Ich arbeite mit Guice, jedoch verstehe ich eins nicht so richtig.
Also man hat ja ein Injector, wo man sich seine ganzen Module erzeugt
In den Modulen wird es gebunden.
Was ich NICHT verstehe wann brauche ich ein Provider und wann nicht ?
mit Providern:
ohne Providern:
ich versteh halt nichtwirklich wann ich was mache???!???:L:rtfm:
Kann mir jemand das verdeutlichen bitte
Also man hat ja ein Injector, wo man sich seine ganzen Module erzeugt
Java:
Injector injector = createInjector(new Module1(),
new NotifierModule());
In den Modulen wird es gebunden.
Was ich NICHT verstehe wann brauche ich ein Provider und wann nicht ?
mit Providern:
Java:
public class NotifierModule extends AbstractModule {
private NotifierProvider provider;
/**
* Erzeugt ein {@link NotifierModule}
*/
public NotifierModule(@Nonnull INotifier handlerInstance) {
provider = new NotifierProvider(handlerInstance);
}
@Override
protected void configure() {
bind(INotifier.class).toProvider(NotifierProvider.class).in(SINGLETON);
}
private class NotifierProvider implements Provider<INotifier> {
private INotifier instance;
public NotifierProvider(INotifier handler) {
instance = handler;
}
@Override
public INotifier get() {
return instance;
}
}
}
ohne Providern:
Java:
public class NotifierModule extends AbstractModule {
@Override
protected void configure() {
bind(INotifier.class).to(Notifier.class);
}
}
ich versteh halt nichtwirklich wann ich was mache???!???:L:rtfm:
Kann mir jemand das verdeutlichen bitte