ºÝºÝߣ

ºÝºÝߣShare 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);
}
Ad

Recommended

Dagger 2
Dagger 2
William Wang
?
Getting started with dagger 2
Getting started with dagger 2
Rodrigo Henriques
?
Moderne App-Architektur mit Dagger2 und RxJava
Moderne App-Architektur mit Dagger2 und RxJava
inovex GmbH
?
Android talks #08 dagger2
Android talks #08 dagger2
Infinum
?
DI with Dagger2
DI with Dagger2
Eugen Martynov
?
Dagger2 Intro
Dagger2 Intro
Young-Hyuk Yoo
?
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?t
Infinum
?
Dagger 2 - Ciklum Speakers' Corner
Dagger 2 - Ciklum Speakers' Corner
Constantine Mars
?
»ùì¶ Flow & Path µÄ MVP ¼Ü˜‹
»ùì¶ Flow & Path µÄ MVP ¼Ü˜‹
ÐþÎä Wu
?
Reason to choose Angular JS for your Web Application
Reason to choose Angular JS for your Web Application
Priyanka Verma
?
Android Develpment vol. 2, MFF UK, 2015
Android Develpment vol. 2, MFF UK, 2015
Tom¨¢? Kypta
?
Writing testable Android apps
Writing testable Android apps
Tom¨¢? Kypta
?
Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...
Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...
DicodingEvent
?
Di with dagger2 in android
Di with dagger2 in android
Brian Kiptoo
?
Android Modularization
Android Modularization
Young-Hyuk Yoo
?
Angular%201%20to%20angular%202
Angular%201%20to%20angular%202
Ran Wahle
?
React Native¤Î¹â¤Èéœ
React Native¤Î¹â¤Èéœ
Yukiya Nakagawa
?
Angular 2... so can I use it now??
Angular 2... so can I use it now??
Laurent Duveau
?
Cara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
Cara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
DicodingEvent
?
Android studio&Gradle&Autotest
Android studio&Gradle&Autotest
Òã ·½
?
Dependency injection: koin vs dagger
Dependency injection: koin vs dagger
Matteo Pasotti
?
Angular 2
Angular 2
Travis van der Font
?
Angular2 - getting-ready
Angular2 - getting-ready
Nir Kaufman
?
Adventures with Angular 2
Adventures with Angular 2
Dragos Ionita
?
Building blocks of Angular
Building blocks of Angular
Knoldus Inc.
?
Putting the Native in React Native - React Native Boston
Putting the Native in React Native - React Native Boston
stan229
?
Android application architecture
Android application architecture
Romain Rochegude
?
Angular
Angular
sridhiya
?
Dependency injection and dagger2 in android paramvir singh
Dependency injection and dagger2 in android paramvir singh
Paramvir Singh
?
Android Dagger 2
Android Dagger 2
Sanket Shah
?

More Related Content

What's hot (20)

»ùì¶ Flow & Path µÄ MVP ¼Ü˜‹
»ùì¶ Flow & Path µÄ MVP ¼Ü˜‹
ÐþÎä Wu
?
Reason to choose Angular JS for your Web Application
Reason to choose Angular JS for your Web Application
Priyanka Verma
?
Android Develpment vol. 2, MFF UK, 2015
Android Develpment vol. 2, MFF UK, 2015
Tom¨¢? Kypta
?
Writing testable Android apps
Writing testable Android apps
Tom¨¢? Kypta
?
Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...
Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...
DicodingEvent
?
Di with dagger2 in android
Di with dagger2 in android
Brian Kiptoo
?
Android Modularization
Android Modularization
Young-Hyuk Yoo
?
Angular%201%20to%20angular%202
Angular%201%20to%20angular%202
Ran Wahle
?
React Native¤Î¹â¤Èéœ
React Native¤Î¹â¤Èéœ
Yukiya Nakagawa
?
Angular 2... so can I use it now??
Angular 2... so can I use it now??
Laurent Duveau
?
Cara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
Cara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
DicodingEvent
?
Android studio&Gradle&Autotest
Android studio&Gradle&Autotest
Òã ·½
?
Dependency injection: koin vs dagger
Dependency injection: koin vs dagger
Matteo Pasotti
?
Angular 2
Angular 2
Travis van der Font
?
Angular2 - getting-ready
Angular2 - getting-ready
Nir Kaufman
?
Adventures with Angular 2
Adventures with Angular 2
Dragos Ionita
?
Building blocks of Angular
Building blocks of Angular
Knoldus Inc.
?
Putting the Native in React Native - React Native Boston
Putting the Native in React Native - React Native Boston
stan229
?
Android application architecture
Android application architecture
Romain Rochegude
?
Angular
Angular
sridhiya
?
»ùì¶ Flow & Path µÄ MVP ¼Ü˜‹
»ùì¶ Flow & Path µÄ MVP ¼Ü˜‹
ÐþÎä Wu
?
Reason to choose Angular JS for your Web Application
Reason to choose Angular JS for your Web Application
Priyanka Verma
?
Android Develpment vol. 2, MFF UK, 2015
Android Develpment vol. 2, MFF UK, 2015
Tom¨¢? Kypta
?
Writing testable Android apps
Writing testable Android apps
Tom¨¢? Kypta
?
Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...
Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...
DicodingEvent
?
Di with dagger2 in android
Di with dagger2 in android
Brian Kiptoo
?
Angular%201%20to%20angular%202
Angular%201%20to%20angular%202
Ran Wahle
?
React Native¤Î¹â¤Èéœ
React Native¤Î¹â¤Èéœ
Yukiya Nakagawa
?
Angular 2... so can I use it now??
Angular 2... so can I use it now??
Laurent Duveau
?
Cara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
Cara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
DicodingEvent
?
Android studio&Gradle&Autotest
Android studio&Gradle&Autotest
Òã ·½
?
Dependency injection: koin vs dagger
Dependency injection: koin vs dagger
Matteo Pasotti
?
Angular2 - getting-ready
Angular2 - getting-ready
Nir Kaufman
?
Adventures with Angular 2
Adventures with Angular 2
Dragos Ionita
?
Building blocks of Angular
Building blocks of Angular
Knoldus Inc.
?
Putting the Native in React Native - React Native Boston
Putting the Native in React Native - React Native Boston
stan229
?
Android application architecture
Android application architecture
Romain Rochegude
?

Similar to Dagger 2 ppt (19)

Dependency injection and dagger2 in android paramvir singh
Dependency injection and dagger2 in android paramvir singh
Paramvir Singh
?
Android Dagger 2
Android Dagger 2
Sanket Shah
?
Android Dagger2
Android Dagger2
Monir Zzaman
?
Android architecture
Android architecture
Trong-An Bui
?
The Power of Dependency Injection with Dagger 2 and Kotlin
The Power of Dependency Injection with Dagger 2 and Kotlin
Knoldus Inc.
?
Advanced Dagger talk from 360andev
Advanced Dagger talk from 360andev
Mike Nakhimovich
?
Dependency injection using dagger 2
Dependency injection using dagger 2
Mahmoud El-Naggar
?
Sword fighting with Dagger GDG-NYC Jan 2016
Sword fighting with Dagger GDG-NYC Jan 2016
Mike Nakhimovich
?
Introduction to Dagger 2 by Ratanak
Introduction to Dagger 2 by Ratanak
ratanak pek
?
Di code steps
Di code steps
Brian Kiptoo
?
Dependency injection with dagger 2
Dependency injection with dagger 2
Nischal0101
?
Dependency injection using dagger2
Dependency injection using dagger2
Javad Hashemi
?
Dagger for android
Dagger for android
Kan-Han (John) Lu
?
How To Dependency Inject a Kitten: An Introduction to Dagger 2
How To Dependency Inject a Kitten: An Introduction to Dagger 2
Todd Burgess
?
Introduction to Depedency Injection in Android
Introduction to Depedency Injection in Android
Yoza Aprilio
?
DI using dagger
DI using dagger
Jayant Sethi
?
Di & dagger
Di & dagger
Vitali Pekelis
?
Daggerate your code - Write your own annotation processor
Daggerate your code - Write your own annotation processor
Bartosz Kosarzycki
?
Dagger1
Dagger1
Ramesh Akula
?
Dependency injection and dagger2 in android paramvir singh
Dependency injection and dagger2 in android paramvir singh
Paramvir Singh
?
Android architecture
Android architecture
Trong-An Bui
?
The Power of Dependency Injection with Dagger 2 and Kotlin
The Power of Dependency Injection with Dagger 2 and Kotlin
Knoldus Inc.
?
Advanced Dagger talk from 360andev
Advanced Dagger talk from 360andev
Mike Nakhimovich
?
Dependency injection using dagger 2
Dependency injection using dagger 2
Mahmoud El-Naggar
?
Sword fighting with Dagger GDG-NYC Jan 2016
Sword fighting with Dagger GDG-NYC Jan 2016
Mike Nakhimovich
?
Introduction to Dagger 2 by Ratanak
Introduction to Dagger 2 by Ratanak
ratanak pek
?
Dependency injection with dagger 2
Dependency injection with dagger 2
Nischal0101
?
Dependency injection using dagger2
Dependency injection using dagger2
Javad Hashemi
?
How To Dependency Inject a Kitten: An Introduction to Dagger 2
How To Dependency Inject a Kitten: An Introduction to Dagger 2
Todd Burgess
?
Introduction to Depedency Injection in Android
Introduction to Depedency Injection in Android
Yoza Aprilio
?
Daggerate your code - Write your own annotation processor
Daggerate your code - Write your own annotation processor
Bartosz Kosarzycki
?
Ad

Dagger 2 ppt