users@jersey.java.net

Re: [Jersey] Guice access to Jersey-created objects

From: Craig McClanahan <Craig.McClanahan_at_Sun.COM>
Date: Thu, 13 Aug 2009 14:43:07 -0700

Richard Wallace wrote:
> On Thu, Aug 13, 2009 at 11:32 AM, Craig
> McClanahan<Craig.McClanahan_at_sun.com> wrote:
>
>> Furthering my explorations with integrating Jersey and Guice, I'd like to be
>> able to inject Jersey-provided components into a Guice-instantiated service
>> class. As a particular example, I have a "transformer" class that turns my
>> internal data model object into a suitable external representation,
>> including some computed URIs. For that, I need to have Guice able to inject
>> things like the UriInfo object Jersey injects into resource classes.
>>
>> OK, I can bind a Provider<UriInfo> into Guice's injector ... but where does
>> the implementation of this acquire the UriInfo instance from Jersey? Any
>> ideas on a strategy to make these kinds of things visible to Guice's
>> injector?
>>
>
> What I've been doing is allowing Guice to create my WebApplication
> instance and injecting that into my own GuiceServletContainer which
> overrides the create() method to return the injected WebApplication.
> If you do that, then you can do something like what I have here
> <http://pastie.org/583188>. It's in Scala, but you should be able to
> get the idea.
>
> I also talked with Paul once about taking it a bit further. It
> requires exposing more of the Jersey services so they could be
> injected using Guice 2.0's custom integrations. The biggest drawback
> is that they wouldn't be injectable into the constructor that way,
> only on fields and methods. But it would be better than nothing I
> figure. Unfortunately, I haven't found the time to follow up on this.
> Maybe you can?
>
>
Thanks for the info ... this will really help. I'll see if I can come
up with something we could consider adding to jersey-guice.

Craig
> Rich
>
> [1] http://code.google.com/docreader/#p=google-guice&s=google-guice&t=CustomInjections
> [2] http://n2.nabble.com/Enhanced-Guice-Jersey-integration-td3140841.html#a3140841
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>