frjaeger220 / google-guice

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

com.google.inject.Injector.GuiceServletContextListener.INJECTOR_NAME should be protected #326

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
We need to be able to get INJECTOR_NAME when subclassing
GuiceServletContextListener because of the following use-case:

1) GuiceServletContextListener creates an Injector
2) Other filters (such as Jersey) need to get at the existing Injector. I
am able to pass them the name of the context attribute holding the Injector
but I have no safe way of getting at it.

It is also worth nothing that I need to get at this information from
com.google.inject.servlet.ServletModule.configureServlets() which occurs
before the actual Injector is instantiated. This is because ServletModule
binds JerseyServlet which takes an init-param indicating the injector name.

FYI: This change was recently applied to warp-servlet. It was never ported
to the Guice branch. I'm not sure whether this was done on purpose or not.

Original issue reported on code.google.com by gili.tza...@gmail.com on 7 Feb 2009 at 4:36

GoogleCodeExporter commented 9 years ago
Small caveat: In warp-servlet all the module configuration went directly into
ServletContextInjector so you could access the protected field directly. In
guice-servlet we implement ServletModule which is not directly bound
GuiceServletContextListener.

This means that the ServletContextInjector.getInjector() implementation will 
need to
grab INJECTOR_NAME from the superclass and pass it to the ServletModule 
constructor.
This is the cleanest approach that comes to mind.

You could also expose the value using a getter method instead of accessing the 
field
directly. Let me know if you have a better idea.

Original comment by gili.tza...@gmail.com on 7 Feb 2009 at 4:51

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 7 Feb 2009 at 8:45

GoogleCodeExporter commented 9 years ago
Why can't you simply inject the Jersey filter directly, and manage it thru 
Guice Servlet?

Original comment by dha...@gmail.com on 7 Feb 2009 at 11:33

GoogleCodeExporter commented 9 years ago
Dhanji, I'm not sure what you mean. Can you give an example?

I'm trying to get Jersey to delegate injection of its internal classes to 
Guice. In
order to do that I need to pass it a reference to the Injector.

Original comment by gili.tza...@gmail.com on 8 Feb 2009 at 3:12

GoogleCodeExporter commented 9 years ago
A reference to the Injector can be @Injected into any provider--make one for 
the Jersey filter and pass the 
injector along.

As long as the Jersey Filter is registered in a ServletModule, it can be 
injected like any other Guice object. 

Btw, we are going to remove the injector from the servlet context (and get rid 
of INJECTOR_NAME altogether) so 
the preferred way is the use ServletModule from now on.

Original comment by dha...@gmail.com on 8 Feb 2009 at 7:50