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
Dagger 2.0 - new dependency injection for Andro...
Search
Radek Piekarz
December 05, 2014
Programming
2k
1
Share
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
89
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
13k
How to use Apple iBeacons with Android
radzio
1
430
Overview of libraries and tools that make your Android development easier and faster
radzio
1
180
Other Decks in Programming
See All in Programming
実践ハーネスエンジニアリング:ステアリングループを実例から読み解く / Practical Harness Engineering: Understanding Steering Loops Through Real-World Examples
nrslib
5
5.1k
いつか誰かが、と思っていた フロントエンド刷新5年間の実践知
kiichisugihara
1
270
Road to RubyKaigi: Play Hard(ware)
makicamel
1
570
ハーネスエンジニアリングとは?
kinopeee
13
6.9k
Claude CodeでETLジョブ実行テストを自動化してみた
yoshikikasama
0
1.2k
空間オーディオの活用
objectiveaudio
0
150
過去のレビュー知見をSkillsで資産化した話
pkshadeck
PRO
1
1.8k
when storing skills in S3 file
watany
3
1.5k
SREに優しいTerraform構成 modulesとstateの組み方
hiyanger
2
170
〜バイブコーディングを超えて〜 チームで実験し続けたAI駆動開発
tigertora7571
0
200
Symfony AI in Action - SymfonyLive Berlin 2026
chr_hertel
1
140
My daily life on Ruby
a_matsuda
3
270
Featured
See All Featured
The Spectacular Lies of Maps
axbom
PRO
1
740
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
44
SEO for Brand Visibility & Recognition
aleyda
0
4.5k
Leo the Paperboy
mayatellez
7
1.8k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.9k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.1k
So, you think you're a good person
axbom
PRO
2
2k
Git: the NoSQL Database
bkeepers
PRO
432
67k
Evolving SEO for Evolving Search Engines
ryanjones
0
190
Designing for humans not robots
tammielis
254
26k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
160
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 { }