users@jersey.java.net

Re: [Jersey] Guice, injecting into constructors, etc

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 22 Jun 2010 08:49:30 -0700

Hi Chris,

The situation has not changed much. To support constructor injection
of say @QueryParam requires some modification to Guice.

I did recently add support for binding of UriInfo etc via Guice that
can be used with constructor injection see:

   https://jersey.dev.java.net/nonav/apidocs/latest/contribs/jersey-guice/com/sun/jersey/guice/JerseyServletModule.html

IMHO i think Guice is cleaner than Spring, especially if you do not
require all the additional Spring stuff. I like the way modules
provide a "unit of bindings" for isolation, reuse and extension.

I know we can and should improve the Spring support, namely it needs
to integrate properly with the injection process, plus could provide
similar bindings as for the case of Guice (but i do not know how to do
that).

Paul.

On Jun 18, 2010, at 2:42 PM, Christopher Piggott wrote:

> Hi,
>
> I'm just wondering about a couple of things...
>
> Paul S. wrote: http://blogs.sun.com/sandoz/entry/guice_2_0_is_almost
> back in 2009:
>
> and linked to it in response to
> http://jersey.576304.n2.nabble.com/Can-QueryParam-be-used-in-resource-constructor-along-with-Guice-injection-td4488885.html
>
> The gist of those communications as I understand them was that ycx4321
> said "I would like constructor injection" followed by Paul S. saying
> "I prefer constructor injection, too, but..."
>
> From a testability perspective, I agree ... plus, I have always mildly
> disliked the concept of injecting into private data members.
>
> I like guice, but part of why I looked at it was because, at the time,
> I was only aware of old-style spring bindings via xml files, which I
> really didn't want. Now it seems that's no longer necessary. I was
> tempted to say heck with it, I'll use jersey-spring instead of
> jersey-guice -- but there are still some things I like better about
> guice, and there's also the appearance that jersey and guice are
> integrated and work together a little more easily. (agree or
> disagree?)
>
>
> The constructor injection thing isn't by any means a deal breaker, but
> I'm wondering if the situation has changed since Paul wrote that in
> Aug 2009.
>
>
> --Chris
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>