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

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

From: Santiago Pericas-Geertsen <Santiago.PericasGeertsen_at_oracle.com>
Date: Fri, 20 Apr 2012 11:38:29 -0400

On Apr 20, 2012, at 11:28 AM, Bill Burke wrote:

>
>
> On 4/20/12 11:18 AM, Santiago Pericas-Geertsen wrote:
>>
>> On Apr 19, 2012, at 8:46 AM, Bill Burke wrote:
>>
>>>>>
>>>>> 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?
>>
>> Yes, but not for @Context stuff, right?
>>
>
> Why wouldn't/shouldn't it?
 
 Because the EJB or CDI container don't understand the meaning of @Context?

 Perhaps we are starting to discuss an implementation technique here. Let's take CDI as an example. The bean is first created and injected by CDI (for everything that it understands, like @Inject) and then it's passed to the JAX-RS container to finish injection (of @Context). The alternative would be to "teach" CDI about @Context and everything that is injectable in JAX-RS. Is that what you have in mind?

-- Santiago