Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
DIライブラリ Airframeを使ってみた
Search
takeosuzuki
April 25, 2019
Programming
1.7k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
DIライブラリ Airframeを使ってみた
takeosuzuki
April 25, 2019
Other Decks in Programming
See All in Programming
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
710
AIだと陥りがちなJakarta EE最新技術への移行時の落とし穴と解決策
tnagao7
0
110
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
200
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
190
AI時代のUIはどこへ行く?その2!
yusukebe
22
7.4k
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6.2k
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.7k
TAKTでAI駆動開発の品質を設計する
j5ik2o
7
1.4k
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
210
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
21
6.7k
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
210
さぁV100、メモリをお食べ・・・
nilpe
0
140
Featured
See All Featured
Done Done
chrislema
186
16k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
71
40k
The World Runs on Bad Software
bkeepers
PRO
72
12k
What does AI have to do with Human Rights?
axbom
PRO
1
2.2k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
140
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Building AI with AI
inesmontani
PRO
1
1.1k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.6k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
320
We Have a Design System, Now What?
morganepeng
55
8.2k
Transcript
by TakeoSuzuki
自己紹介 Scala歴4ヶ月 3月からChatworkでアルバイト
@taroleoさんが開発していたライブラリ Scalaアプリケーション開発に便利 その中の一つがDIライブラリ
複数の実装があるとき
trait DataBase { def write(text: String): Unit } class RealDB()
extends DataBase { override def write(text: String): Unit = println(s"$text を本番用DBに書き込みました!") } class TestDB() extends DataBase { override def write(text: String): Unit = println(s"テスト環境のため $text は書き込みしてません!") } trait MyApp { val db = bind[DataBase] } val d = newDesign .bind[DataBase].to[RealDB] d.build[MyApp] { app => app.db.write("お試し") // お試し を本番用DBに書き込みました! // TestDB =>テスト環境のため お試し は書き込みしてません! }
RealDB、TestDBを変えるだけで 実装を切り替えることができる
同一のBindが複数ある時
trait MyApp { val firstName = bind[String] val lastName =
bind[String] } val d = newDesign .bind[String].toInstance("Takeo") .bind[String].toInstance("Suzuki") d.build[MyApp] { app => println(app.firstName) //Takeo println(app.lastName) //Suzuki } d.build[MyApp] { app => println(app.firstName) //Suzuki println(app.lastName) // Suzuki } 予想 結果
• 後が優先される • その型のフィールド全てに適用
MyAppに未定義のメソッドがある時
trait MyApp { val firstName = bind[String] val lastName =
bind[String] def f(x: Int): Int } class MyAppImpl extends MyApp { override def f(x: Int): Int = x + 1 } val d = newDesign .bind[String].toInstance("Takeo") .bind[MyApp].to[MyAppImpl] d.build[MyApp] { app => println(app.firstName) // Takeo println(app.lastName) // Takeo println(app.f(10)) //11 } これでいいのか・・・
val db: DataBase = new RealDB() val d = newDesign.bind[DataBase].to[RealDB]
None