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
Dagger2 has been released!
Search
Masaki Ogata
April 15, 2015
Programming
3
3.2k
Dagger2 has been released!
Migrated story from Dagger1 to Dagger2 in Qiitanium App
Masaki Ogata
April 15, 2015
Tweet
Share
More Decks by Masaki Ogata
See All by Masaki Ogata
Jetpack Composeで始めるServer Cache State
ogaclejapan
2
160
AbemaTVを支えるアプリの優しさ / abematv_devcon_2017
ogaclejapan
3
6.4k
Architecture Components - Lifecycle library
ogaclejapan
3
2.3k
How to keep data between orientation changes
ogaclejapan
7
2.5k
Your app name
ogaclejapan
1
2.8k
Flux de Relax :)
ogaclejapan
13
61k
Other Decks in Programming
See All in Programming
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
330
tidymodelsによるtidyな生存時間解析 / Japan.R2024
dropout009
1
720
Full stack testing :: basic to basic
up1
1
930
ソフトウェアの振る舞いに着目し 複雑な要件の開発に立ち向かう
rickyban
0
890
暇に任せてProxmoxコンソール 作ってみました
karugamo
1
710
N.E.X.T LEVEL
pluu
2
300
快速入門可觀測性
blueswen
0
310
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
610
複雑な仕様に立ち向かうアーキテクチャ
myohei
0
170
バグを見つけた?それAppleに直してもらおう!
uetyo
0
170
14 Years of iOS: Lessons and Key Points
seyfoyun
1
770
Featured
See All Featured
Optimising Largest Contentful Paint
csswizardry
33
3k
Why Our Code Smells
bkeepers
PRO
335
57k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
For a Future-Friendly Web
brad_frost
175
9.4k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
A Philosophy of Restraint
colly
203
16k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
440
Automating Front-end Workflow
addyosmani
1366
200k
GraphQLとの向き合い方2022年版
quramy
44
13k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.3k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Transcript
Dagger 2.0 has been released! at potatotips #16
About me Job $> Android Engineer v0.1 GitHub $> https://github.com/ogaclejapan
Company $> CyberAgent, Inc. Name $> Masaki Ogata (@ogaclejapan)
Qiitanium
http://github.com/ogaclejapan/qiitanium ɾRxJava ɾClean Architecture + MVVMʢࣗশʣ ɾDagger ɾOkHttp
http://github.com/ogaclejapan/qiitanium ɾ ɾ ɾDagger ɾ
http://github.com/ogaclejapan/qiitanium ɾ ɾ ɾDagger 1.x ɾ Dagger 2.0 Migrated!
About Dagger
About Dagger Let me ask Wasabeef !! https://speakerdeck.com/wasabeef/dagger at potatotips
#9
Dagger2.0 Overview
100% Proguard friendly @Generated("dagger.internal.codegen.ComponentProcessor") public final class AppModule_ProvideApplicationFactory implements Factory<Application>
{ private final AppModule module; @Override public Application get() { Application provided = module.provideApplication(); if (provided == null) { throw new NullPointerException("Cannot return null from a non-@Nullable @Provides method"); } return provided; } }
100% Proguard friendly ɾ θϩϦϑϨΫγϣϯ ɾ ࣗಈੜίʔυσόοάτϨʔε͕Մೳ ɾύϑΥʔϚϯε্͕
@Component Dagger1: FeatureModule ObjectGraph SubModule1 SubModule2 SubModule3 load Includes AppModule
plus SubGraph
@Component Dagger1: @Module(includes={Module1.class, …}, injects={…}) public class AppModule { @Provided
public Hoge provideHoge() { return new Hoge(); } } ObjectGraph graph = ObjectGraph.create(new Object[] { new AppModule()}); graph.inject(this); ObjectGraph sub = graph.plus(new FeatureModule());
@Component Dagger2: AppComponent FeatureComponent Module1 Module2 Module3 modules FeatureModule AppModule
modules dependencies
@Component Dagger2: @Component(modules={ AppModule.class, …}) public interface AppComponent { public
void inject(Application app); } @Generated(“…”) public class DaggerAppComponent { //… } Annotation Processor AppComponent component = DaggerAppComponent.builder() .appModule(…).build(); component.inject(this);
Migrate Dagger 1.x to 2.0 (ͦͷұ)
Scope @Module public class Module1 { @Singleton @Provided public Hoge
provideHoge() { return new Hoge(); } } @Component(modules = { Module1.class }) public interface AppComponent { //… }
Error: AppComponent (unscoped) may not reference scoped bindings: @Singleton @Provides
Hoge Compile Error…
Fix @Module public class @Provided public return new } }
@Component(modules = { public interface AppComponent { //… } @Singleton
Custom Scope Component୯ҐͰΠϯελϯεΛཧ͍ͯ͠Δ @Generated(“…”) public final class DaggerAppComponent { //…
private void initialize(final Builder builder) { this.…Provider = ScopedProvider.create(…); } //… } ScopedProviderͰSingleton੍ޚ͕͞Ε͍ͯΔ
Custom Scope @Scope @Retention(RetentionPolicy.RUNTIME) public @interface PerActivity { } @Module(modules={…})
public class ActivityModule { @PerActivity @Provided public Hoge provideHoge() { return new Hoge(); } } Dagger2ͰScopeΛಠࣗʹఆٛͯ͠͏
Migrate Dagger 1.x to 2.0 (ͦͷ್)
Override Module Dagger1: src/debug/java/.. @Module(addsTo=AppModule.class, override=true, …) public class DebugAppModule
{ @Singleton @Provided public Hoge provideHoge() { return new DebugHoge(); } } class Modules { Object[] list() { return ObjectGraph.create(new Object[] { new AppModule(), new DebugAppModule }); } }
Override Module Dagger2: src/debug/java/.. @Module(addsTo=AppModule.class, override=true, …) public class DebugAppModule
{ @Singleton @Provided public Hoge provideHoge() { return new DebugHoge(); } } class Modules { Object[] list() { return ObjectGraph.create(new Object[] { new AppModule(), new DebugAppModule }); } }
Override Module Dagger2: src/debug/java/.. @Module(addsTo=AppModule.class, override=true, …) public class DebugAppModule
extends AppModule { @Singleton @Provided public Hoge provideHoge() { return new DebugHoge(); } } class Modules { Object[] list() { return ObjectGraph.create(new Object[] { new AppModule(), new DebugAppModule }); } }
Override Module Dagger2: src/debug/java/.. @Module(addsTo=AppModule.class, override=true, …) public class DebugAppModule
extends AppModule { @Singleton @Provided @Override public Hoge provideHoge() { return new DebugHoge(); } } class Modules { Object[] list() { return ObjectGraph.create(new Object[] { new AppModule(), new DebugAppModule }); } }
Override Module Dagger2: src/debug/java/.. @Module(addsTo=AppModule.class, override=true, …) public class DebugAppModule
extends AppModule { @Singleton @Provided @Override public Hoge provideHoge() { return new DebugHoge(); } } class Modules { Object[] list() { return ObjectGraph.create(new Object[] { new AppModule(), new DebugAppModule }); } }
Override Module Dagger2: src/debug/java/.. @Module(addsTo=AppModule.class, override=true, …) public class DebugAppModule
extends AppModule { @Singleton @Provided @Override public Hoge provideHoge() { return new DebugHoge(); } } class Modules { AppModule appModule() { return new DebugAppModule(); } }
Override Module Dagger2: src/main/java/.. public class MyApplication extends Application {
@Inject Hoge mHoge; @Override public void onCreate() { AppComponent component = DaggerAppComponent.builder() .appModule(Modules.appModule()) .build(); component.inject(this); System.out.println(mHoge instanceof DebugHoge); //true } }
Let’s enjoy Dagger2 !!
͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ m(_ _)m