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
190
AbemaTVを支えるアプリの優しさ / abematv_devcon_2017
ogaclejapan
3
6.5k
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
Package Traits
ikesyo
1
200
Azure AI Foundryのご紹介
qt_luigi
1
140
2025.01.17_Sansan × DMM.swift
riofujimon
2
520
QA環境で誰でも自由自在に現在時刻を操って検証できるようにした話
kalibora
1
140
GitHub CopilotでTypeScriptの コード生成するワザップ
starfish719
26
5.9k
.NETでOBS Studio操作してみたけど…… / Operating OBS Studio by .NET
skasweb
0
120
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
6
1.4k
DevinとCursorから学ぶAIエージェントメモリーの設計とMoatの考え方
itarutomy
0
110
Оптимизируем производительность блока Казначейство
lamodatech
0
940
AppRouterを用いた大規模サービス開発におけるディレクトリ構成の変遷と問題点
eiganken
1
440
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
630
ESLintプラグインを使用してCDKのセオリーを適用する
yamanashi_ren01
2
220
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
51
7.3k
Testing 201, or: Great Expectations
jmmastey
41
7.2k
Docker and Python
trallard
43
3.2k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
Designing for humans not robots
tammielis
250
25k
Building Applications with DynamoDB
mza
93
6.2k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
860
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
3
170
Become a Pro
speakerdeck
PRO
26
5.1k
Measuring & Analyzing Core Web Vitals
bluesmoon
5
200
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.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