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
240
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
820
Realm World Tour - ErrorProne in Realm Java
zaki50
1
800
オフラインファーストなアプリケーション開発
zaki50
1
2.7k
Other Decks in Technology
See All in Technology
AIを活用するために決めた "やらないこと" - 価値に注目する / Not betting on AI
soudai
PRO
3
550
Genieを崇めよ
kameitomohiro
0
160
SREへの勘違いに気づいた後の話
tomodakengo
0
110
AI de Idea
kawaguti
PRO
2
120
The Knowledge Spine: A Machine-Executable Ontology for Governed Marketing Activation
vananth22
0
110
新機種発売前に見直そう!端末移行で再ログインが要るアプリ・要らないアプリは何が違うのか 〜シームレスに再開できる設計と実装〜
zozotech
PRO
0
210
今話題のAI「Jev」って何? 宇宙最速で学ぶ会
minorun365
PRO
29
16k
Deployment の 先にある AI Agent 基盤 - kagent vNext、Agent Substrate、Hermes から読み解く Agent Runtime の現在地 / k8s-matsuri-2-ai-agent-platform-amsy810
masayaaoyama
4
660
幾何アルゴリズムで なめらかなピン操作を / iOSDC Japan 2026 / smoothpin
kazumanagano
0
360
.NET WebAssemblyで実現するクライアントサイドAI推論:NuGetからViteまで、2つのエコシステムを繋ぐビルド戦略
yamachu
0
180
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
12k
Cloudflare Workers 向けアプリを C# で構築する ~WASM Native AOT への道~
nenonaninu
1
400
Featured
See All Featured
The Limits of Empathy - UXLibs8
cassininazir
1
680
Ethics towards AI in product and experience design
skipperchong
2
380
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
610
What's in a price? How to price your products and services
michaelherold
247
13k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
WCS-LA-2024
lcolladotor
0
830
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
700
The SEO Collaboration Effect
kristinabergwall1
1
570
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
540
Game over? The fight for quality and originality in the time of robots
wayneb77
1
280
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
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())
·ͱΊ • ͱʹ͔͘Ϟδϡʔϧείʔϓͷఆٛ ͕؆୯ • ύϑΥʔϚϯεྑ͍ • ςετͷαϙʔτ͋Δ