users@jersey.java.net

Re: [Jersey] Newbie question: How do I inject objects into resources

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Wed, 25 Mar 2009 10:21:07 -0700

On Wed, Mar 25, 2009 at 10:17 AM, David Fogel <carrotsalad_at_gmail.com> wrote:
> Hi Craig, Paul-
>
> Thanks for responding, and I think that does answer my question.
>
> What this seems to mean is that JAX-RS is not a stand-alone
> specification, and any implementation of it is essentially useless
> without extra features outside the realm of what's covered by JAX-RS
> itself (specifically the ability to access any kind of application
> state or services), which in turn seems to imply that there's
> essentially no such thing as _portable_ JAX-RS code, and never will
> be.
...

That is the challenge of API specifications isn't it? Shouldn't
reinvent other parts, need to rely on some, but not all come into
existence at same point.
So comparison to full frameworks (Restlet) is apples to oranges.

But on a practical note, assuming you do run on a servlet container,
why not just use standard way of injecting those context objects and
access it from there (and initialize using the usual Servlet way).
Seems similar to the original example.

And one thing to keep mind is that while setup work (for new kinds of
injectable things) is bit verbose, that's a one-time cost, compared to
using injected things.
So overall effects of complexity may be overblown: time to set up a
web service is a tiny fraction of overall effort (development,
testing, maintenance etc).

Just my 2c,

-+ Tatu +-