jsr339-experts@jax-rs-spec.java.net

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

From: Bill Burke <bburke_at_redhat.com>
Date: Thu, 19 Apr 2012 08:46:10 -0400

On 4/19/12 5:01 AM, Sergey Beryozkin wrote:
> On 17/04/12 16:37, 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 understand how the sub-resource injection can work at all.
> Lets take an example where a root resource is a singleton.
>
> This root resource can return sub-resource instances. Such instances can
> be created at a per-request basis or may've been pre-allocated and are
> singletons too. Only the root resource knows the rules.
>
> How can the runtime make sure that the injection into sub-resources is
> thread-safe ?
>

Another thing, if the sub-resource is an EJB or CDI bean, won't
injection happen anyways?

Bill

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