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
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
590
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
290
DynamoDBには集計系のクエリがないけどなんとかしたい
musan
1
180
net-httpのHTTP/2対応について
naruse
0
500
AI時代のUIはどこへ行く?その2!
yusukebe
22
7.4k
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.3k
dRuby over BLE
makicamel
2
380
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
14
5.6k
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
21
6.7k
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
1
260
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
170
Inside Stream API
skrb
1
740
Featured
See All Featured
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.8k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
240
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.8k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
360
What does AI have to do with Human Rights?
axbom
PRO
1
2.2k
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
How to build a perfect <img>
jonoalderson
1
5.7k
Evolving SEO for Evolving Search Engines
ryanjones
0
220
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.3k
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