Hi, I work with legacy web app that have a ojbect in session scope.
I create a new front end with Vaadin and mvp lite that work togheter with old Struts front end.
Now in my vaadin application class at every request, i create a new injector with an object because i retrieve a UserContextInfo object from Session that have some infos of user and db name to use.
private Module createModule(final CreateViewService s) {
Module modules = new AbstractModule() {
@Override
protected void configure() {
bind(EventBus.class).toInstance(eventBus);
// usercontext info get from request
bind(UserContextInfoDecorator.class).toInstance(userContextInfo);
bind(View.class).annotatedWith(ParentViewAnnotation.class).toInstance(s.getParent());
bind(Parameter.class).toInstance(s.getParameters());
bind(SecureValidator.class).toInstance(validator);
}
};
return modules;
}
At every request i create a new injector whit this method and catch the exact instance of UserContextInfo.
private View createViewInstance(Class<? extends View> clazz, Module modules) throws GuiException, ProvisionException {
Injector localInjector = Guice.createInjector(modules);
View instance = localInjector.getInstance(clazz);
instance.inizialize(validator);
return instance;
}
It right use of guice? or it's better to exclude instance parameter from injections? Any suggestion?