SlideShare a Scribd company logo
DAGGER SO SHARP!
DEPENDENCY INJECTION IN ANDROID
TOPICS
 What is Dependency Injection
 What is Dagger
 Pros and Cons of Dagger
 Dagger alternatives
 Sample Implementation
 QA session
WHAT IS DEPENDENCY INJECTION?
 Dependency Injection (DI) is a design pattern used to implement Inversion of Control(IoC). It allows the
creation of dependent objects outside of a class and provides those objects to a class through different
ways. Using DI, we move the creation and binding of the dependent objects outside of the class that
depends on them.
 It's a design pattern(No need for a library to implement)
 We all use some form of DI
Car Engine
Dependency
Depends
DEPENDENCY INJECTION PATTERN
CLIENT
INJECTOR
SERVICE
Uses
HARD COUPLED
EXAMPLE
 BadCar is tightly coupled to
the fate of Engine and
Wheels
BENEFITS OF DI
LOOSE COUPLING EASY TO TEST CODE REUSABILITY
TYPES OF DI
Constructor
injection
Field
injection
Method
injection
Di with dagger2 in android
POPULAR
LIBRARIES
 Dagger2
 Koin
 Kodein
 Roboguice
 Butterknife
 Android annotation
 Toothpick
WEAPONS,
MONEY AND
DRUGS
A SIDE BY SIDE
COMPARISON OF
DAGGER2, KOIN
AND KODEIN
COMPARISON BETWEEN DAGGER2, KOIN & KODEIN
Dagger 2 Koin Kodein
Written in Java Written in kotlin Written in Kotlin(Java support)
Generates code in build does not generate code(less
build time)
No code generation
Has proxy classes No proxy classes No proxy classes
Uses annotations No annotation No annotation
A lot of boilerplate Less boilerplate
DAGGER2
Car
Engine
Plugs Starter
Wheels
Tires Nuts
Driver
DAGGER2
 Uses Directed Acyclic Graph = DAGger
 There are no cyclic dependencies
 @Module and @Provides: define classes and methods which provide dependencies
 @Inject: request dependencies. Can be used on a constructor, a field, or a method
 @Component: enable selected modules and used for performing dependency injection
LET'S ROLL UP
OUR SLEEVES
AND WRITE
SOME CODE!
BENEFITS OF DAGGER2
 Provides compile-time verification of the whole dependency graph so app doesn't crash at runtime
 Very clear error messages
 Designed for low-end devices
CONS OF DAGGER2
 Too verbose
 Steep learning curve
INTERACTIVE QA
SESSION
ASK AWAY
THANK YOU THE END. THAT'S IT.
REFERENCES &
FURTHER
READING
 https://codinginflow.com/tutorials/android/dagger-2/part-1-introduction
 https://www.tutorialsteacher.com/ioc/dependency-injection
 https://android.jlelse.eu/fundamentals-of-dependency-injection-and-
popular-libraries-in-android-c17cf48b5253
 https://medium.com/@egek92/koin-di-comparison-of-android-dependency-
injection-frameworks-236a6909bc3e
 https://dagger.dev/users-guide
 https://medium.com/@charbgr/bye-bye-dagger-1494118dcd41
 https://www.journaldev.com/20654/android-mvp-dagger2-retrofit-rxjava
 https://android.jlelse.eu/7-steps-to-implement-dagger-2-in-android-
dabc16715a3a
 https://www.vogella.com/tutorials/Dagger/article.html
 https://blog.mindorks.com/introduction-to-dagger-2-using-dependency-
injection-in-android-part-2-b55857911bcd
 https://medium.com/@harivigneshjayapalan/dagger-2-for-android-
beginners-introduction-be6580cb3edb
 https://www.youtube.com/watch?v=ZZ_qek0hGkM
 https://medium.com/dvt-engineering/android-dagger-2-isnt-hard-
97671ac15b07
DAGGERING
NEVER STOP
I HAD TO ADD THIS

More Related Content

PDF
Getting started with dagger 2
Rodrigo Henriques
 
PDF
Moderne App-Architektur mit Dagger2 und RxJava
inovex GmbH
 
PPTX
Dagger 2
William Wang
 
PPTX
Dagger 2 ppt
Swati Srivastava
 
PDF
React native bridge for iOS and android
Katy Slemon
 
PDF
Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...
DicodingEvent
 
PDF
Android talks #08 dagger2
Infinum
 
PDF
00 android開發課程大綱
BITs Information Technology Consultants Co., Ltd.
 
Getting started with dagger 2
Rodrigo Henriques
 
Moderne App-Architektur mit Dagger2 und RxJava
inovex GmbH
 
Dagger 2
William Wang
 
Dagger 2 ppt
Swati Srivastava
 
React native bridge for iOS and android
Katy Slemon
 
Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...
DicodingEvent
 
Android talks #08 dagger2
Infinum
 

What's hot (20)

PDF
ChromeとAndroidの過去・現在・未来
Shinobu Okano
 
PDF
Android testing part i
Kan-Han (John) Lu
 
PDF
C# Cookware - presented at CukeUp! 2014
Manuel Pais
 
PPTX
Let's Explore C# 6
Jaliya Udagedara
 
PPTX
Debugging C# Applications
Jaliya Udagedara
 
PDF
Phonegap presentation
Atilla Özgür
 
PDF
Common Java problems when developing with Android
Stephen Gilmore
 
PDF
12092019 JavaZone "The Battle of the IDEs"
Ko Turk
 
PDF
Getting Started with IntelliJ IDEA as an Eclipse User
ZeroTurnaround
 
PDF
Moved to https://slidr.io/azzazzel/what-s-not-new-in-modular-java
Milen Dyankov
 
PDF
Flutter vs react native head to toe comparison [2021 edition]
Katy Slemon
 
PDF
Ja coco ignite
Aleksandr Zhuikov
 
PDF
Fight your technical debt with Jenkins, Jacoco and Sonar
Mickael Istria
 
PDF
Current Testing Challenges Ireland
David O'Dowd
 
PPTX
Android Study Jam - Info Session
AITIKDANDAPAT
 
PDF
Moved to https://slidr.io/azzazzel/osgi-fundamentals
Milen Dyankov
 
PDF
Android reverse engineering: understanding third-party applications. OWASP EU...
Internet Security Auditors
 
PDF
Lecture 19
Debasish Pratihari
 
PDF
Mobile development with React Native — one year in production
Avivi Academy
 
PDF
Getting started with react basics
Knoldus Inc.
 
ChromeとAndroidの過去・現在・未来
Shinobu Okano
 
Android testing part i
Kan-Han (John) Lu
 
C# Cookware - presented at CukeUp! 2014
Manuel Pais
 
Let's Explore C# 6
Jaliya Udagedara
 
Debugging C# Applications
Jaliya Udagedara
 
Phonegap presentation
Atilla Özgür
 
Common Java problems when developing with Android
Stephen Gilmore
 
12092019 JavaZone "The Battle of the IDEs"
Ko Turk
 
Getting Started with IntelliJ IDEA as an Eclipse User
ZeroTurnaround
 
Moved to https://slidr.io/azzazzel/what-s-not-new-in-modular-java
Milen Dyankov
 
Flutter vs react native head to toe comparison [2021 edition]
Katy Slemon
 
Ja coco ignite
Aleksandr Zhuikov
 
Fight your technical debt with Jenkins, Jacoco and Sonar
Mickael Istria
 
Current Testing Challenges Ireland
David O'Dowd
 
Android Study Jam - Info Session
AITIKDANDAPAT
 
Moved to https://slidr.io/azzazzel/osgi-fundamentals
Milen Dyankov
 
Android reverse engineering: understanding third-party applications. OWASP EU...
Internet Security Auditors
 
Lecture 19
Debasish Pratihari
 
Mobile development with React Native — one year in production
Avivi Academy
 
Getting started with react basics
Knoldus Inc.
 
Ad

Similar to Di with dagger2 in android (20)

PDF
Dagger2 Intro
Young-Hyuk Yoo
 
PPTX
Android Dagger2
Monir Zzaman
 
PPTX
The Power of Dependency Injection with Dagger 2 and Kotlin
Knoldus Inc.
 
PDF
Dependency injection and dagger2 in android paramvir singh
Paramvir Singh
 
PPTX
Android Dagger 2
Sanket Shah
 
PPTX
Dependency injection using dagger 2
Mahmoud El-Naggar
 
PDF
Dagger 2 - Ciklum Speakers' Corner
Constantine Mars
 
PDF
DI using dagger
Jayant Sethi
 
PDF
DI with Dagger2
Eugen Martynov
 
PDF
Dependency injection with dagger 2
Nischal0101
 
PDF
Di code steps
Brian Kiptoo
 
PPTX
Introduction to Depedency Injection in Android
Yoza Aprilio
 
PPTX
Introduction to Dagger 2 by Ratanak
ratanak pek
 
PDF
Dependency Injection on Android
Joan Puig Sanz
 
PPTX
Android architecture
Trong-An Bui
 
PDF
Dagger for android
Kan-Han (John) Lu
 
PPTX
Dependency injection using dagger2
Javad Hashemi
 
PDF
Dependency injection on Android
Pedro Vicente Gómez Sánchez
 
PPTX
Dependency Injection in Android with Dagger 2
Cumulations Technologies
 
PPTX
How To Dependency Inject a Kitten: An Introduction to Dagger 2
Todd Burgess
 
Dagger2 Intro
Young-Hyuk Yoo
 
Android Dagger2
Monir Zzaman
 
The Power of Dependency Injection with Dagger 2 and Kotlin
Knoldus Inc.
 
Dependency injection and dagger2 in android paramvir singh
Paramvir Singh
 
Android Dagger 2
Sanket Shah
 
Dependency injection using dagger 2
Mahmoud El-Naggar
 
Dagger 2 - Ciklum Speakers' Corner
Constantine Mars
 
DI using dagger
Jayant Sethi
 
DI with Dagger2
Eugen Martynov
 
Dependency injection with dagger 2
Nischal0101
 
Di code steps
Brian Kiptoo
 
Introduction to Depedency Injection in Android
Yoza Aprilio
 
Introduction to Dagger 2 by Ratanak
ratanak pek
 
Dependency Injection on Android
Joan Puig Sanz
 
Android architecture
Trong-An Bui
 
Dagger for android
Kan-Han (John) Lu
 
Dependency injection using dagger2
Javad Hashemi
 
Dependency injection on Android
Pedro Vicente Gómez Sánchez
 
Dependency Injection in Android with Dagger 2
Cumulations Technologies
 
How To Dependency Inject a Kitten: An Introduction to Dagger 2
Todd Burgess
 
Ad

Di with dagger2 in android

  • 1. DAGGER SO SHARP! DEPENDENCY INJECTION IN ANDROID
  • 2. TOPICS  What is Dependency Injection  What is Dagger  Pros and Cons of Dagger  Dagger alternatives  Sample Implementation  QA session
  • 3. WHAT IS DEPENDENCY INJECTION?  Dependency Injection (DI) is a design pattern used to implement Inversion of Control(IoC). It allows the creation of dependent objects outside of a class and provides those objects to a class through different ways. Using DI, we move the creation and binding of the dependent objects outside of the class that depends on them.  It's a design pattern(No need for a library to implement)  We all use some form of DI Car Engine Dependency Depends
  • 5. HARD COUPLED EXAMPLE  BadCar is tightly coupled to the fate of Engine and Wheels
  • 6. BENEFITS OF DI LOOSE COUPLING EASY TO TEST CODE REUSABILITY
  • 9. POPULAR LIBRARIES  Dagger2  Koin  Kodein  Roboguice  Butterknife  Android annotation  Toothpick
  • 10. WEAPONS, MONEY AND DRUGS A SIDE BY SIDE COMPARISON OF DAGGER2, KOIN AND KODEIN
  • 11. COMPARISON BETWEEN DAGGER2, KOIN & KODEIN Dagger 2 Koin Kodein Written in Java Written in kotlin Written in Kotlin(Java support) Generates code in build does not generate code(less build time) No code generation Has proxy classes No proxy classes No proxy classes Uses annotations No annotation No annotation A lot of boilerplate Less boilerplate
  • 13. DAGGER2  Uses Directed Acyclic Graph = DAGger  There are no cyclic dependencies  @Module and @Provides: define classes and methods which provide dependencies  @Inject: request dependencies. Can be used on a constructor, a field, or a method  @Component: enable selected modules and used for performing dependency injection
  • 14. LET'S ROLL UP OUR SLEEVES AND WRITE SOME CODE!
  • 15. BENEFITS OF DAGGER2  Provides compile-time verification of the whole dependency graph so app doesn't crash at runtime  Very clear error messages  Designed for low-end devices
  • 16. CONS OF DAGGER2  Too verbose  Steep learning curve
  • 18. THANK YOU THE END. THAT'S IT.
  • 19. REFERENCES & FURTHER READING  https://codinginflow.com/tutorials/android/dagger-2/part-1-introduction  https://www.tutorialsteacher.com/ioc/dependency-injection  https://android.jlelse.eu/fundamentals-of-dependency-injection-and- popular-libraries-in-android-c17cf48b5253  https://medium.com/@egek92/koin-di-comparison-of-android-dependency- injection-frameworks-236a6909bc3e  https://dagger.dev/users-guide  https://medium.com/@charbgr/bye-bye-dagger-1494118dcd41  https://www.journaldev.com/20654/android-mvp-dagger2-retrofit-rxjava  https://android.jlelse.eu/7-steps-to-implement-dagger-2-in-android- dabc16715a3a  https://www.vogella.com/tutorials/Dagger/article.html  https://blog.mindorks.com/introduction-to-dagger-2-using-dependency- injection-in-android-part-2-b55857911bcd  https://medium.com/@harivigneshjayapalan/dagger-2-for-android- beginners-introduction-be6580cb3edb  https://www.youtube.com/watch?v=ZZ_qek0hGkM  https://medium.com/dvt-engineering/android-dagger-2-isnt-hard- 97671ac15b07