SlideShare a Scribd company logo
Dagger 2
Dagger 2
Dagger 2 analyzes dependencies for you and generates code to help wire them
together.
WITHOUT DAGGER 2
Activities
Fragments
Views
Objects
API interface
(Retrofit)
Image Loader
(Picasso)
Shared Preference
Network client
Image disk cache
DAGGER USAGE
Components Object
Find object
@Inject
Take all fields with annotation, look in the component and find the object by type, and set the
field.
DAGGER USAGE
@Inject Picasso Picasso;
@ Inject Preference preference onject
// in oncreate function
getComponent().inject(this)
Take all fields with annotation, look in the component and find the object by type, and set the field.
ANNOTATIONS USED BY DAGGER 2
• @Module and @Provides
• @Inject
• @Components
MODULES & COMPONENTS
Activities
Fragments
Views
Objects
Network client
Shared Preferences
Application
Network module
Storage module
Application module
Application
component
.inject()
SCOPES
• @UserScope
• @Singleton
• @ActivityScope
CONSTRUCTOR INJECTION
@Provides
public StoreUserInfo provideStorUserInfo(NetworkApi
networkApi){
return new StoreUserInfo(networkApi);
}
public class MainActivity extends AppCompatActivity {
@Inject
StoreUserInfo storeUserInfo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
((MyApplication) getApplication()).getComponent()
.inject(this);
}

More Related Content

PPTX
Dagger 2
PDF
Getting started with dagger 2
PDF
Moderne App-Architektur mit Dagger2 und RxJava
PDF
Android talks #08 dagger2
PDF
DI with Dagger2
PDF
Dagger2 Intro
PDF
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
PDF
Dagger 2 - Ciklum Speakers' Corner
Dagger 2
Getting started with dagger 2
Moderne App-Architektur mit Dagger2 und RxJava
Android talks #08 dagger2
DI with Dagger2
Dagger2 Intro
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
Dagger 2 - Ciklum Speakers' Corner

What's hot (20)

PDF
基於 Flow & Path 的 MVP 架構
PPTX
Reason to choose Angular JS for your Web Application
PDF
Android Develpment vol. 2, MFF UK, 2015
PDF
Writing testable Android apps
PDF
Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...
PPTX
Di with dagger2 in android
PDF
Android Modularization
PPTX
Angular%201%20to%20angular%202
PDF
React Nativeの光と闇
PDF
Angular 2... so can I use it now??
PDF
Cara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
PPTX
Android studio&Gradle&Autotest
PPTX
Dependency injection: koin vs dagger
PPTX
PDF
Angular2 - getting-ready
PDF
Adventures with Angular 2
PDF
Building blocks of Angular
PDF
Putting the Native in React Native - React Native Boston
PDF
Android application architecture
PPTX
Angular
基於 Flow & Path 的 MVP 架構
Reason to choose Angular JS for your Web Application
Android Develpment vol. 2, MFF UK, 2015
Writing testable Android apps
Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...
Di with dagger2 in android
Android Modularization
Angular%201%20to%20angular%202
React Nativeの光と闇
Angular 2... so can I use it now??
Cara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
Android studio&Gradle&Autotest
Dependency injection: koin vs dagger
Angular2 - getting-ready
Adventures with Angular 2
Building blocks of Angular
Putting the Native in React Native - React Native Boston
Android application architecture
Angular
Ad

Similar to Dagger 2 ppt (20)

PDF
Dependency injection and dagger2 in android paramvir singh
PPTX
Android architecture
PPTX
Sword fighting with Dagger GDG-NYC Jan 2016
PDF
Sharper Better Faster Dagger ‡ - Droidcon SF
PPTX
Modern android development
PPTX
Use Eclipse technologies to build a modern embedded IDE
PDF
Angular 2: core concepts
PPT
ARTag
PDF
Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023
PPTX
Contexts and Dependency Injection
PPT
Steelcon 2015 Reverse-Engineering Obfuscated Android Applications
PDF
Build UI of the Future with React 360
PDF
React Native for multi-platform mobile applications
PDF
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
PDF
Spring Cloud Function & Project riff #jsug
PDF
Using Dagger in a Clean Architecture project
PDF
From MEAN to the MERN Stack
PDF
PPTX
Extending unity3D Editor
PPTX
Dependency injection using dagger2
Dependency injection and dagger2 in android paramvir singh
Android architecture
Sword fighting with Dagger GDG-NYC Jan 2016
Sharper Better Faster Dagger ‡ - Droidcon SF
Modern android development
Use Eclipse technologies to build a modern embedded IDE
Angular 2: core concepts
ARTag
Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023
Contexts and Dependency Injection
Steelcon 2015 Reverse-Engineering Obfuscated Android Applications
Build UI of the Future with React 360
React Native for multi-platform mobile applications
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
Spring Cloud Function & Project riff #jsug
Using Dagger in a Clean Architecture project
From MEAN to the MERN Stack
Extending unity3D Editor
Dependency injection using dagger2
Ad

Recently uploaded (6)

PPTX
ASMS Telecommunication company Profile
DOC
证书学历UoA毕业证,澳大利亚中汇学院毕业证国外大学毕业证
PDF
Lesson 13- HEREDITY _ pedSAWEREGFVCXZDSASEWFigree.pdf
PPTX
Introduction to Packet Tracer Course Overview - Aug 21 (1).pptx
PDF
6-UseCfgfhgfhgfhgfhgfhfhhaseActivity.pdf
DOC
Camb毕业证学历认证,格罗斯泰斯特主教大学毕业证仿冒文凭毕业证
ASMS Telecommunication company Profile
证书学历UoA毕业证,澳大利亚中汇学院毕业证国外大学毕业证
Lesson 13- HEREDITY _ pedSAWEREGFVCXZDSASEWFigree.pdf
Introduction to Packet Tracer Course Overview - Aug 21 (1).pptx
6-UseCfgfhgfhgfhgfhgfhfhhaseActivity.pdf
Camb毕业证学历认证,格罗斯泰斯特主教大学毕业证仿冒文凭毕业证

Dagger 2 ppt