Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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
App Intentsのビルドプロセスを支える技術
kntkymt
0
480
Agents on Rails - Rails at Scale 2026
irinanazarova
0
310
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
420
SREの越境 / SRE Collaboration
y0hgi
2
290
Are APIs Still Relevant in the AI Era?
soyuka
0
380
setup-vp GitLab対応の裏側
naokihaba
0
140
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
800
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
640
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
3.1k
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
2.6k
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
430
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
200
Featured
See All Featured
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
250
The agentic SEO stack - context over prompts
schlessera
0
950
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
710
My Coaching Mixtape
mlcsv
0
330
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
500
Balancing Empowerment & Direction
lara
6
1.3k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
Faster Mobile Websites
deanohume
310
32k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Discover your Explorer Soul
emna__ayadi
2
1.3k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
520
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
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