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
stephanenicolas
November 04, 2016
Programming
1
1.6k
TP-Mobile-Era-2016-final-compressed.pdf
Introduction to Toothpick: a fresh approach to DI
(Java / Android)
stephanenicolas
November 04, 2016
Tweet
Share
More Decks by stephanenicolas
See All by stephanenicolas
Comparing DI frameworks
stephanenicolas
0
1.2k
Dart & Henson: Better Android Intents
stephanenicolas
0
750
Migrate from RoboGuice 4 to Toothpick
stephanenicolas
0
510
Toothpick: a fresh approach to Dependency Injection (DI) on Android.
stephanenicolas
0
4.7k
Reflection No Reflection
stephanenicolas
5
160
Mocking workshop at Groupon
stephanenicolas
3
210
Byte Code Weaving for Android
stephanenicolas
2
610
Blender : Boosting Guice with annotation processing
stephanenicolas
9
2.9k
RoboSpice presentation
stephanenicolas
1
600
Other Decks in Programming
See All in Programming
NEWT Backend Evolution
xpromx
1
110
GitHub Copilot and GitHub Codespaces Hands-on
ymd65536
2
150
ISUCON研修おかわり会 講義スライド
arfes0e2b3c
1
460
AI駆動のマルチエージェントによる業務フロー自動化の設計と実践
h_okkah
0
210
PostgreSQLのRow Level SecurityをPHPのORMで扱う Eloquent vs Doctrine #phpcon #track2
77web
2
570
Webの外へ飛び出せ NativePHPが切り拓くPHPの未来
takuyakatsusa
2
580
High-Level Programming Languages in AI Era -Human Thought and Mind-
hayat01sh1da
PRO
0
840
20250628_非エンジニアがバイブコーディングしてみた
ponponmikankan
0
710
The Modern View Layer Rails Deserves: A Vision For 2025 And Beyond @ RailsConf 2025, Philadelphia, PA
marcoroth
2
680
システム成長を止めない!本番無停止テーブル移行の全貌
sakawe_ee
1
230
効率的な開発手段として VRTを活用する
ishkawa
0
150
AI コーディングエージェントの時代へ:JetBrains が描く開発の未来
masaruhr
1
200
Featured
See All Featured
Faster Mobile Websites
deanohume
307
31k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
510
GraphQLとの向き合い方2022年版
quramy
49
14k
The Language of Interfaces
destraynor
158
25k
YesSQL, Process and Tooling at Scale
rocio
173
14k
Documentation Writing (for coders)
carmenintech
72
4.9k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
Fireside Chat
paigeccino
37
3.5k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
How STYLIGHT went responsive
nonsquared
100
5.6k
Scaling GitHub
holman
460
140k
Automating Front-end Workflow
addyosmani
1370
200k
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