Open GoogleCodeExporter opened 9 years ago
Particularly for the Servlet extension. Im not sure that we can provide a
general mechanism (that would also work well for Servlet), but Im open to
suggestions.
Original comment by dha...@gmail.com
on 18 Jul 2010 at 1:27
Jesse and I spoke about it the other day when I was visiting mountain view, and
he had some good ideas for how it could be done. I hacked up an implementation
on my laptop (which I hope I haven't deleted.. have to check), but got
distracted in trying to figure out what to expose for AssistedInject. I'm not
familiar enough with servlet to know what it wants to expose, but I'll try to
recover the patch & attach it here to see if it's enough to hook into.
Original comment by sberlin
on 19 Jul 2010 at 1:35
Attached are two patches for an extension SPI.
1) guice-extension-spi.txt
This is a small patch that changes Guice so that extensions can provide their own SPI. All it does is introduce a new 'ProviderWithExtensionVisitor' interface that has an 'acceptExtensionVisitor' method. The existing ProviderInstanceBindingImpl class now checks to see if the providerInstance it is calling visit on is an instance of ProviderWithExtensionVisitor, and if so, it delegates the visitation to ProviderWithExtensionVisitor.acceptExtensionVisitor. This is the hook where extensions take over.
2) servlet-extension-spi.txt
This is a minor reworking of the servlet extension so that it can expose its bindings through the SPI. It creates a new public interface 'ServletModuleTargetVisitor' that has these methods:
visitFilterBinding(String, Key, Map)
visitFilterBinding(String, Filter, Map)
visitFilterRegexBinding(String, Key, Map)
visitFilterRegexBinding(String, Filter, Map)
visitServletBinding(String, Key, Map)
visitServletBinding(String, HttpServlet, Map)
visitServletRegexBinding(String, Key, Map)
visitServletRegexBinding(String, HttpServlet, Map)
and calls those methods for any filter(..) or serve(..) methods created in the ServletModule. In order to support this, I had to change the internals of the extension so that each ServletDefinition and FilterDefinition was bound on its own, instead of through a List. The only actual effect this will have is that there will be an additional binding in the Injector for each pattern.
Original comment by sberlin
on 21 Jul 2010 at 4:28
Attachments:
I like the approach.
Original comment by limpbizkit
on 21 Jul 2010 at 6:25
Another variation on how servlet can expose its bindings.
guice-extension-spi.txt would still be applied, but this time the
ServletModuleTargetVisitor looks like:
V visit(LinkedFilterBinding)
V visit(InstanceFilterBinding)
V visit(LinkedServletBinding)
V visit(InstanceServletBinding)
more in the spirit of the other visitor interfaces. Each binding interface has:
boolean isRegex
String getPattern
Map<String, String> getContextParams
and also one of:
Filter getFilterInstance,
HttpServlet getServletInstance,
Key<? extends Filter> getLinkedKey,
or Key<? extends HttpServlet> getLinkedKey
I like this variation slightly better, despite the increase in interfaces,
because it's more suited to growth in the future (if the extension wants to add
any more options to its bindings), and the visitor interface is much simpler.
I was thinking of also adding a parent interface ServletModuleBinding that
contained the three shared methods, but didn't see much use in it now, so
didn't do it.
Original comment by sberlin
on 31 Jul 2010 at 11:07
Attachments:
implemented in r1206 & r1207.
Original comment by sberlin
on 22 Aug 2010 at 6:49
Original issue reported on code.google.com by
sberlin
on 18 Jul 2010 at 12:15