As you wrote Dagger supports two kind of injection:
- field injection
- constructor injection
In the first case you create an object then you inject the fields using inject
method. For example in your onCreate
of an Activity you will call this:
mObjectGraph.inject(this);
The second type of injection (constructor injection) requires that the object is created by Dagger. You simply mark the constructor with @Inject
annotation then you can create instance like this:
HasInjectableConstructor instance = mObjectGraph.get(HasInjectableConstructor.class);
That's it. Maybe Dagger 2 will change something in this matter: squ.re/dagger2