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
android-testing-bootcamp-2
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Yuya Kaido
June 09, 2016
Programming
910
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
android-testing-bootcamp-2
Yuya Kaido
June 09, 2016
More Decks by Yuya Kaido
See All by Yuya Kaido
droidkaigi-2019
yuyakaido
7
4.9k
matching-dev-meetup-1
yuyakaido
1
240
minami-aoyama-night-6
yuyakaido
1
1.3k
eureka-meetup-10
yuyakaido
0
850
droidkaigi-2018
yuyakaido
4
6.2k
navitime-eureka-1
yuyakaido
0
110
droidkaigi-2017
yuyakaido
11
8.3k
retty-tech-cafe-8
yuyakaido
0
200
mti-eureka-tech-beer
yuyakaido
0
500
Other Decks in Programming
See All in Programming
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
260
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
210
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
430
Agentic UI
manfredsteyer
PRO
0
220
才能?センス?知らん、 続けたもん勝ちだ。-- 結婚・出産・癌を越えてなお、私がプロダクトを創り続ける理由
16bitidol
2
640
AIで効率化できた業務・日常
ochtum
0
160
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
280
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
570
Contextとはなにか
chiroruxx
1
390
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
150
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
14
6.6k
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
1k
Featured
See All Featured
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.6k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.9k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
210
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.5k
Embracing the Ebb and Flow
colly
88
5.1k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
180
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
380
Amusing Abliteration
ianozsvald
1
220
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Balancing Empowerment & Direction
lara
6
1.2k
Transcript
Advanced Dagger for Android Android Testing Bootcamp #2 yuyakaido
ࣗݾհ • ւ౻༏ʢ͔͍Ͳ͏Ώ͏ʣ • גࣜձࣾΤϨΧ • 1ͷΠϯλʔϯΛܦͯɺ20154݄ʹ৽ଔೖࣾ • ςετ͓͡͞Μ
yuyakaido yuyakaido
גࣜձࣾΤϨΧ • ࣗࣾαʔϏεͷاըɾ։ൃɾӡӦ • ΦϯϥΠϯσʔςΟϯάαʔϏεɿ • Χοϓϧઐ༻ΞϓϦɿ • ࣾһɿ104໊ •
IAC ΤϯδχΞ 51ਓ ඇΤϯδχΞ 53ਓ
࣍ • DIͱ • جૅฤ • Ԡ༻ฤ • ·ͱΊ
DIͱ • DI = Dependency Injection • ຊޠͰɺґଘੑೖ • ґଘੑͱ
ґଘੑ • Կͱ͋ΕɺίʔυΛݟͯΈΔ • GithubRepositoryΫϥε2ͭͷΫϥεʹґଘ • ΫϥεA͕ΫϥεBʹґଘ͍ͯ͠Δ͜ͱ͕ґଘੑ public class
GithubRepository { private GithubClient githubClient = new GithubClient(); private GithubDao githubDao = new GithubDao(); }
ґଘੑ • ґଘੑ͕ϕλॻ͖ͩͱԿ͕Ϛζ͍ͷ͔ • Ϣχοτςετ͕ࠔ • ґଘઌͷΫϥε͕ਖ਼ৗʹಈ͍͍ͯΔඞཁੑ • Կͱ͔ͯ͠ґଘੑΛഉআ͍ͨ͠ •
ͱΓ͋͑ͣηολʔΛఆٛ͢Ε͍͍ͷͰʁ
ґଘੑ • ଟগґଘԼ͕͕ͬͨɺࠜຊղܾʹͳͬͯͳ͍ • Ϣχοτςετ͕ࠔ • ґଘઌͷΫϥε͕ਖ਼ৗʹಈ͍͍ͯΔඞཁੑ public class
GithubRepository { private GithubClient githubClient; private GithubDao githubDao; public void setGithubClient(GithubClient githubClient) { this.githubClient = githubClient; } public void setGithubDao(GithubDao githubDao) { this.githubDao = githubDao; } }
public class GithubRepository { private GithubClient githubClient; private GithubDao githubDao;
public GithubRepository(GithubClient client, GithubDao dao) { this.githubClient = client; this.githubDao = dao; } } public interface GithubClient { /* লུ */ } public interface GithubDao { /* লུ */ } ґଘੑ • Ϣχοτςετ͕ࠔ • GithubClientɺGithubDaoΛϞοΫ͢Ε GithubRepositoryͷϢχοτςετ͕Մೳ • ґଘΫϥε͕ਖ਼ৗʹಈ࡞͍ͯ͠Δඞཁੑ • ͱΓ͋͑ͣϞοΫͯ͠͠·͑ಈ͘
DIͱ • DI = Dependency Injection • ຊޠͰɺґଘੑೖ • DI
= ґଘΛϕλॻ͖Λආ͚ΔͨΊͷΈ
Dagger • ಥવͰ͕͢ɺDagger2ͭ͋Γ·͢ • https://github.com/square/dagger • ΦϦδφϧͬͪ͜ • https://github.com/google/dagger •
square/daggerΛϕʔεʹͯ͠Google͕ख ΛೖΕͨͷ
جૅฤ • Inject • Module • Component • جຊతͳ͍ํ
Inject • @InjectΛॻ͘ͱΠϯελϯε͕ೖ͞ΕΔ public class GithubRepository { private GithubClient
githubClient; private GithubDao githubDao; public GithubRepository(GithubClient client, GithubDao dao) { this.githubClient = client; this.githubDao = dao; } }
Inject • @InjectΛॻ͘ͱΠϯελϯε͕ೖ͞ΕΔ public class GithubRepository { private GithubClient
githubClient; private GithubDao githubDao; @Inject public GithubRepository(GithubClient client, GithubDao dao) { this.githubClient = client; this.githubDao = dao; } }
Module • ੜ͢ΔΠϯελϯεΛఆٛ͢ΔΫϥε @Module public class GithubModule {
@Provides public GithubClient provideGithubClient() { return new GithubClientImpl(); } @Provides public GithubDao provideGithubDao() { return new GithubDaoImpl(); } }
Component • ModuleͱInjectରΫϥεͷؔΛఆٛ @Component(modules = {GithubModule.class}) public interface AppComponent
{ void inject(MainActivity mainActivity); }
جຊతͳ͍ํ • DaggerAppComponentΛॳظԽ public class Genesis extends Application {
private AppComponent appComponent; public static AppComponent getAppComponent(Context context) { Genesis genesis = (Genesis) context.getApplicationContext(); return genesis.appComponent; } @Override public void onCreate() { super.onCreate(); appComponent = DaggerAppComponent.builder().build(); } }
جຊతͳ͍ํ • Inject͢Δ public class MainActivity extends Activity {
@Inject GithubRepository githubRepository; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Genesis.getAppComponent(this).inject(this); } }
Ԡ༻ฤ • Dependencies • Subcomponent
લఏ • ΞϓϦͷنʹൺྫͯ͠ɺModule૿͑Δ • Module͕૿͑ΔͱComponent͕ڊେԽ͍ͯ͘͠
Dependencies Subcomponent ͱ • ΞϓϦͷنʹൺྫͯ͠ɺModule૿͑Δ • Moduleͷཧํ๏ • Dependencies •
Subcomponent
Dependencies • ґଘ͍ͯ͠ΔModuleΛྻڍ @Component(dependencies = {GithubModule.class}) public interface AppComponent
{ void inject(MainActivity mainActivity); }
Dependencies • ґଘ͍ͯ͠ΔModuleΛྻڍ @Component(dependencies = {GithubModule.class}) public interface AppComponent
{ void inject(MainActivity mainActivity); }
Subcomponent • ComponentΛ֊Խ͢Δ @ScreenScope @Subcomponent(modules = {InstagramModule.class}) public interface
InstagramComponent { void inject(InstagramActivity instagramActivity); }
Subcomponent • ComponentΛ֊Խ͢Δ @ScreenScope @Subcomponent(modules = {InstagramModule.class}) public interface
InstagramComponent { void inject(InstagramActivity instagramActivity); }
Dependencies Subcomponent • Dependencies • ґଘ͍ͯ͠ΔModuleΛྻڍ • Subcomponent • ComponentΛ֊Խ
Dependencies Subcomponent ͷҧ͍ • Dependencies • શͯͷModule͕1ͭͷComponentʹॴଐ • Subcomponent •
Componentࣗମ͕֊Խ͞ΕɺͦΕͧΕ ͷComponent͕ModuleΛཧ ͳΔ΄Ͳɺ͔ΒΜ
Dependencies AppComponent FooModule BarModule
Subcomponent AppComponent FooComponent BarComponent
Dependencies Subcomponent • ͲͪΒΛ͏͖͔ • ن͕খ͚͞ΕɺDependencies • ͋ΔఔͷنΛఆ͢ΔͳΒɺSubcomponent • Dependenciesͩͱ1ͭͷComponent͕શͯͷґ
ଘΠϯελϯεΛཧ͢Δ͜ͱʹɺɺ
·ͱΊ • DIͱԿͳͷ͔ • ґଘੑΛϕλॻ͖͠ͳ͍ͨΊͷΈ • Daggerجૅฤ • ModuleͱComponent •
DaggerԠ༻ฤ • DependenciesͱSubcomponent
ࢀߟ • ཁ͢Δʹ DI ͬͯԿͳͷͱ͍͏ • http://nekogata.hatenablog.com/entry/ 2014/02/13/073043 • Android:
Dagger2 - Subcomponent vs. dependencies • http://yuki312.blogspot.jp/2016/02/android-dagger2- subcomponent-vs.html
Thank you :) Credit: NASA Earth Observatory/NOAA NGDC