Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Dagger 2.0 - new dependency injection for Andro...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Radek Piekarz
December 05, 2014
Programming
2.1k
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
100
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
14k
How to use Apple iBeacons with Android
radzio
1
460
Overview of libraries and tools that make your Android development easier and faster
radzio
1
190
Other Decks in Programming
See All in Programming
速習iPhone Duo対応
yuukiw00w
2
910
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
170
TiDB Cloudのカスタムコントローラーによるオートスケール対応
takaidohigasi
0
140
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
330
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
1
660
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.6k
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
SREの越境 / SRE Collaboration
y0hgi
2
290
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
5
9.2k
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
320
Security issues being discussed on Web Platforms
petamoriken
0
1.4k
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
5.2k
Featured
See All Featured
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
620
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
750
Six Lessons from altMBA
skipperchong
29
4.5k
Producing Creativity
orderedlist
PRO
348
41k
The SEO identity crisis: Don't let AI make you average
varn
0
560
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
58k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
290
Un-Boring Meetings
codingconduct
0
430
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.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 { }