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
1.9k
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
69
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
400
Overview of libraries and tools that make your Android development easier and faster
radzio
1
170
Other Decks in Programming
See All in Programming
Building, Deploying, and Monitoring Ruby Web Applications with Falcon (Kaigi on Rails 2025)
ioquatix
4
2.1k
overlayPreferenceValue で実現する ピュア SwiftUI な AdMob ネイティブ広告
uhucream
0
180
Flutterで分数(Fraction)を表示する方法
koukimiura
0
130
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
330
What's new in Spring Modulith?
olivergierke
1
140
Railsだからできる 例外業務に禍根を残さない 設定設計パターン
ei_ei_eiichi
0
620
Go言語はstack overflowの夢を見るか?
logica0419
0
260
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
0
240
技術的負債の正体を知って向き合う / Facing Technical Debt
irof
0
170
Go言語の特性を活かした公式MCP SDKの設計
hond0413
1
230
複雑化したリポジトリをなんとかした話 pipenvからuvによるモノレポ構成への移行
satoshi256kbyte
1
1.1k
Foundation Modelsを実装日本語学習アプリを作ってみた!
hypebeans
0
110
Featured
See All Featured
Faster Mobile Websites
deanohume
310
31k
Building a Scalable Design System with Sketch
lauravandoore
463
33k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
657
61k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.6k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.6k
How to train your dragon (web standard)
notwaldorf
96
6.3k
GraphQLとの向き合い方2022年版
quramy
49
14k
Scaling GitHub
holman
463
140k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
19
1.2k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
189
55k
Producing Creativity
orderedlist
PRO
347
40k
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 { }