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ライブラリToothpick
Search
zaki50
January 26, 2018
Technology
260
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
簡単高速なDIライブラリToothpick
zaki50
January 26, 2018
More Decks by zaki50
See All by zaki50
I/O Extended 2018 @Tokyo Android1
zaki50
3
1.4k
Android Studio 3.0 profilerハンズオン
zaki50
2
820
Realm Japan meetup #23_Java
zaki50
0
770
Realm Japan meetup #22_Java
zaki50
1
600
Realm World Tour Osaka Recent Java Updates
zaki50
0
510
Realm World Tour - ErrorProne in Realm Java
zaki50
2
510
Realm World Tour Tokyo Recent Java Updates
zaki50
2
840
Realm World Tour - ErrorProne in Realm Java
zaki50
1
820
オフラインファーストなアプリケーション開発
zaki50
1
2.7k
Other Decks in Technology
See All in Technology
増え続けるプロダクトの品質をどう担保するか。ProductSpecとTypeScriptによる取り組み
joere
3
1.1k
AIコーディングはじめました
miso
0
150
AIがGISを代替する日:〜すべてをAIが創る時代に、私たちがFOSS4Gに関わる意味〜
lehupa
1
210
TSKaigi Sendai 2026 - tsgo時代のTypeScript Playgroundはどう動くか
teamlab
PRO
0
110
Deep Data Security 機能解説
oracle4engineer
PRO
3
1k
Technical Project Manager の役割とやりがい、少しだけ AI
yoshiiryo1
0
600
cdkd (CDK Direct)
gotok365
4
270
The future of architectural work
ufried
0
180
【dbts2026】AIエージェントの 判断と探索を変える、 データベース エンジニアリング― 既存DBの処理と依存関係から作る、オペレーショナルオントロジー ―
shisyu_gaku
0
240
内製アプリとClaudeスキルのセキュリティチェック、 Backlogの課題で回しています。
ayaka_egaaa
0
140
デザインレビューは自動化できるのか?─ Flutter × Figma で UI 品質保証を考える
techiro
2
820
お客様の「やりたい」の先を見通す合意形成プロセス ~裏にある課題と不安を解きほぐすコツ~
yukakoseki
0
110
Featured
See All Featured
WCS-LA-2024
lcolladotor
0
980
A Modern Web Designer's Workflow
chriscoyier
699
190k
New Earth Scene 8
popppiees
4
2.8k
How Software Deployment tools have changed in the past 20 years
geshan
3
35k
Optimising Largest Contentful Paint
csswizardry
37
4k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Mobile First: as difficult as doing things right
swwweet
225
10k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
GraphQLとの向き合い方2022年版
quramy
50
15k
Context Engineering - Making Every Token Count
addyosmani
9
1.3k
Transcript
؆୯ߴͳDIϥΠϒϥϦToothpick DroidKaigi Prelude YAMAZAKI Makoto (@zaki50)
Toothpick https://github.com/stephanenicolas/toothpick
ಛ • γϯϓϧͰ؆୯ • ͪΐͬͱ͚ͩྼΔ͚Ͳ΄΅ಉ͡ • ͍͔ͭ͘ͷ༻සͷ͍ػೳυϩοϓ Dagger2ͱ͘Βͯ https://github.com/stephanenicolas/toothpick/wiki/Benchmark
͍ํ • ToothpickΛґଘϥΠϒϥϦͱͯ͠Ճ • ϞδϡʔϧΛఆٛ • είʔϓΛఆٛ • είʔϓͰ༻͢ΔϞδϡʔϧΛࢦఆ •
ೖ
ϥΠϒϥϦՃ app/build.gradle: dependencies { implementation 'com.github.stephanenicolas.toothpick:toothpick-runtime:1.1.1' kapt 'com.github.stephanenicolas.toothpick:toothpick-compiler:1.1.1' }
Ϟδϡʔϧఆٛ ApplicationModule.kt class ApplicationModule(private val application: Application) : Module() {
init { bind() } private fun bind() { val repository = ModelRepository(application) bind(ModelRepository::class.java).toInstance(repository) bind(Foo::class.java).to(FooImpl::class.java) bind(Bar::class.java).toProvider(BarProvider::class.java) } }
࣮Ϋϥε FooImpl.kt class FooImpl @Inject constructor() : Foo { init
{ ... } } BarProvider.kt class BarProvider : Provider<Bar> { override fun get(): Bar = BarImpl() }
είʔϓ
ɹείʔϓͷ࡞Γํ MainActivity.kt class MyApplication : Application() { override fun onCreate()
{ super.onCreate() val scope = Toothpick.openScope(this) scope.installModules(ApplicationModule(this)) } override fun onTerminate() { super.onTerminate() Toothpick.closeScope(this) } }
ɹωετͨ͠είʔϓ MainActivity.kt class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState:
Bundle?) { super.onCreate(savedInstanceState) val scope = Toothpick.openScopes(application, this) scope.installModules(MainActivityModule(this)) } override fun onDestroy() { super.onDestroy() Toothpick.closeScope(this) } }
ɹগ͠ݡ͍είʔϓ MainActivity.kt class MainActivity : AppCompatActivity() { private lateinit var
activityId: String override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) ... activityId = getActivityId(savedInstanceState) scope = Toothpick.openScopes(application, activityId) } private fun getActivityId(savedInstanceState: Bundle?): String { return savedInstanceState?.getString("activity_id") ?: UUID.randomUUID().toString() } }
ɹগ͠ݡ͍είʔϓ(ଓ͖) MainActivity.kt class MainActivity : AppCompatActivity() { ... override fun
onSaveInstanceState(outState: Bundle?) { super.onSaveInstanceState(outState) outState?.putString("activity_id", activityId) } override fun onDestroy() { super.onDestroy() if (isFinishing) { Toothpick.closeScope(activityId) } } }
Ϟδϡʔϧ༻ MyApplication.kt class MyApplication : Application() { override fun onCreate()
{ super.onCreate() val scope = Toothpick.openScope(this) scope.installModules(ApplicationModule(this)) } override fun onTerminate() { super.onTerminate() Toothpick.closeScope(this) } }
ೖ MainActivity.kt class MainActivity : AppCompatActivity() { @Inject lateinit var
repo: ModelRepository @Inject lateinit var foo: Foo override fun onCreate() { super.onCreate() val scope = Toothpick.openScopes(application, this) scope.installModules(ApplicationModule(this)) Toothpick.inject(this, scope) } }
γϯάϧτϯ BarImpl.kt @Singleton class BarImpl @Inject constructor() : Bar {
init { ... } }
Android༻ศརϞδϡʔϧ app/build.gradle: dependencies { implementation 'com.github.stephanenicolas.toothpick:toothpick-runtime:1.1.1' kapt 'com.github.stephanenicolas.toothpick:toothpick-compiler:1.1.1' implementation 'com.github.stephanenicolas.toothpick:smoothie:1.1.1'
} val scope = Toothpick.openScope(this) scope.installModules(SmoothieApplicationModule(this)) scope.installModules(ApplicationModule(this))
ϦϑϨΫγϣϯͷഉআ app/build.gradle: kapt { generateStubs = true arguments { arg('toothpick_registry_package_name',
"${android.defaultConfig.applicationId}.toothpick") } }
ϦϑϨΫγϣϯͷഉআ MyApplication.kt ͷ onCreateͰ Toothpick.setConfiguration( Configuration.forProduction().disableReflection()) MemberInjectorRegistryLocator.setRootRegistry( com.example.toothpick.MemberInjectorRegistry()) FactoryRegistryLocator.setRootRegistry( com.example.toothpick.FactoryRegistry())
·ͱΊ • ͱʹ͔͘Ϟδϡʔϧείʔϓͷఆٛ ͕؆୯ • ύϑΥʔϚϯεྑ͍ • ςετͷαϙʔτ͋Δ