users@jax-rs-spec.java.net

[jax-rs-spec users] [jsr339-experts] Re: Re: Re: Back To DI in Subresources

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Wed, 18 Apr 2012 17:02:14 +0200

On Apr 17, 2012, at 6:12 PM, Bill Burke wrote:

>
>
> On 4/17/12 11:37 AM, Santiago Pericas-Geertsen wrote:
>>
>> On Apr 17, 2012, at 7:45 AM, Marek Potociar wrote:
>>
>>> There are 2 solutions that I've been thinking about:
>>>
>>> 1. introduce an injectable request-scoped ResourceContext with
>>> methods like inject(Class<?> subresourceClass), inject(Object
>>> subresource)
>>> 2. update the spec to mandate field injection on the sub-resource
>>> instances returned by sub-resource locator.
>>>
>>>
>>> So far I am leaning towards #1 as it seems more flexible.
>>>
>>> Any thoughts on the above?
>>
>> Why not both? As you say, (1) is more flexible but (2) is quite convenient.
>>
>
> I don't see why you need #1 if you have #2. Things would be doubly injected. Also, is there any issues with singletons vs. per-request sub-resource instances? I can't think of any at the moment, so long as injected things are proxied appropriately.

I guess a potential issue with #2 is that you may want to return a fully custom-initialized sub-resource (that may contain @Context/@*Param annotations on fields) occasionally. In such cases the automatic injection would need to be disabled somehow. That's why I am saying that #1 is more flexible and that's also why I am leaning towards that approach.

Marek

>
> Bill
>
> --
> Bill Burke
> JBoss, a division of Red Hat
> http://bill.burkecentral.com