Dagger 2 is around the corner but the available examples wouldn't even compile right off the box, and the documentation is a copy-paste-replace from Dagger 1.
Does anyone have an example of a proper application working on Google's Dagger 2?
What is Dagger 2? Dagger 2 is a dependency injection for Android. Dagger 2 is a dependency injection (DI) framework. And, Dependency Injection in build upon the concept of Inversion of Control which says that a class should get its dependencies from outside.
This interface defines the connection between the provider of objects (modules) and the objects which express a dependency (consumers). The name of the the generated class is Dagger + the name of the interface. This generated class has a create () method which allows configuring the objects based on the given configuration.
You can use the @Singleton annotation to indicate that there should be only one instance of the object. This is the most basic example of using Dagger 2 without component dependencies, subcomponents, complex modules, or custom scopes. The main Dagger 2 features used are:
If you want to use field injection you have to define a method in your @Component interface which takes the instance into which you would like Dagger 2 to inject an object into this field. You can use the @Singleton annotation to indicate that there should be only one instance of the object.
I've just published sample app based on Gradle which integrates Dagger2, retrolambda, butterknife and lombok. You can find it here: https://github.com/mgrzechocinski/dagger2-example.
Hope it would help :)
I've just ported u2020-mvp app to Dagger 2. We use it as our sandbox app. Dagger 2 has nice implementation of scopes by the way. Components are really big deal. And it is based on u2021 made by Christian Gruber. You can check that as well.
Hope it helps :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With