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
TP-Mobile-Era-2016-final-compressed.pdf
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
stephanenicolas
November 04, 2016
Programming
1.6k
1
Share
TP-Mobile-Era-2016-final-compressed.pdf
Introduction to Toothpick: a fresh approach to DI
(Java / Android)
stephanenicolas
November 04, 2016
More Decks by stephanenicolas
See All by stephanenicolas
Comparing DI frameworks
stephanenicolas
0
1.2k
Dart & Henson: Better Android Intents
stephanenicolas
0
790
Migrate from RoboGuice 4 to Toothpick
stephanenicolas
0
570
Toothpick: a fresh approach to Dependency Injection (DI) on Android.
stephanenicolas
0
4.8k
Reflection No Reflection
stephanenicolas
5
180
Mocking workshop at Groupon
stephanenicolas
3
250
Byte Code Weaving for Android
stephanenicolas
2
660
Blender : Boosting Guice with annotation processing
stephanenicolas
9
3k
RoboSpice presentation
stephanenicolas
1
630
Other Decks in Programming
See All in Programming
How We Benchmarked Quarkus: Patterns and anti-patterns
hollycummins
1
130
Reactive ❤️ Loom: A Forbidden Love Story
franz1981
2
240
Kingdom of the Machine
yui_knk
1
120
Cache-moi si tu peux : patterns et pièges du cache en production - Devoxx France 2026 - Conférence
slecache
0
220
GNU Makeの使い方 / How to use GNU Make
kaityo256
PRO
16
5.6k
Server-Side Kotlin LT大会 vol.18 [Kotlin-lspの最新情報と Neovimのlsp設定例]
yasunori0418
1
140
書籍「ユーザーストーリーマッピング」が私のバイブル
asumikam
3
310
10年分の技術的負債、完済へ ― Claude Code主導のAI駆動開発でスポーツブルを丸ごとリプレイスした話
takuya_houshima
0
2.5k
t *testing.T は どこからやってくるの?
otakakot
0
520
クラウドネイティブなエンジニアに向ける Raycastの魅力と実際の活用事例
nealle
2
190
Vibe NLP for Applied NLP
inesmontani
PRO
0
420
飯MCP
yusukebe
0
510
Featured
See All Featured
Scaling GitHub
holman
464
140k
Statistics for Hackers
jakevdp
799
230k
The Curious Case for Waylosing
cassininazir
0
300
Odyssey Design
rkendrick25
PRO
2
570
4 Signs Your Business is Dying
shpigford
187
22k
Accessibility Awareness
sabderemane
0
100
Building AI with AI
inesmontani
PRO
1
900
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
520
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
680
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
64
53k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
53k
Everyday Curiosity
cassininazir
0
190
Transcript
A FRESH APPROACH TO DI TOOTHPICK https://github.com/stephanenicolas/toothpick/
ABOUT US Senior Android Dev @ Groupon ~20 years of
Java coding OSS: Dart, TP STEPHANE NICOLAS DANIEL MOLINERO REGUERA Android Dev @ Groupon Best level 3 ever OSS: Dart, +stephane)nicolas @D_Lemures
5IF"OESPJE5FBNJT)JSJOH jobs.groupon.com/careers/
THE TALK WHY DI ? WHY TOOTHPICK? TOOTHPICK FEATURES
ADVANCED FEATURES CONCLUSION SCOPE MODULES & BINDINGS SCOPE TREE SCOPE SINGLETONS MVP & STATE PRESERVATION MULTIPLE ACTIVITIES FLOWS
WHY DI ? DECOUPLE REUSE TEST USES USES USES MOCK
USES
WHY TOOTHPICK? SIMPLER BETTER TEST SUPPORT EVEN FASTER
TOOTHPICK FEATURES public class SmoothieMachine { @Inject IceMachine iceMachine;
public void doSmoothie() { iceMachine.makeIce(); } } @Singleton public class IceMachine { Foo foo; @Inject public IceMachine(Foo foo) { this.foo = foo; } JSR 330 annotations→nothing new here
TOOTHPICK FEATURES SCOPE SCOPE MAKE INJECTIONS public class MyApplication extends
Application { @Inject Machine machine; @Override protected void onCreate() { super.onCreate(); Scope appScope = Toothpick.openScope(this); appScope.installModules(…); Toothpick.inject(this, appScope); } }
TOOTHPICK FEATURES SCOPE, MODULES & BINDINGS SCOPE BINDINGS MODULES public
class MyApplication extends Application { @Inject Machine machine; @Override protected void onCreate() { super.onCreate(); Scope appScope = Toothpick.openScope(this); appScope.installModules(new Module() {{ bind(Machine.class).to(IceMachine.class); }}); Toothpick.inject(this, appScope); } }
TOOTHPICK FEATURES APPLICATION SCOPE ACTIVITY 1 SCOPE ACTIVITY 2 SCOPE
SERVICE 1 SCOPE FRAGMENT 3 SCOPE FRAGMENT 1 SCOPE FRAGMENT 2 SCOPE SCOPE TREE
TOOTHPICK FEATURES public class LemonActivity extends Activity { @Inject
SmoothieMachine smoothieMachine; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Scope scope = Toothpick.openScopes(getApplication(), this); scope.installModules(…); Toothpick.inject(this, scope); } } SCOPE TREE APPLICATION SCOPE ACTIVITY SCOPE
TOOTHPICK FEATURES APPLICATION SCOPE ACTIVITY SCOPE APP SINGLETONS ACTIVITY SINGLETONS
SCOPE SINGLETONS
TOOTHPICK FEATURES public class Module extends Module { public Module1()
{ bind(Machine.class).toInstance(new IceMachine()); } } SCOPE SINGLETONS SINGLETONS CAN BE DEFINED IN MODULES
TOOTHPICK FEATURES @Singleton public class IceMachine { } @ActivitySingleton public
class SmoothieMachine { } APPLICATION SCOPE ACTIVITY SCOPE SCOPE SINGLETONS OR USING ANNOTATIONS
ADVANCED TOOTHPICK FEATURES MVP & STATE PRESERVATION
ADVANCED TOOTHPICK FEATURES MVP & STATE PRESERVATION Landscape Portrait
PRESENTER INSTANCE APPLICATION SCOPE PRESENTER SCOPE ADVANCED TOOTHPICK FEATURES MVP
& STATE PRESERVATION ACTIVITY SCOPE
ADVANCED TOOTHPICK FEATURES MVP & STATE PRESERVATION public class MyActivity
extends Activity { @Inject MyPresenter presenter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Scope scope = openScopes(getApplication(), PresenterSingleton.class, this); Toothpick.inject(this, scope); } }
@PresenterSingleton public class MyPresenter { String dealId; int quantity; }
PRESENTER SCOPE MVP & STATE PRESERVATION ADVANCED TOOTHPICK FEATURES
ACTIVITY 1 ADVANCED TOOTHPICK FEATURES ACTIVITY 3 ACTIVITY 2 MULTI
ACTIVITY FLOWS Purchase Flow !
APPLICATION SCOPE ACTIVITY 1 SCOPE ADVANCED TOOTHPICK FEATURES FLOW SCOPE
ACTIVITY 3 SCOPE ACTIVITY 2 SCOPE MULTI ACTIVITY FLOWS
ADVANCED TOOTHPICK FEATURES MVP & STATE PRESERVATION public class MyActivity
extends Activity { @Inject ShoppingCart shoppingCart; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Scope scope = openScopes(getApplication(), FlowSingleton.class, this); Toothpick.inject(this, scope); } }
@FlowSingleton public class ShoppingCart { List<PurchaseItem> purchases… } FLOW SCOPE
MULTI ACTIVITY FLOWS ADVANCED TOOTHPICK FEATURES
CONCLUSION QUESTIONS ? COMMENTS ?
A FRESH APPROACH TO DI TOOTHPICK https://github.com/stephanenicolas/toothpick/ +stephane)nicolas @D_Lemures