users@jersey.java.net

Re: [Jersey] Guice injection does not support field/method injection without forcing you to bind the Resource class to the module...

From: James Strachan <james.strachan_at_gmail.com>
Date: Fri, 30 Apr 2010 16:41:53 +0100

On 30 April 2010 16:36, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
> Hi James,
>
> You beat me to it :-)
>
> I think we may be able to refine things as i got the following to work:
>
>    @Path("unbound/perrequest")
>    public static class InjectedPerRequestResource {
>
>        @Context UriInfo ui;
>
>        String x;
>
>        @Inject
>        GuiceManagedClass gmc;
>
>        public InjectedPerRequestResource(@QueryParam("x") String x) {
>            this.x = x;
>        }
>
>        @GET
>        @Produces("text/plain")
>        public String getIt() {
>            assertEquals("unbound/perrequest", ui.getPath());
>            assertEquals("x", x);
>
>            return gmc.toString();
>        }
>    }
>
> Thus we can also support the case when Jersey instantiates and Guice injects
> too i.e. when there are constructors with no @Inject with @Injected
> fields/methods.

Great!


> I will merge things.

Great stuff, thanks! :)


-- 
James
-------
http://macstrac.blogspot.com/
Open Source Integration
http://fusesource.com/