SlideShare a Scribd company logo
Dependency Injection
Using Dagger 2
What is Dependency Injection ?
It’s Famous and everybody is talking about it.
You might be using it without writing the independent examples.
Butterknife is the hint
What is Dependency ?
Class Car{
getPermittedSpeed(String country){
TrafficRules rules=new Traficrules(); // Dependency
rules.getSpeed(country);
}
getAgeLimit(String country){
TrafficRules rules=new Traficrules(); // Dependency
rules.getAgeLimit(country);
}
}
Class Car{
getPermittedSpeed(String country,TrafficRules rule){
rule.getSpeed(country);
}
getAgeLimit(String country, TrafficRules rule){
rule.getAgeLimit();
}
}
This is Dependency Injection
// Only god can create perfectly not you, so dont create us simply call us
Class Car{
TrafficRules rules;
Car(){
rules=new TrafficRules();
}
// Dependency Resolved
getPermittedSpeed(String country){
rules.getSpeed(country);
}
getAgeLimit(String country)...
}
Wrong ! You cannot create you
should only call
Class Car{
TrafficRules rules;
Car(TrafficRules rules){
this.rules= rules;
}
// Dependency Resolved
getPermittedSpeed(String country){
rules.getSpeed(country);
}
getAgeLimit(String country)...
}
Now you are a good guy!
This is correct as we are not
creating but calling
Someone have to do the god’s job of Creation!
Class Car{
@Inject
TrafficRules rules; // Will be done by Libraries like Dagger ?
// Dependency Resolved
getPermittedSpeed(String country){
rules.getSpeed(country);
}
}
Welcome to Dagger 2
How did dagger2 know to create object ?
Secret: You will tell Dagger2, what objects it has to
create
Dagger2 usage
Tell 3 Things to Dagger2
> What are the Objects Dagger 2 has to create for you
> What functions it has call for creating these Objects ?
> Where all it has to inject these pre created Objects
Dagger2 usage
Tell 3 Things to Dagger2
> What are the Objects Dagger 2 has to create for you
> What functions it has call for creating these Objects ?
> Where all it has to inject these pre created Objects
@Modules
@Provides
@Component
THANK
YOU

More Related Content

More from Cumulations Technologies

Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging
Push Notification for Android, iOS & Sever Side Using Firebase Cloud MessagingPush Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging
Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging
Cumulations Technologies
 
Understanding of iBeacons for BLE Projects
Understanding of iBeacons for BLE Projects Understanding of iBeacons for BLE Projects
Understanding of iBeacons for BLE Projects
Cumulations Technologies
 
Understanding of MQTT for IoT Projects
Understanding of MQTT for IoT ProjectsUnderstanding of MQTT for IoT Projects
Understanding of MQTT for IoT Projects
Cumulations Technologies
 
Android App with Meatwear
Android App with MeatwearAndroid App with Meatwear
Android App with Meatwear
Cumulations Technologies
 
On Problems, Products and IoT by Tej | CuTech Talks
On Problems, Products and IoT by Tej | CuTech TalksOn Problems, Products and IoT by Tej | CuTech Talks
On Problems, Products and IoT by Tej | CuTech Talks
Cumulations Technologies
 
Modes of Communication by Cumulations | CuTech Talks
Modes of Communication by Cumulations | CuTech TalksModes of Communication by Cumulations | CuTech Talks
Modes of Communication by Cumulations | CuTech Talks
Cumulations Technologies
 
IoT Protocols by Nagasai Panchakarla | CuTech Talks
IoT Protocols by Nagasai Panchakarla | CuTech TalksIoT Protocols by Nagasai Panchakarla | CuTech Talks
IoT Protocols by Nagasai Panchakarla | CuTech Talks
Cumulations Technologies
 
IoT(internet of Things) Basics
IoT(internet of Things)  BasicsIoT(internet of Things)  Basics
IoT(internet of Things) Basics
Cumulations Technologies
 
Retrofit Technology Overview by Cumulations Technologies
Retrofit Technology Overview by Cumulations TechnologiesRetrofit Technology Overview by Cumulations Technologies
Retrofit Technology Overview by Cumulations Technologies
Cumulations Technologies
 

More from Cumulations Technologies (9)

Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging
Push Notification for Android, iOS & Sever Side Using Firebase Cloud MessagingPush Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging
Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging
 
Understanding of iBeacons for BLE Projects
Understanding of iBeacons for BLE Projects Understanding of iBeacons for BLE Projects
Understanding of iBeacons for BLE Projects
 
Understanding of MQTT for IoT Projects
Understanding of MQTT for IoT ProjectsUnderstanding of MQTT for IoT Projects
Understanding of MQTT for IoT Projects
 
Android App with Meatwear
Android App with MeatwearAndroid App with Meatwear
Android App with Meatwear
 
On Problems, Products and IoT by Tej | CuTech Talks
On Problems, Products and IoT by Tej | CuTech TalksOn Problems, Products and IoT by Tej | CuTech Talks
On Problems, Products and IoT by Tej | CuTech Talks
 
Modes of Communication by Cumulations | CuTech Talks
Modes of Communication by Cumulations | CuTech TalksModes of Communication by Cumulations | CuTech Talks
Modes of Communication by Cumulations | CuTech Talks
 
IoT Protocols by Nagasai Panchakarla | CuTech Talks
IoT Protocols by Nagasai Panchakarla | CuTech TalksIoT Protocols by Nagasai Panchakarla | CuTech Talks
IoT Protocols by Nagasai Panchakarla | CuTech Talks
 
IoT(internet of Things) Basics
IoT(internet of Things)  BasicsIoT(internet of Things)  Basics
IoT(internet of Things) Basics
 
Retrofit Technology Overview by Cumulations Technologies
Retrofit Technology Overview by Cumulations TechnologiesRetrofit Technology Overview by Cumulations Technologies
Retrofit Technology Overview by Cumulations Technologies
 

Recently uploaded

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 

Recently uploaded (20)

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 

Dependency Injection in Android with Dagger 2

  • 2. What is Dependency Injection ? It’s Famous and everybody is talking about it. You might be using it without writing the independent examples. Butterknife is the hint
  • 3. What is Dependency ? Class Car{ getPermittedSpeed(String country){ TrafficRules rules=new Traficrules(); // Dependency rules.getSpeed(country); } getAgeLimit(String country){ TrafficRules rules=new Traficrules(); // Dependency rules.getAgeLimit(country); } }
  • 4. Class Car{ getPermittedSpeed(String country,TrafficRules rule){ rule.getSpeed(country); } getAgeLimit(String country, TrafficRules rule){ rule.getAgeLimit(); } } This is Dependency Injection // Only god can create perfectly not you, so dont create us simply call us
  • 5. Class Car{ TrafficRules rules; Car(){ rules=new TrafficRules(); } // Dependency Resolved getPermittedSpeed(String country){ rules.getSpeed(country); } getAgeLimit(String country)... } Wrong ! You cannot create you should only call
  • 6. Class Car{ TrafficRules rules; Car(TrafficRules rules){ this.rules= rules; } // Dependency Resolved getPermittedSpeed(String country){ rules.getSpeed(country); } getAgeLimit(String country)... } Now you are a good guy! This is correct as we are not creating but calling
  • 7. Someone have to do the god’s job of Creation!
  • 8. Class Car{ @Inject TrafficRules rules; // Will be done by Libraries like Dagger ? // Dependency Resolved getPermittedSpeed(String country){ rules.getSpeed(country); } } Welcome to Dagger 2
  • 9. How did dagger2 know to create object ? Secret: You will tell Dagger2, what objects it has to create
  • 10. Dagger2 usage Tell 3 Things to Dagger2 > What are the Objects Dagger 2 has to create for you > What functions it has call for creating these Objects ? > Where all it has to inject these pre created Objects
  • 11. Dagger2 usage Tell 3 Things to Dagger2 > What are the Objects Dagger 2 has to create for you > What functions it has call for creating these Objects ? > Where all it has to inject these pre created Objects @Modules @Provides @Component