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ライブラリToothpick
Search
zaki50
January 26, 2018
Technology
230
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
800
Realm Japan meetup #23_Java
zaki50
0
760
Realm Japan meetup #22_Java
zaki50
1
570
Realm World Tour Osaka Recent Java Updates
zaki50
0
490
Realm World Tour - ErrorProne in Realm Java
zaki50
2
500
Realm World Tour Tokyo Recent Java Updates
zaki50
2
810
Realm World Tour - ErrorProne in Realm Java
zaki50
1
790
オフラインファーストなアプリケーション開発
zaki50
1
2.7k
Other Decks in Technology
See All in Technology
【NRUG vol.18】KubernetesにおけるNew Relicデータ取得量削減の考え方
nrug_member
0
170
SONiCのLinuxベースを活かしたZabbix監視
sonic
0
240
Claude Codeをどのように キャッチアップしているか
oikon48
13
8.6k
2026TECHFRESH畢業分享會 - 原生還是跨平台? App 開發踩坑實錄
line_developers_tw
PRO
0
1.4k
自分が詳しくない領域でAIを使う #プロヒス2026
konifar
18
6.2k
【Cyber-sec+】経営層を"動かす"ための考え方
hssh2_bin
0
200
いまさら聞けない「仕様駆動開発入門」 〜AI活用時代の開発プロセスを考える〜
findy_eventslides
2
160
アンオフィシャルな、オフィシャルからのお願い
wyamazak_devrel
0
140
Bucharest Tech Week 2026 - Guardians of the Cloud-Native Galaxy
edeandrea
PRO
0
130
Kiroで書いた 設計書 が AI レビューの 採点基準 になる
ezaki
0
140
水を運ぶ人としてのリーダーシップ
izumii19
2
170
SteampipeとExcel Power QueryでAWS構成定義書の作成を自動化する
jhashimoto
0
160
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
28
2.7k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.5k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.5k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
160
Into the Great Unknown - MozCon
thekraken
41
2.6k
Scaling GitHub
holman
464
140k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.5k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
370
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
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())
·ͱΊ • ͱʹ͔͘Ϟδϡʔϧείʔϓͷఆٛ ͕؆୯ • ύϑΥʔϚϯεྑ͍ • ςετͷαϙʔτ͋Δ