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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Radek Piekarz
December 05, 2014
Programming
2k
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
92
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
440
Overview of libraries and tools that make your Android development easier and faster
radzio
1
180
Other Decks in Programming
See All in Programming
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
160
Performance Engineering for Everyone
elenatanasoiu
0
220
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
300
Webフレームワークの ベンチマークについて
yusukebe
0
180
はてなアカウント基盤 State of the Union
cockscomb
1
720
エージェンティックRAGにAWSで入門しよう!
har1101
9
1.7k
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
210
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
320
OSもどきOS
arkw
0
590
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
150
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
210
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
270
Featured
See All Featured
BBQ
matthewcrist
89
10k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.2k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Believing is Seeing
oripsolob
1
150
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
140
How to Think Like a Performance Engineer
csswizardry
28
2.7k
[SF Ruby Conf 2025] Rails X
palkan
2
1.1k
Accessibility Awareness
sabderemane
1
140
Are puppies a ranking factor?
jonoalderson
1
3.6k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
170
Building the Perfect Custom Keyboard
takai
2
800
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
610
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 { }