dev-resources.site
for different kinds of informations.
Practical guide to Dagger 2
The post was published at my blog. If you don't have any idea about dependency injection or dagger, head over to the article link above.
Keep reading if you have an idea about dagger annotations like @Inject, @Module, @Provides and @Component. These rules are for simple use-cases of dependency injection.
Rule-set:
Use @Inject on constructors wherever you can (To declare dependencies).
Make modules for stuff you canโt instantiate directly (e.g. Retrofit client as itโs built by itโs builder) or for stuff you canโt create like Context.
Also make โprovidesโ method in modules if you want to inject interfaces instead of implementations.
Use @Singleton if you want the dependencies to remain a Singleton.
Include all the required modules in the component and define where that component will inject dependencies to.
Use @Inject to ask dagger to inject dependencies you have declared.
Featured ones: