Library Dagger 2 Dependency Injection in Applications
suggest changeVersions
This topic was documented against Android 3.0 through 7.1.
Introduction
Dagger 2, as explained on GitHub, is a compile-time evolution approach to dependency injection. Taking the approach started in Dagger 1.x to its ultimate conclusion, Dagger 2.x eliminates all reflection, and improves code clarity by removing the traditional ObjectGraph/Injector in favor of user-specified @Component interfaces.
Remarks
- Library setup in an application (for Maven, Gradle, and Java projects)
- Advantages of Dagger
- Important links (for documentation and demos)
- How to integrate and use Dagger components
The setup, advantages, and integration steps are not on this page. The notes below are the annotations and links.
Dagger 2 API:
Dagger 2 exposes a number of special annotations:
@Module for the classes whose methods provide dependencies
@Provides for the methods within @Module classes
@Inject to request a dependency (a constructor, a field, or a method)
@Component is a bridge interface between modules and injection
Important Links:
GitHub: https://github.com/google/dagger
UserGuide(Google): https://google.github.io/dagger/users-guide.html
Videos: https://google.github.io/dagger/resources.html
Vogella Tutorial: http://www.vogella.com/tutorials/Dagger/article.html
Codepath Tutorial: https://github.com/codepath/android_guides/wiki/Dependency-Injection-with-Dagger-2