Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Dagger 2.0 - new dependency injection for Andro...
Search
Radek Piekarz
December 05, 2014
Programming
1
2k
Dagger 2.0 - new dependency injection for Android (Droidcon Krakow 2014)
Short introduction to Dagger 2.0 during
Droidcon Kraków
2014.
See more information
here
.
Radek Piekarz
December 05, 2014
Tweet
Share
More Decks by Radek Piekarz
See All by Radek Piekarz
Nearby Notifications – annoy your friends!
radzio
1
74
Deep dive into Android Data Binding
radzio
4
2.6k
How to use MVVM pattern in Android
radzio
1
1.1k
How to use MVVM pattern in Android (Droidcon Krakow 2014)
radzio
14
13k
How to use Apple iBeacons with Android
radzio
1
410
Overview of libraries and tools that make your Android development easier and faster
radzio
1
170
Other Decks in Programming
See All in Programming
生成AIを利用するだけでなく、投資できる組織へ
pospome
2
340
著者と進める!『AIと個人開発したくなったらまずCursorで要件定義だ!』
yasunacoffee
0
140
マスタデータ問題、マイクロサービスでどう解くか
kts
0
100
ViewファーストなRailsアプリ開発のたのしさ
sugiwe
0
470
251126 TestState APIってなんだっけ?Step Functionsテストどう変わる?
east_takumi
0
320
Full-Cycle Reactivity in Angular: SignalStore mit Signal Forms und Resources
manfredsteyer
PRO
0
140
AIエージェントを活かすPM術 AI駆動開発の現場から
gyuta
0
420
実はマルチモーダルだった。ブラウザの組み込みAI🧠でWebの未来を感じてみよう #jsfes #gemini
n0bisuke2
2
1.1k
React Native New Architecture 移行実践報告
taminif
1
150
TestingOsaka6_Ozono
o3
0
160
複数人でのCLI/Infrastructure as Codeの暮らしを良くする
shmokmt
5
2.3k
新卒エンジニアのプルリクエスト with AI駆動
fukunaga2025
0
230
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.6k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.1k
How STYLIGHT went responsive
nonsquared
100
6k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.6k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
The Language of Interfaces
destraynor
162
25k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.8k
Typedesign – Prime Four
hannesfritz
42
2.9k
Become a Pro
speakerdeck
PRO
31
5.7k
Building Applications with DynamoDB
mza
96
6.8k
The Art of Programming - Codeland 2020
erikaheidi
56
14k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.5k
Transcript
Dagger 2.0 New dependency injection for Android Radosław Piekarz
Spring • Popular in the Java community • Polularized DI/IoC
• XML configuration
Guice / RoboGuice • Used new features in Java 1.5
• No XML configuration • Not so easy to debug • Runtime validation
None
None
Dagger 1 • Compile time validation • Do more work
during compile and less in runtime • Faster than Guice/RoboGuice
Dagger 1 • Not proguard safe • Runtime graph composition
Source: Jake Wharton
Minimal graph creation time - not just fast, but hand-written
DI fast
Full, static inspection of code paths
No reflection, no explicit classloading
Dagger 2 API • @Module & @Provides - mechanism for
providing dependencies • @Inject - mechanism for requesting dependencies • @Component bridge between modules and injections
Example module @Module class PumpModule { @Provides Pump providePump(Thermosiphon pump)
{ return pump; } }
@Inject class CoffeeMaker { private final Lazy<Heater> heater; private final
Pump pump; @Inject CoffeeMaker(Lazy<Heater> heater, Pump pump) { this.heater = heater; this.pump = pump; }
@Component @Component(modules = {DripCoffeeModule.class}) public interface Coffee { CoffeeMaker maker();
}
Example app public class CoffeeApp { public static void main(String[]
args) { Coffee coffee = Dagger_Coffee.builder() .build(); coffee.maker().brew(); } }
Dagger 1 vs Dagger 2 public class CoffeeApp implements Runnable
{ @Inject CoffeeMaker coffeeMaker; @Override public void run() { coffeeMaker.brew(); } public static void main(String[] args) { ObjectGraph objectGraph = ObjectGraph.create(new DripCoffeeModule()); CoffeeApp coffeeApp = objectGraph.get(CoffeeApp.class); coffeeApp.run(); } }
None
Quick demos
u2020 & u2021 https://github.com/Jak eWharton/u2020 https://github.com/cgr uber/u2020/tree/dagg er2
Dagger 2 Pros • It is really fast • Compile
time validation for entire graph • Easy debugging Cons • Not flexible • There is no dynamism
https://github.com/google/dagger/ https://google.github.io/dagger/
Q&A Thank you for your attention! radzio RadoslawPiekarz { }