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
Toothpick - A fresh approach to DI - Short Version
Search
Daniel Molinero Reguera
September 26, 2017
Programming
0
57
Toothpick - A fresh approach to DI - Short Version
Presented at GDG East Bay - Samsung office
Daniel Molinero Reguera
September 26, 2017
Tweet
Share
More Decks by Daniel Molinero Reguera
See All by Daniel Molinero Reguera
TP3 & KTP: Simple, fast, and boilerplate-free DI for Kotlin
dlemures
0
52
Toothpick - A fresh approach to DI (Including Unit Testing)
dlemures
1
1.1k
Toothpick Bad Practices 🙅 and Nice Tricks 👌
dlemures
0
98
Dart & Henson - Better Android Intents
dlemures
1
220
Toothpick - A fresh approach to DI
dlemures
0
120
Toothpick & Dependency Injection
dlemures
1
2k
Other Decks in Programming
See All in Programming
PHPカンファレンス 2024|共創を加速するための若手の技術挑戦
weddingpark
0
140
asdf-ecspresso作って 友達が増えた話 / Fujiwara Tech Conference 2025
koluku
0
1.4k
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
1.3k
DMMオンラインサロンアプリのSwift化
hayatan
0
190
各クラウドサービスにおける.NETの対応と見解
ymd65536
0
250
はてなにおけるfujiwara-wareの活用やecspressoのCI/CD構成 / Fujiwara Tech Conference 2025
cohalz
3
2.7k
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
6
700
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
360
Simple組み合わせ村から大都会Railsにやってきた俺は / Coming to Rails from the Simple
moznion
3
2.1k
Flatt Security XSS Challenge 解答・解説
flatt_security
0
730
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
7
1.4k
ErdMap: Thinking about a map for Rails applications
makicamel
1
640
Featured
See All Featured
Building Adaptive Systems
keathley
38
2.4k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3.1k
The Cost Of JavaScript in 2023
addyosmani
46
7.2k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
The Cult of Friendly URLs
andyhume
78
6.1k
VelocityConf: Rendering Performance Case Studies
addyosmani
327
24k
Docker and Python
trallard
43
3.2k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
113
50k
Become a Pro
speakerdeck
PRO
26
5.1k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
192
16k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
Transcript
A FRESH APPROACH TO DI TOOTHPICK https://github.com/stephanenicolas/toothpick/
5IF"OESPJE5FBNJT)JSJOH jobs.groupon.com/careers/ @D_Lemures #ToothpickDI @GrouponEng @SteffNicolas
THE TALK WHY TOOTHPICK? USING TOOTHPICK REUSING INSTANCES
VERSION 2.0 CONCLUSION DEFINING DEPENDENCIES INJECTING DEPENDENCIES MODULES & BINDINGS SCOPE TREE SCOPE SINGLETONS MULTI-ACTIVITY FLOW @D_Lemures | #ToothpickDI
WHY TOOTHPICK? @D_Lemures | #ToothpickDI The Ancient Roma Coffee Machine
Visual Toy javierarres.wordpress.com
WHY TOOTHPICK? SIMPLER BETTER TEST SUPPORT EVEN FASTER @D_Lemures |
#ToothpickDI
USING TOOTHPICK public class DealPresenter { @Inject DealApiClient apiClient;
@Inject Navigator navigator; } @Singleton public class DealApiClient { Retrofit retrofit; @Inject public IceMachine(Retrofit retrofit) { this.retrofit = retrofit; } } JSR 330 annotations→nothing new here @D_Lemures | #ToothpickDI DEFINING DEPENDENCIES
INJECTING DEPENDENCIES public class DealActivity extends Activity { @Inject DealPresenter
presenter; @Override protected void onCreate() { super.onCreate(); Scope appScope = Toothpick.openScope(getApplication()); Toothpick.inject(this, appScope); } } @D_Lemures | #ToothpickDI USING TOOTHPICK
INJECTING DEPENDENCIES @D_Lemures | #ToothpickDI USING TOOTHPICK SCOPE MAKE INJECTIONS
public class DealActivity extends Activity { @Inject DealPresenter presenter; @Override protected void onCreate() { super.onCreate(); Scope appScope = Toothpick.openScope(getApplication()); Toothpick.inject(this, appScope); } }
INJECTING DEPENDENCIES @D_Lemures | #ToothpickDI USING TOOTHPICK DEAL PRESENTER public
class DealActivity extends Activity { @Inject DealPresenter presenter; @Override protected void onCreate() { super.onCreate(); Scope appScope = Toothpick.openScope(getApplication()); Toothpick.inject(this, appScope); } } DEAL APICLIENT NAVIGATOR RETROFIT
public class DealActivity extends Activity { @Inject DealPresenter presenter;
@Override protected void onCreate() { super.onCreate(); Scope appScope = Toothpick.openScope(getApplication()); appScope.installModules(new Module() {{ bind(Navigator.class).to(NavigatorImpl.class); bind(Retrofit.class).toInstance(retrofitInstance); }}); Toothpick.inject(this, appScope); } } MODULES & BINDINGS @D_Lemures | #ToothpickDI USING TOOTHPICK BINDINGS MODULES SCOPE
@D_Lemures | #ToothpickDI USING TOOTHPICK SCOPE 1 SCOPE 2 SCOPE
4 SCOPE 3 MODULES & BINDINGS
APPLICATION SCOPE ACTIVITY 1 SCOPE ACTIVITY 2 SCOPE SERVICE 1
SCOPE FRAGMENT 3 SCOPE FRAGMENT 1 SCOPE FRAGMENT 2 SCOPE SCOPE TREE @D_Lemures | #ToothpickDI USING TOOTHPICK
public class DealActivity extends Activity { @Inject DealPresenter presenter; @Inject
Context context; @Override protected void onCreate() { super.onCreate(); Scope scope = Toothpick.openScope(getApplication(), this); scope.installModules(new Module() {{ bind(Context.class).toInstance(this); }}); Toothpick.inject(this, scope); } } SCOPE TREE APPLICATION SCOPE ACTIVITY SCOPE @D_Lemures | #ToothpickDI USING TOOTHPICK
SCOPE SINGLETONS @D_Lemures | #ToothpickDI REUSING INSTANCES ANDROID INTENT ACTIVITY
FRAGMENT RECYCLER VIEW LOCAL SINGLETON
APPLICATION SCOPE ACTIVITY SCOPE APP SINGLETONS ACTIVITY SINGLETONS SCOPE SINGLETONS
@D_Lemures | #ToothpickDI REUSING INSTANCES
public class Module extends Module { public Module() { bind(ViewHelper.class).toInstance(new
ViewHelper()); } } SCOPE SINGLETONS SINGLETONS CAN BE DEFINED IN MODULES @D_Lemures | #ToothpickDI REUSING INSTANCES
@Singleton public class DealApiClient { } @ActivitySingleton public class ViewHelper
{ } APPLICATION SCOPE ACTIVITY SCOPE SCOPE SINGLETONS OR USING ANNOTATIONS @D_Lemures | #ToothpickDI REUSING INSTANCES
ACTIVITY 1 ACTIVITY 3 ACTIVITY 2 MULTI ACTIVITY FLOWS Purchase
Flow @D_Lemures | #ToothpickDI REUSING INSTANCES
APPLICATION SCOPE ACTIVITY 1 SCOPE FLOW SCOPE ACTIVITY 3 SCOPE
ACTIVITY 2 SCOPE MULTI ACTIVITY FLOWS @D_Lemures | #ToothpickDI REUSING INSTANCES
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); } } @D_Lemures | #ToothpickDI REUSING INSTANCES MULTI ACTIVITY FLOWS
@FlowSingleton public class ShoppingCart { List<PurchaseItem> purchases… } FLOW SCOPE
MULTI ACTIVITY FLOWS @D_Lemures | #ToothpickDI REUSING INSTANCES
VERSION 2.0 RELEASABLE SINGLETONS @D_Lemures | #ToothpickDI BETTER SCOPE ANNOTATIONS
KILLING REGISTRIES BETTER API
CONCLUSION QUESTIONS ? COMMENTS ? @D_Lemures | #ToothpickDI
A FRESH APPROACH TO DI TOOTHPICK https://github.com/stephanenicolas/toothpick/ @D_Lemures #ToothpickDI @GrouponEng
@SteffNicolas