SlideShare a Scribd company logo
Getting Started with
Dagger 2
Fast dependency injection for Android applications
Why dependency injection?
Separation of concerns
Testability
Every app has some
kind of dependency
injection
Uncle Bob
“Depend upon Abstractions. Do
not depend upon concretions.”
A brief history of time
JSR-330
Guice
Dagger
Getting started with dagger 2
Dagger 2
Maintained by Java Core Libraries team
at Google
Faster than Guice and Dagger
Easy to use and to debug
Mobile first
Getting started with dagger 2
Dagger API
@Modules + @Provides
@Inject
@Component
Providing Dependencies
Requesting Dependencies
@Inject annotations required
Constructor, Field & Method
Constructor Injection
@Inject on a single constructor
Parameters are dependencies
They can be stored in private and
final fields
Constructor Injection
Constructor Injection
It’s useless now
Constructor Injection
Dependency Graph
EpisodeRepository DataModule#provideEpisodeRepository
RemoteEpisodeRepository
TraktvApi DataModule#provideTraktvApi
OmdbApi DataModule#provideOmdbApi
Constructor Injection
Field Injection
@Inject on fields for dependencies
Field can not be private or final
Inject happens after object is fully
instantiated
Object is usually responsible for injection
Method Injection
Getting started with dagger 2
http://google.github.io/dagger/
Components
Bridge between modules and
injections
The injector
Components
Components
this notation is optional
Components
Components
How about some live
coding?
github.com/google/dagger
Questions?
Questions?
github.com/rodrigohenriques
Getting started with dagger 2

More Related Content

What's hot (20)

PPTX
Android Dagger2
Monir Zzaman
 
PPTX
Android Dagger 2
Sanket Shah
 
PDF
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
Infinum
 
PDF
Dagger 2 - Ciklum Speakers' Corner
Constantine Mars
 
PPTX
Di with dagger2 in android
Brian Kiptoo
 
PPTX
Dependency injection using dagger2
Javad Hashemi
 
PDF
Android Modularization
Young-Hyuk Yoo
 
PDF
Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...
DicodingEvent
 
PPTX
An Introduction to Dependency Inversion Principle
Dunith Dhanushka
 
PPTX
Dagger2
Anjan Debnath
 
PDF
Fastlane on Android 介紹
Kros Huang
 
PPTX
Dependency Inversion Principle
Marco Mangia Musardo
 
PDF
Creating modern java web applications based on struts2 and angularjs
Johannes Geppert
 
PDF
Memulai Karir menjadi iOS Developer - Gilang ramadhan (Academy Content Writer...
DicodingEvent
 
PDF
Angular 2... so can I use it now??
Laurent Duveau
 
PPTX
Dependency Inversion Principle
Shahriar Hyder
 
PDF
React Nativeの光と闇
Yukiya Nakagawa
 
PDF
Adventures with Angular 2
Dragos Ionita
 
PPTX
Angular 2
Travis van der Font
 
PDF
Angular2 - getting-ready
Nir Kaufman
 
Android Dagger2
Monir Zzaman
 
Android Dagger 2
Sanket Shah
 
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
Infinum
 
Dagger 2 - Ciklum Speakers' Corner
Constantine Mars
 
Di with dagger2 in android
Brian Kiptoo
 
Dependency injection using dagger2
Javad Hashemi
 
Android Modularization
Young-Hyuk Yoo
 
Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...
DicodingEvent
 
An Introduction to Dependency Inversion Principle
Dunith Dhanushka
 
Dagger2
Anjan Debnath
 
Fastlane on Android 介紹
Kros Huang
 
Dependency Inversion Principle
Marco Mangia Musardo
 
Creating modern java web applications based on struts2 and angularjs
Johannes Geppert
 
Memulai Karir menjadi iOS Developer - Gilang ramadhan (Academy Content Writer...
DicodingEvent
 
Angular 2... so can I use it now??
Laurent Duveau
 
Dependency Inversion Principle
Shahriar Hyder
 
React Nativeの光と闇
Yukiya Nakagawa
 
Adventures with Angular 2
Dragos Ionita
 
Angular2 - getting-ready
Nir Kaufman
 

Similar to Getting started with dagger 2 (20)

PPTX
The Power of Dependency Injection with Dagger 2 and Kotlin
Knoldus Inc.
 
PDF
Dagger for android
Kan-Han (John) Lu
 
PDF
Writing testable Android apps
Tomáš Kypta
 
PPTX
Introduction to Dagger 2 by Ratanak
ratanak pek
 
PPTX
[Android] DI in multimodule application
Oleg Mazhukin
 
PPTX
Introduction to dependency injection in Scala (Play)
Knoldus Inc.
 
PDF
An Implementation Tour to AngularJS
rahulmonikasharma
 
PPTX
C# Dependency Injection Tutorial | C# Dependency Injection Example | C# Tutor...
Simplilearn
 
PDF
Angular2 with type script
Ravi Mone
 
PDF
Ідіоматична ін'єкція залежностей на Kotlin без фреймворків - UA Mobile2019
UA Mobile
 
PPTX
How To Dependency Inject a Kitten: An Introduction to Dagger 2
Todd Burgess
 
PDF
Dependency injection and dagger2 in android paramvir singh
Paramvir Singh
 
PPTX
Android architecture
Trong-An Bui
 
PPTX
Introduction to Spring Framework
ASG
 
PDF
Rapid Prototyping with TurboGears2
Alessandro Molina
 
PDF
The 2014 Decision Makers Guide to Java Web Frameworks
Kunal Ashar
 
PDF
Angular 2: core concepts
Codemotion
 
PDF
IRJET- DocLock Application for Secure Document Sharing
IRJET Journal
 
PPTX
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Theo Jungeblut
 
PPTX
Angular2 + Ng-Lightning + Lightning Design System = Great Apps
Emily Hurn
 
The Power of Dependency Injection with Dagger 2 and Kotlin
Knoldus Inc.
 
Dagger for android
Kan-Han (John) Lu
 
Writing testable Android apps
Tomáš Kypta
 
Introduction to Dagger 2 by Ratanak
ratanak pek
 
[Android] DI in multimodule application
Oleg Mazhukin
 
Introduction to dependency injection in Scala (Play)
Knoldus Inc.
 
An Implementation Tour to AngularJS
rahulmonikasharma
 
C# Dependency Injection Tutorial | C# Dependency Injection Example | C# Tutor...
Simplilearn
 
Angular2 with type script
Ravi Mone
 
Ідіоматична ін'єкція залежностей на Kotlin без фреймворків - UA Mobile2019
UA Mobile
 
How To Dependency Inject a Kitten: An Introduction to Dagger 2
Todd Burgess
 
Dependency injection and dagger2 in android paramvir singh
Paramvir Singh
 
Android architecture
Trong-An Bui
 
Introduction to Spring Framework
ASG
 
Rapid Prototyping with TurboGears2
Alessandro Molina
 
The 2014 Decision Makers Guide to Java Web Frameworks
Kunal Ashar
 
Angular 2: core concepts
Codemotion
 
IRJET- DocLock Application for Secure Document Sharing
IRJET Journal
 
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Theo Jungeblut
 
Angular2 + Ng-Lightning + Lightning Design System = Great Apps
Emily Hurn
 
Ad

Getting started with dagger 2