SlideShare uma empresa Scribd logo
1 de 11
Baixar para ler offline
Dagger
Presenter : Ramesh Akula
http://about.me/aramesh
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.squareup.dagger:dagger:1.2.+'
provided 'com.squareup.dagger:dagger-compiler:1.2.+'
}
Gradle Dependencies
❖ @Module : Identify this class as a Dagger module.
❖ @Inject : Classes where this module is going to inject any of
its dependencies. Specify those classes that are directly
injected into object graph.
❖ @Provides: Identify method as an injection provider. The name
of the method doesn’t matter, it only relies on what class type
is provided.
Introduction
@Module(
complete = false,
library = true
)
public class DemoModule {
//Provide log object
@Provides
@Singleton
public Log provideLog() {
return new LogImpl();
}
}
Create a Module (@Module)
@Module(
injects = {
BaseApp.class,
MainActivity.class,
},
includes = {
DemoModule.class,
}
)
public class AppModule {
private BaseApp app;
public AppModule(BaseApp app) {
this.app = app;
}
@Provides
@Singleton
public Context provideApplicationContext() {
return app;
}
}
Create a Root Module (@Module)
public class BaseApp extends Application {
private ObjectGraph objectGraph;
@Override
public void onCreate() {
super.onCreate();
injectDependencies();
}
private void injectDependencies() {
objectGraph = ObjectGraph.create(new AppModule(this));
objectGraph.inject(this);
}
public void inject(Object object) {
objectGraph.inject(object);
}
}
Create an Object graph
public class MainActivity extends AppCompatActivity {
@Inject
Log mLog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Add to the object graph.
((BaseApp) getApplication()).inject(this);
}
Inject Dependencies (@Inject)
@Module(
complete = false,
library = true
)
public class DemoModule {
//……
@Provides
@Singleton
@Named(“login”)
public PreferencesEndPoint provideLoginPreferencesEndPoint(final Context context)
{
return new PreferenceEndPointImpl(context, “login”);
}
@Named - annotation
public class MainActivity extends AppCompatActivity {
@Inject
Log mLog;
@Inject
@Named(“login”)
PreferencesEndPoint loginEndPoint;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Add to the object graph.
((BaseApp) getApplication()).inject(this);
//……
}
@Named - annotation
public class MainActivity extends AppCompatActivity {
@Inject
Log mLog;
@Inject
Provider<Log> mLogProvider;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Add to the object graph.
((BaseApp) getApplication()).inject(this);
//……
// Request new object every time requested
Log log = mLogProvider.get();
}
@Inject Provider
Thank You!

Mais conteúdo relacionado

Mais procurados (19)

mediator
mediatormediator
mediator
 
python and database
python and databasepython and database
python and database
 
C++
C++C++
C++
 
Cloudproject
CloudprojectCloudproject
Cloudproject
 
Constructor overloading & method overloading
Constructor overloading & method overloadingConstructor overloading & method overloading
Constructor overloading & method overloading
 
Classes & objects new
Classes & objects newClasses & objects new
Classes & objects new
 
Database programming
Database programmingDatabase programming
Database programming
 
React hooks
React hooksReact hooks
React hooks
 
Active Object
Active ObjectActive Object
Active Object
 
ConsTRUCTION AND DESTRUCTION
ConsTRUCTION AND DESTRUCTIONConsTRUCTION AND DESTRUCTION
ConsTRUCTION AND DESTRUCTION
 
Constructor&amp; destructor
Constructor&amp; destructorConstructor&amp; destructor
Constructor&amp; destructor
 
New Microsoft Word Document.doc
New Microsoft Word Document.docNew Microsoft Word Document.doc
New Microsoft Word Document.doc
 
Servlet session 9
Servlet   session 9Servlet   session 9
Servlet session 9
 
Java DataBase Connectivity - JDBC Part-2
Java DataBase Connectivity - JDBC Part-2Java DataBase Connectivity - JDBC Part-2
Java DataBase Connectivity - JDBC Part-2
 
Ian 2014.10.24 weekly report
Ian 2014.10.24 weekly reportIan 2014.10.24 weekly report
Ian 2014.10.24 weekly report
 
Dynamic databinding
Dynamic databindingDynamic databinding
Dynamic databinding
 
Python my SQL - create table
Python my SQL - create tablePython my SQL - create table
Python my SQL - create table
 
Constructor destructor.ppt
Constructor destructor.pptConstructor destructor.ppt
Constructor destructor.ppt
 
JVM and OOPS Introduction
JVM and OOPS IntroductionJVM and OOPS Introduction
JVM and OOPS Introduction
 

Destaque

Destaque (18)

Raising the efficiency of the open education system
Raising the efficiency of the open education system Raising the efficiency of the open education system
Raising the efficiency of the open education system
 
Panorámicas
PanorámicasPanorámicas
Panorámicas
 
A previdência do servidor público estadual - Ari Lovera
A previdência do servidor público estadual - Ari LoveraA previdência do servidor público estadual - Ari Lovera
A previdência do servidor público estadual - Ari Lovera
 
Fotos
FotosFotos
Fotos
 
Dedinho
DedinhoDedinho
Dedinho
 
Plano de 5ªaula 5ªserie 6º ano gestar 2012 cópia
Plano de 5ªaula 5ªserie 6º ano gestar 2012   cópiaPlano de 5ªaula 5ªserie 6º ano gestar 2012   cópia
Plano de 5ªaula 5ªserie 6º ano gestar 2012 cópia
 
Ester - Bachelor's degree Diploma
Ester - Bachelor's degree DiplomaEster - Bachelor's degree Diploma
Ester - Bachelor's degree Diploma
 
No Estés Triste
No Estés TristeNo Estés Triste
No Estés Triste
 
British and American
British and AmericanBritish and American
British and American
 
Jovens Brasileiros e o Mundo Mobile
Jovens Brasileiros e o Mundo MobileJovens Brasileiros e o Mundo Mobile
Jovens Brasileiros e o Mundo Mobile
 
American Express
American ExpressAmerican Express
American Express
 
Proyecto bloque 2
Proyecto bloque 2Proyecto bloque 2
Proyecto bloque 2
 
027. Superhik Alkohol Prijeti
027. Superhik   Alkohol Prijeti027. Superhik   Alkohol Prijeti
027. Superhik Alkohol Prijeti
 
PEPTIC ULCER
PEPTIC ULCERPEPTIC ULCER
PEPTIC ULCER
 
The Voicemail Script Part 4
The Voicemail Script Part 4The Voicemail Script Part 4
The Voicemail Script Part 4
 
Audience Feedback
Audience FeedbackAudience Feedback
Audience Feedback
 
Working Title Part 6
Working Title Part 6Working Title Part 6
Working Title Part 6
 
Tablas
Tablas Tablas
Tablas
 

Semelhante a Dagger1

Idiomatic gradle plugin writing
Idiomatic gradle plugin writingIdiomatic gradle plugin writing
Idiomatic gradle plugin writingSchalk Cronjé
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingSchalk Cronjé
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingSchalk Cronjé
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingSchalk Cronjé
 
Gradle - small introduction
Gradle - small introductionGradle - small introduction
Gradle - small introductionIgor Popov
 
Chapter 13 introduction to classes
Chapter 13 introduction to classesChapter 13 introduction to classes
Chapter 13 introduction to classesrsnyder3601
 
Sharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SFSharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SFPierre-Yves Ricau
 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsRai University
 
Mca 2nd sem u-2 classes & objects
Mca 2nd  sem u-2 classes & objectsMca 2nd  sem u-2 classes & objects
Mca 2nd sem u-2 classes & objectsRai University
 
Dependency injection using dagger2
Dependency injection using dagger2Dependency injection using dagger2
Dependency injection using dagger2Javad Hashemi
 
Basic Gradle Plugin Writing
Basic Gradle Plugin WritingBasic Gradle Plugin Writing
Basic Gradle Plugin WritingSchalk Cronjé
 
Chapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIChapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIEduardo Bergavera
 
Java căn bản - Chapter7
Java căn bản - Chapter7Java căn bản - Chapter7
Java căn bản - Chapter7Vince Vo
 
object oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoMobject oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoMambikavenkatesh2
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Javakjkleindorfer
 

Semelhante a Dagger1 (20)

Idiomatic gradle plugin writing
Idiomatic gradle plugin writingIdiomatic gradle plugin writing
Idiomatic gradle plugin writing
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin Writing
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin Writing
 
Di code steps
Di code stepsDi code steps
Di code steps
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin Writing
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan ThakurClass and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
 
Gradle - small introduction
Gradle - small introductionGradle - small introduction
Gradle - small introduction
 
Chapter 13 introduction to classes
Chapter 13 introduction to classesChapter 13 introduction to classes
Chapter 13 introduction to classes
 
Sharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SFSharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SF
 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objects
 
Mca 2nd sem u-2 classes & objects
Mca 2nd  sem u-2 classes & objectsMca 2nd  sem u-2 classes & objects
Mca 2nd sem u-2 classes & objects
 
Dependency injection using dagger2
Dependency injection using dagger2Dependency injection using dagger2
Dependency injection using dagger2
 
Basic Gradle Plugin Writing
Basic Gradle Plugin WritingBasic Gradle Plugin Writing
Basic Gradle Plugin Writing
 
OOPs & Inheritance Notes
OOPs & Inheritance NotesOOPs & Inheritance Notes
OOPs & Inheritance Notes
 
Java notes
Java notesJava notes
Java notes
 
Chapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIChapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part II
 
Java căn bản - Chapter7
Java căn bản - Chapter7Java căn bản - Chapter7
Java căn bản - Chapter7
 
object oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoMobject oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoM
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Java
 

Último

Introduction to Quantum Computing
Introduction to Quantum ComputingIntroduction to Quantum Computing
Introduction to Quantum ComputingGDSC PJATK
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
Babel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxBabel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxYounusS2
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.francesco barbera
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxGDSC PJATK
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URLRuncy Oommen
 
Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?SANGHEE SHIN
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
PicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer ServicePicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer ServiceRenan Moreira de Oliveira
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 

Último (20)

Introduction to Quantum Computing
Introduction to Quantum ComputingIntroduction to Quantum Computing
Introduction to Quantum Computing
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
Babel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxBabel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptx
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URL
 
Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
PicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer ServicePicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer Service
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 

Dagger1

  • 1. Dagger Presenter : Ramesh Akula http://about.me/aramesh
  • 2. dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.squareup.dagger:dagger:1.2.+' provided 'com.squareup.dagger:dagger-compiler:1.2.+' } Gradle Dependencies
  • 3. ❖ @Module : Identify this class as a Dagger module. ❖ @Inject : Classes where this module is going to inject any of its dependencies. Specify those classes that are directly injected into object graph. ❖ @Provides: Identify method as an injection provider. The name of the method doesn’t matter, it only relies on what class type is provided. Introduction
  • 4. @Module( complete = false, library = true ) public class DemoModule { //Provide log object @Provides @Singleton public Log provideLog() { return new LogImpl(); } } Create a Module (@Module)
  • 5. @Module( injects = { BaseApp.class, MainActivity.class, }, includes = { DemoModule.class, } ) public class AppModule { private BaseApp app; public AppModule(BaseApp app) { this.app = app; } @Provides @Singleton public Context provideApplicationContext() { return app; } } Create a Root Module (@Module)
  • 6. public class BaseApp extends Application { private ObjectGraph objectGraph; @Override public void onCreate() { super.onCreate(); injectDependencies(); } private void injectDependencies() { objectGraph = ObjectGraph.create(new AppModule(this)); objectGraph.inject(this); } public void inject(Object object) { objectGraph.inject(object); } } Create an Object graph
  • 7. public class MainActivity extends AppCompatActivity { @Inject Log mLog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Add to the object graph. ((BaseApp) getApplication()).inject(this); } Inject Dependencies (@Inject)
  • 8. @Module( complete = false, library = true ) public class DemoModule { //…… @Provides @Singleton @Named(“login”) public PreferencesEndPoint provideLoginPreferencesEndPoint(final Context context) { return new PreferenceEndPointImpl(context, “login”); } @Named - annotation
  • 9. public class MainActivity extends AppCompatActivity { @Inject Log mLog; @Inject @Named(“login”) PreferencesEndPoint loginEndPoint; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Add to the object graph. ((BaseApp) getApplication()).inject(this); //…… } @Named - annotation
  • 10. public class MainActivity extends AppCompatActivity { @Inject Log mLog; @Inject Provider<Log> mLogProvider; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Add to the object graph. ((BaseApp) getApplication()).inject(this); //…… // Request new object every time requested Log log = mLogProvider.get(); } @Inject Provider