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
Transcript
23 slides
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 { }
More Decks by Radek Piekarz
See All by Radek Piekarz
Nearby Notifications – annoy your friends!
radzio
1
110
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
470
Overview of libraries and tools that make your Android development easier and faster
radzio
1
200
Other Decks in Programming
See All in Programming
はじめてのPLATEAU
nokonoko1203
1
640
Web3Dライブラリを作ってVue Custom Rendererの仕組みを理解しよう / lets learn vue custom renderer by making 3d library
drumath2237
1
130
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
750
AI-Powered Domain-Driven Design
ziobrando
0
440
AI時代のIaC入門 〜なぜインフラをコードで管理したいのか?〜 / Introduction to IaC in the AI Era
akihisaikeda
6
1.5k
自作Discord音声botをLambda MicroVMsに移行した話 / Migrating My Discord Voice Bot to Lambda MicroVMs
akihisaikeda
1
310
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
2.3k
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
1.2k
AI駆動開発4年目の現在地(『あなたはFDEになるべきか?』イベント資料)
kumaiu
0
610
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
340
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
120
graphql-ruby を Spinel で速くしようとした話
mtsmfm
0
140
Featured
See All Featured
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8.2k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
48k
Building the Perfect Custom Keyboard
takai
2
950
How to Think Like a Performance Engineer
csswizardry
28
2.9k
Un-Boring Meetings
codingconduct
0
490
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
23k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1.1k
Rails Girls Zürich Keynote
gr2m
96
14k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
630
AI: The stuff that nobody shows you
jnunemaker
PRO
12
1.3k