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
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
73
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
競馬で学ぶ機械学習の基本と実践 / Machine Learning with Horse Racing
shoheimitani
14
14k
AIの弱点、やっぱりプログラミングは人間が(も)勉強しよう / YAPC AI and Programming
kishida
13
5.4k
開発生産性が組織文化になるまでの軌跡
tonegawa07
0
190
ソフトウェア設計の課題・原則・実践技法
masuda220
PRO
22
18k
JEP 496 と JEP 497 から学ぶ耐量子計算機暗号入門 / Learning Post-Quantum Crypto Basics from JEP 496 & 497
mackey0225
2
500
Feature Flags Suck! - KubeCon Atlanta 2025
phodgson
0
170
Rails Girls Sapporo 2ndの裏側―準備の日々から見えた、私が得たもの / SAPPORO ENGINEER BASE #11
lemonade_37
2
190
開発15年のAIネイティブでない 巨大サービスのAI最適化
rapicro
0
100
Stay Hacker 〜九州で生まれ、Perlに出会い、コミュニティで育つ〜
pyama86
2
2.6k
Combinatorial Interview Problems with Backtracking Solutions - From Imperative Procedural Programming to Declarative Functional Programming - Part 1
philipschwarz
PRO
0
110
Micro Frontendsで築いた 共通基盤と運用の試行錯誤 / Building a Shared Platform with Micro Frontends: Operational Learnings
kyntk
0
1.6k
高単価案件で働くための心構え
nullnull
0
170
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
680
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.3k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
A Tale of Four Properties
chriscoyier
162
23k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
1
56
Mobile First: as difficult as doing things right
swwweet
225
10k
Scaling GitHub
holman
464
140k
Raft: Consensus for Rubyists
vanstee
140
7.2k
Become a Pro
speakerdeck
PRO
30
5.6k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
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 { }