View
469
Download
0
Category
Preview:
Citation preview
Why dependency injection?
Separation of concerns
Testability
Every app has some kind of dependency injection
Dagger 2
Maintained by Java Core Libraries team at Google
Faster than Guice and Dagger
Easy to use and to debug
Mobile first
Constructor Injection
@Inject on a single constructor
Parameters are dependencies
They can be stored in private and final fields
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
Recommended