Hi,

In my application, I have one injector for the entire application, and a 
child injector for every http request that comes in. In some of my classes, 
I want to inject the HttpRequest. However, I don't have the HttpRequest 
until I'm ready to create the child injector. I never ask the parent 
injector for an instance of anything. I have a few singleton bindings, but 
none of them depend in any way on HttpRequest.

My application does not work because guice never lets me create the parent 
injector. It scans through all of the classes it knows about, finds out 
that some where in my code I have an @Inject annotation on a field of type 
HttpRequest, and it fails with the error "No implementation for HttpRequest 
was bound."

Can I disable the completeness checking in the parent injector, and have it 
done only in the child injector, where I actually bind the HttpRequest?

Here's a few solutions I've thought of, and why they don't work for me:

1.) Move 90% of the bindings which are currently in the parent injector 
into the child injector.

This seems like it would have a negative impact on performance. I'm 
particularly concerned about AssistedInject. FactoryModuleBuilder.build 
makes a call to Proxy.newProxyInstance, which contains a global lock. I 
don't want each request to acquire a global lock, even for a little while. 
I can switch away from AssistedInject and use old-fashioned factories, but 
then AOP stops working.

2.) Bind HttpRequest to a provider, and stick the HttpRequest in a 
ThreadLocal.

This does not work for me because my entire application is asynchronous. 
(Lots of Futures.transform all over the place.)

----

On a second look, it seems like I can call FactoryModuleBuilder.build once 
in main, and just install it once for each child injector. So that would 
get around the global lock. It still requires that I move 90% of my 
bindings into a child injector, or switch most of them to just-in-time 
bindings. Can I avoid this? If not, should I be concerned about the 
performance cost of creating a child injector with lots of bindings?

Thanks,
Josh "Ua" Ball

-- 
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/groups/opt_out.


Reply via email to