Creating the injector can be rather expensive.
You may consider either of the following:
- Create child injectors instead of the main injector for every
request.
- Use RequestScope (see:
https://code.google.com/p/google-guice/wiki/Scopes) to have an
instance which is a singleton for the request and can be used to
store the data which you collected from the request.
On 05/28/2014 04:56 PM, Luca Miorelli
wrote:
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?
--
You received this message because you are subscribed to the Google
Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it,
send an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/d/optout.
|