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 Android (Droidcon Krakow 2014)
Search
Radek Piekarz
December 05, 2014
Programming
1
1.7k
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
0
56
Deep dive into Android Data Binding
radzio
4
2.3k
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
390
Overview of libraries and tools that make your Android development easier and faster
radzio
1
160
Other Decks in Programming
See All in Programming
TCAとKMPを用いた新規動画配信アプリ 「ABEMA Live」の設計
tomu28
1
110
Goのエラースタックトレースの歴史と今後
sonatard
9
1.5k
Ruby Function Composition
bkuhlmann
1
330
Rethinking UI building strategies @ SFI 2024
letelete
0
270
PHP8.3の機能を振り返る / Review of PHP 8.3 features
seike460
PRO
1
110
Kotlin Multiplatform at Stable and Beyond (Android Makers 2024)
zsmb
0
260
Site Reliability Engineering for GMO
pyama86
8
1k
Node.js v22 で変わること
yosuke_furukawa
PRO
9
3.4k
OpenAPIを中心に考えるAPI開発入門 / Introduction to API Development with a Focus on OpenAPI
seike460
PRO
2
170
大規模Reactアプリのリアーキテクチャ~8万行のTanStack Query移行の軌跡~
kj455
4
960
『Railsオワコン』と言われる時代に、なぜブルーモ証券はRailsを選ぶのか
free_world21
0
240
0→1と1→10の狭間で Javaという技術選定を振り返る/Reflecting on the Decision to Choose Java Between Scaling from 0 to 1 and 1 to 10
jaguar_imo
2
380
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
7
1k
Code Reviewing Like a Champion
maltzj
514
39k
How To Stay Up To Date on Web Technology
chriscoyier
782
250k
What’s in a name? Adding method to the madness
productmarketing
PRO
16
2.6k
Intergalactic Javascript Robots from Outer Space
tanoku
266
26k
BBQ
matthewcrist
80
8.8k
Robots, Beer and Maslow
schacon
PRO
155
7.9k
The Language of Interfaces
destraynor
151
23k
A Philosophy of Restraint
colly
197
16k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
34
8.9k
The Art of Programming - Codeland 2020
erikaheidi
42
12k
Optimizing for Happiness
mojombo
370
69k
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 { }