bineanzhou / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Accessing Guice Injector from SessionListener #170

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
We are writing an application using Struts 2 + Guice.  We are using the
Guice Struts 2 plugin of course and everything has been working great...
until this morning when I tried to write a SessionListener.  Clearly, the
lifecycle of the SessionListener is not managed by Struts and therefore
isn't going to go thru the GuiceObjectFactory.  At first I figured I would
just access the GuiceObjectFactory directly via
ObjectFactory.getObjectFactory() but this is dependent on a thread-local
which is not available in the context of the SessionListener.  Bummer...

So how do I get a hold of a "global" Guice Injector for cases like these? 
This type of thing is easy to do in Spring but I couldn't find anything
similar in Guice.  The options I see are:

1) Wire up Guice myself instead of using the Struts 2 Guice Plugin
2) Extend the GuiceObjectFactory to make the instance available... almost
like a Singleton.  Really just a variation on #1.
3) ???

Thoughts?

Original issue reported on code.google.com by chris.ma...@gmail.com on 17 Dec 2007 at 4:55

GoogleCodeExporter commented 9 years ago
Wired up Guice ourselves in our case.

Original comment by earwin@gmail.com on 1 Apr 2008 at 10:32

GoogleCodeExporter commented 9 years ago
You can also inject the injector.

Original comment by limpbizkit on 5 Jun 2008 at 4:49

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 27 Apr 2009 at 6:14