Throughout the Guice docs it says the way to mix scopes is with a
provider, but I've not found any concrete examples on how to do it.
I'm not sure my solution is the best/cleanest way, so I'd appreciate
some advice.
I have a servlet annotated as @Singleton, and a Provider<Foo> that I'm
injecting into the servlet's constructor. A Foo is generated based on
information in the current ServletRequest.
Inside Provider<Foo> I've got my get() method, and I've got a static
inner class marked @RequestScoped that generates my Foo:
class FooProvider implements Provider<Foo> {
@Inject Injector injector;
@RequestScoped
static class FooMaker {
HttpServletRequest request;
@Inject
public FooMaker(HttpServletRequest request /*etc.*/) {this.request
= request; }
public Foo makeFoo() { /* make myNewFoo */ return myNewFoo;}
}
@Override
public Foo get() {
return injector.getInstance(FooMaker.class).makeFoo();
}
}
Specifically, can I do away with the inner class? Thanks for your
help!
Jonathan
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to
google...@googlegroups.com.
To unsubscribe from this group, send email to
google-guice...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.