I've run into that sort of thing a few times, and ended up developing a 
small library for easily writing custom Scopes, and then just have the code 
that is the front-door where requests come in enter the scope, passing in 
an array of objects that should be available for injection.  That way, 
objects don't leak outside of the call stack (unless you want them to - 
there's a way to wrap an ExecutorService so that will reenter the scope if 
you need to do async stuff).

http://timboudreau.com/code/useful/file/40f2eefbba65/guicy/guicy/src/main/java/com/mastfrog/guicy/scope

Whether you use that code or your own stuff, that sounds like the pattern 
you want.  I gather writing your own scopes is discouraged for some reason 
or other, but with some well-tested base classes to avoid the obvious 
potential issues, they're darned useful - you could probably do it with 
assisted inject, but it would be considerably more verbose than
myScope.enter(someRunnable, connection, user);

-Tim

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-guice/-/fgWXII3SvqQJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to