I have a Guice based project using vanilla Guice;
no Assisted-Inject, no AOP, no extra plugin extending Guice, etc.
To run it more easily on Android, Dagger seems like a better solution.
Every class has a dependency and a constructor with @Inject
annotation.
No field or method injection is used.
The modules are quite simple (making Guice an overkill) and mostly contain bindings like the following:
class SomethingModule extends AbstractModule {
protected void configure() {
Bind(Handler.class)
.annotatedWith(Names.named("something"))
.to(SomeImplementation.class);
}
}
}
And later used like the following:
Injector inj = Guice.createInjector(new SomethingModule());
... = inj.getInstance(SampleInterface.class);
// and rest of the code.
Unfortunately, I can not get my head around Daggers terminology. Can you guide me with a direct translation / transformation of a Guice module to a Dagger module?
Dagger has:
- Dagger's Components.
- Dagger's Modules.
@Provides
@Inject
Guice has:
@Inject
@Named
(or any custom annotation, if implemented correctly).- Our modules extending
AbstractModule
. @Provides
in the modules.- Guice
Injector
created from modules.
How do these relate?
Update: In addition to the nice answer by EpicPandaForce, these slides can help too.