Dagger: injection into android library modules made easy
Garima’s recent post on Defeating the Dahaka made me realize that a lot of new things have been incorporated lately in Dagger. There are now ‘tons’ of new mysterious annotations to get baffled with, but if you understand a few of them, they are gonna make life easy for all you droids.
One of the problems I was facing was to have dagger injections in a library module. The application component had to had abstract`inject(LibraryActivity activity)` methods and also the activities and fragments had to somehow get hold of application component to inject. This was causing a two way coupling between the two. With the release of Android support in Dagger 2.10 onwards, this problem has been solved.
Here is a simple example of how it can work.
Some resources to learn more about new features of Dagger 2
- Google sample todo-mvp-dagger
- Dagger Android Injector by Mert
- Defeat the Dahaka series by Garima
Never stop exploring