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
250
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.3k
Android Studio 3.0 profilerハンズオン
zaki50
2
810
Realm Japan meetup #23_Java
zaki50
0
770
Realm Japan meetup #22_Java
zaki50
1
590
Realm World Tour Osaka Recent Java Updates
zaki50
0
500
Realm World Tour - ErrorProne in Realm Java
zaki50
2
500
Realm World Tour Tokyo Recent Java Updates
zaki50
2
830
Realm World Tour - ErrorProne in Realm Java
zaki50
1
810
オフラインファーストなアプリケーション開発
zaki50
1
2.7k
Other Decks in Technology
See All in Technology
ミイダス株式会社 テックチームのご紹介 / MIIDAS Tech Team
miidas
0
170
ログラスのマルチプロダクトを 支える認証基盤 〜テナントごとに異なる統制とどう向き合うか〜
dada4386
3
410
データ品質を壊しながらSnowflakeのAIに分析させてみた
kawanago
0
540
DevelopersIO 2026 知識の地図を描く ─ オントロジーとは何か?
ishikawa_satoru
1
270
Datadog の学び方 - あるいは、オブザーバビリティを学ぶとは何か
mananyuki
1
500
3つのアプローチで目指す チームを強くするAI駆動開発
thkt
0
130
オンラインゲームのシステム全体像 - コロプラ 2026年度 新卒研修
colopl
0
910
The seven pitfalls of AI (revised version)
ufried
0
290
メルペイ 会計システム概要と歴史
mewuto
0
190
AgentCoreで実践するハーネスエンジニアリング
yakumo
1
290
Meet AgentCore Identity Consent Portal
hironobuiga
3
190
いちAWSエンジニアのAI活用を振り返る #devio2026 / devio osaka 2026 kawahara
masahirokawahara
2
410
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
260
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
480
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Accessibility Awareness
sabderemane
1
240
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
300
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Design in an AI World
tapps
1
350
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
The agentic SEO stack - context over prompts
schlessera
0
970
Facilitating Awesome Meetings
lara
57
7.2k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
2
6.3k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
770
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())
·ͱΊ • ͱʹ͔͘Ϟδϡʔϧείʔϓͷఆٛ ͕؆୯ • ύϑΥʔϚϯεྑ͍ • ςετͷαϙʔτ͋Δ