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
54
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
負債になりにくいCSSをデザイナとつくるには?
fsubal
9
2.4k
クリーンアーキテクチャから見る依存の向きの大切さ
shimabox
2
340
動作確認やテストで漏れがちな観点3選
starfish719
6
1k
Java Webフレームワークの現状 / java web framework at burikaigi
kishida
9
2.2k
Linux && Docker 研修/Linux && Docker training
forrep
24
4.5k
ソフトウェアエンジニアの成長
masuda220
PRO
10
1.1k
AIの力でお手軽Chrome拡張機能作り
taiseiue
0
170
Rails アプリ地図考 Flush Cut
makicamel
1
120
2024年のkintone API振り返りと2025年 / kintone API look back in 2024
tasshi
0
220
Introduction to kotlinx.rpc
arawn
0
700
一休.com のログイン体験を支える技術 〜Web Components x Vue.js 活用事例と最適化について〜
atsumim
0
490
sappoRo.R #12 初心者セッション
kosugitti
0
250
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
182
22k
Navigating Team Friction
lara
183
15k
A Philosophy of Restraint
colly
203
16k
Producing Creativity
orderedlist
PRO
344
39k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
100
18k
Docker and Python
trallard
44
3.3k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
4
330
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
9
440
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.6k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.4k
Building Your Own Lightsaber
phodgson
104
6.2k
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