SlideShare a Scribd company logo
1 of 18
Download to read offline
MANAGE DI WITH DAGGER2
Philips CDPTechTalks #15
QUIZ
• ?
• ?
• ?
QUIZ
• What is dependencies injection?
• ?
• ?
QUIZ
• What is dependencies injection?
• Dependencies injection and dependencies
inversion?
• ?
QUIZ
• What is dependencies injection?
• Dependencies injection and dependencies
inversion?
• Who worked with Dagger2?
SEPARATE CONSTRUCTION
AND USAGE
WRONG
public Car() {
this.motor = new Motor();
}
RIGHT
public Car(Motor motor) {
this.motor = motor;
}
DI LIBRARIES
• RoboGuice
• Dagger 1 (Classis)
• Dagger 2
DI LIBRARIES
• RoboGuice
• Dagger 1 (Classis)
• Dagger 2
ANNOTATIONS
• @Module for the classes whose methods provide
dependencies
• @Provides for the methods within @Module classes
• @Inject to request a dependency
• @Component, @Subcomponent are bridge
interfaces between modules and injection
EXAMPLE
• A pet project with Dagger 2
ANNOTATIONS
• @Module for the classes whose methods provide
dependencies
• @Provides for the methods within @Module classes
• @Inject to request a dependency
• @Component, @Subcomponent are bridge
interfaces between modules and injection
SCOPES
• Within scope Dagger will return same instance of
the dependency
SCOPES
• @Singlethon
• @Scope
@NAMED
@Provides @Named("cached")
OkHttpClient provideOkHttpClient(Cache cache) {
OkHttpClient client = new OkHttpClient();
client.setCache(cache);
return client;
}
@Provides @Named("non_cached")
OkHttpClient provideOkHttpClient() {
return new OkHttpClient();
}
@NAMED
@Inject @Named("cached") OkHttpClient
cachedClient;
@Inject @Named("non_cached") OkHttpClient
nonCachedClient;
Q&A
• https://lostechies.com/derickbailey/2011/09/22/dependency-injection-is-not-the-same-as-the-dependency-
inversion-principle/
• https://en.wikipedia.org/wiki/Dependency_injection
• http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/
• http://blog.nimbledroid.com/2016/03/07/performance-of-dependency-injection-libraries.html
• http://google.github.io/dagger/
• https://github.com/codepath/android_guides/wiki/Dependency-Injection-with-Dagger-2
• https://www.youtube.com/watch?v=oK_XtfXPkqw
• https://www.youtube.com/watch?v=HAzu57MrGgA
• https://www.youtube.com/watch?v=3B7F7emCc64

More Related Content

What's hot

What's hot (20)

Android Modularization
Android ModularizationAndroid Modularization
Android Modularization
 
[Android] DI in multimodule application
[Android] DI in multimodule application[Android] DI in multimodule application
[Android] DI in multimodule application
 
Memulai Karir menjadi iOS Developer - Gilang ramadhan (Academy Content Writer...
Memulai Karir menjadi iOS Developer - Gilang ramadhan (Academy Content Writer...Memulai Karir menjadi iOS Developer - Gilang ramadhan (Academy Content Writer...
Memulai Karir menjadi iOS Developer - Gilang ramadhan (Academy Content Writer...
 
Dagger 2 - Ciklum Speakers' Corner
Dagger 2 - Ciklum Speakers' CornerDagger 2 - Ciklum Speakers' Corner
Dagger 2 - Ciklum Speakers' Corner
 
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan KuštInfinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
 
Angular 2... so can I use it now??
Angular 2... so can I use it now??Angular 2... so can I use it now??
Angular 2... so can I use it now??
 
Android application architecture
Android application architectureAndroid application architecture
Android application architecture
 
Lecture java basics
Lecture   java basicsLecture   java basics
Lecture java basics
 
Dependency injection: koin vs dagger
Dependency injection: koin vs daggerDependency injection: koin vs dagger
Dependency injection: koin vs dagger
 
Angular 2
Angular 2Angular 2
Angular 2
 
React Nativeの光と闇
React Nativeの光と闇React Nativeの光と闇
React Nativeの光と闇
 
JUnit 5 — New Opportunities for Testing on the JVM
JUnit 5 — New Opportunities for Testing on the JVMJUnit 5 — New Opportunities for Testing on the JVM
JUnit 5 — New Opportunities for Testing on the JVM
 
Adventures with Angular 2
Adventures with Angular 2Adventures with Angular 2
Adventures with Angular 2
 
Reason to choose Angular JS for your Web Application
Reason to choose Angular JS for your Web ApplicationReason to choose Angular JS for your Web Application
Reason to choose Angular JS for your Web Application
 
Angular
AngularAngular
Angular
 
Moved to https://slidr.io/azzazzel/what-s-not-new-in-modular-java
Moved to https://slidr.io/azzazzel/what-s-not-new-in-modular-javaMoved to https://slidr.io/azzazzel/what-s-not-new-in-modular-java
Moved to https://slidr.io/azzazzel/what-s-not-new-in-modular-java
 
Dependency injection
Dependency injectionDependency injection
Dependency injection
 
Reactjs
ReactjsReactjs
Reactjs
 
Menggunakan NoSQL Database di Aplikasi Android - Ahmad Imaduddin (Google Asso...
Menggunakan NoSQL Database di Aplikasi Android - Ahmad Imaduddin (Google Asso...Menggunakan NoSQL Database di Aplikasi Android - Ahmad Imaduddin (Google Asso...
Menggunakan NoSQL Database di Aplikasi Android - Ahmad Imaduddin (Google Asso...
 
Angular 2 - The Next Framework
Angular 2 - The Next FrameworkAngular 2 - The Next Framework
Angular 2 - The Next Framework
 

Similar to DI with Dagger2

Ідіоматична ін'єкція залежностей на Kotlin без фреймворків - UA Mobile2019
Ідіоматична ін'єкція залежностей на Kotlin без фреймворків - UA Mobile2019Ідіоматична ін'єкція залежностей на Kotlin без фреймворків - UA Mobile2019
Ідіоматична ін'єкція залежностей на Kotlin без фреймворків - UA Mobile2019
UA Mobile
 

Similar to DI with Dagger2 (20)

The Power of Dependency Injection with Dagger 2 and Kotlin
The Power of Dependency Injection with Dagger 2 and KotlinThe Power of Dependency Injection with Dagger 2 and Kotlin
The Power of Dependency Injection with Dagger 2 and Kotlin
 
Di with dagger2 in android
Di with dagger2 in androidDi with dagger2 in android
Di with dagger2 in android
 
DIC To The Limit – deSymfonyDay, Barcelona 2014
DIC To The Limit – deSymfonyDay, Barcelona 2014DIC To The Limit – deSymfonyDay, Barcelona 2014
DIC To The Limit – deSymfonyDay, Barcelona 2014
 
Writing testable Android apps
Writing testable Android appsWriting testable Android apps
Writing testable Android apps
 
King Tut Architecture
King Tut ArchitectureKing Tut Architecture
King Tut Architecture
 
Android Dagger 2
Android  Dagger 2Android  Dagger 2
Android Dagger 2
 
ColdBox Hierarchical MVC - Transform Your Monolith
ColdBox Hierarchical MVC - Transform Your MonolithColdBox Hierarchical MVC - Transform Your Monolith
ColdBox Hierarchical MVC - Transform Your Monolith
 
Ідіоматична ін'єкція залежностей на Kotlin без фреймворків - UA Mobile2019
Ідіоматична ін'єкція залежностей на Kotlin без фреймворків - UA Mobile2019Ідіоматична ін'єкція залежностей на Kotlin без фреймворків - UA Mobile2019
Ідіоматична ін'єкція залежностей на Kotlin без фреймворків - UA Mobile2019
 
Dagger 2, 2 years later
Dagger 2, 2 years laterDagger 2, 2 years later
Dagger 2, 2 years later
 
Introduction to Dagger 2 by Ratanak
Introduction to Dagger 2 by RatanakIntroduction to Dagger 2 by Ratanak
Introduction to Dagger 2 by Ratanak
 
Introduction to Depedency Injection in Android
Introduction to Depedency Injection in AndroidIntroduction to Depedency Injection in Android
Introduction to Depedency Injection in Android
 
Alex Theedom Java ee revisits design patterns
Alex Theedom	Java ee revisits design patternsAlex Theedom	Java ee revisits design patterns
Alex Theedom Java ee revisits design patterns
 
SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"
 
Dependency injection using Google guice
Dependency injection using Google guiceDependency injection using Google guice
Dependency injection using Google guice
 
Angular TS(typescript)
Angular TS(typescript)Angular TS(typescript)
Angular TS(typescript)
 
Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelines
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
TypeScript and Angular workshop
TypeScript and Angular workshopTypeScript and Angular workshop
TypeScript and Angular workshop
 
Protractor survival guide
Protractor survival guideProtractor survival guide
Protractor survival guide
 
Java 9 Jigsaw HackDay
Java 9 Jigsaw HackDayJava 9 Jigsaw HackDay
Java 9 Jigsaw HackDay
 

More from Eugen Martynov

More from Eugen Martynov (13)

Kotlin Script
Kotlin ScriptKotlin Script
Kotlin Script
 
My path to freelance
My path to freelanceMy path to freelance
My path to freelance
 
Gradle Again
Gradle AgainGradle Again
Gradle Again
 
Android CD
Android CDAndroid CD
Android CD
 
Lokalise
LokaliseLokalise
Lokalise
 
Facebook Stetho
Facebook StethoFacebook Stetho
Facebook Stetho
 
Template project
Template projectTemplate project
Template project
 
Robolectric v2
Robolectric v2Robolectric v2
Robolectric v2
 
Android Brown Bag Lunch - DroidconNL overview
Android Brown Bag Lunch - DroidconNL overviewAndroid Brown Bag Lunch - DroidconNL overview
Android Brown Bag Lunch - DroidconNL overview
 
Flow
FlowFlow
Flow
 
Robolectric Adventure
Robolectric AdventureRobolectric Adventure
Robolectric Adventure
 
Mobile developer is Software developer
Mobile developer is Software developerMobile developer is Software developer
Mobile developer is Software developer
 
XP Days UA Pecha kucha
XP Days UA Pecha kuchaXP Days UA Pecha kucha
XP Days UA Pecha kucha
 

Recently uploaded

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Recently uploaded (20)

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 

DI with Dagger2