Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Dagger 2.0 - new dependency injection for Andro...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Radek Piekarz
December 05, 2014
Programming
2.1k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
More Decks by Radek Piekarz
See All by Radek Piekarz
Nearby Notifications – annoy your friends!
radzio
1
110
Deep dive into Android Data Binding
radzio
4
2.7k
How to use MVVM pattern in Android
radzio
1
1.1k
How to use MVVM pattern in Android (Droidcon Krakow 2014)
radzio
14
14k
How to use Apple iBeacons with Android
radzio
1
460
Overview of libraries and tools that make your Android development easier and faster
radzio
1
200
Other Decks in Programming
See All in Programming
Jetpack Compose Mechanisms
skydoves
3
830
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
330
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2.5k
最近”作らせてる” ローカルAIアプリの話
akit37
0
480
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
170
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
190
AWSに止められる覚悟してますか?
morizo_1984
2
540
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
690
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
860
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
5
5.2k
golang-bob.pdf
iwatsukayura
0
130
オーケストレーション記述言語 Katari
yukikurage
0
120
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
187
23k
A Tale of Four Properties
chriscoyier
163
24k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
630
Building Adaptive Systems
keathley
44
3.3k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
460
Building the Perfect Custom Keyboard
takai
2
910
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
320
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 { }