Stats

69 Contributors: 2
Wednesday, August 2, 2017
Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook

Library Dagger 2: Dependency Injection in Applications

Download android eBook

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

  1. Library setup in application(for maven, gradle,java projects)
  2. Advantages of Dragger use
  3. Important Links (for Documentation and demos)
  4. How to integrate and use Dragger components

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

Related Examples