users@jersey.java.net

Re: Get rid of requirement for no-arg constructor

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Mon, 26 Nov 2007 12:10:08 +0100

Hi Rich,

please see in line...

On Sat, Nov 24, 2007 at 11:00:55PM -0800, Richard Wallace wrote:
> Hello,
>
> I'm trying to get Guice working with Jersey and am running into one
> roadblock. The thing is that I really like to use constructor injection
> whenever possible. I want to do this with my resources. To that effect
> I've changed the GuiceProvider.getInstance() method from Christians blog
> post to
>
> public Object getInstance(ResourceProviderContext context)
> throws ContainerException {
> Object resource = getInjector(context).getInstance(resourceClass);
> context.injectDependencies(resource);
> return resource;
> }
>
> That way Guice is completely responsible for creating and injecting
> dependencies into the resource object without the need for a no-arg
> constructor.
>
> This should work. But I'm running into a problem because Jersey is
> building an AbstractResource internally to track information about the
> resource class. This wouldn't be a problem except that one of the
> things that it is trying to find is a no-arg constructor. Why does it
> do that? I've search for references to the getConstructor() method and
> usages of the AbstractResourceConstructor class, but they are only used
> within AbstractResource and it doesn't actually do anything with the
> information, it seems to get it just to have it.
>
> Would it be possible to eliminate this completely and get rid of the
> no-arg constructor requirement?

I have reworked the code getting a resource constructor
on [jersey-resourcemodel] branch. The information is then used
by the runtime model, which is being built upon the abstract model.
The no-arg ctor requirement no longer exist there.

Let me check, if it is ok to merge the changes from the branch
into the main trunk. Then I will get back to you.

Thanks,

~Jakub
 


>
> Thanks,
> Rich
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>