users@jax-rs-spec.java.net

[jax-rs-spec users] [jsr339-experts] Re: Re: Open questions on JSR 330 support

From: Santiago Pericas-Geertsen <Santiago.PericasGeertsen_at_oracle.com>
Date: Thu, 26 Jan 2012 10:57:28 -0500

On Jan 25, 2012, at 8:47 AM, Bill Burke wrote:

>
>
> On 1/25/12 5:13 AM, Marek Potociar wrote:
>> - Should we drop DI and once new CDI extension API is finalized, should we focus more on CDI instead?
>>
>
> Yes ditch 330, CDI is a much more of a thought out, rich API and interface.

 DI on the EE platform is quite confusing even for advanced users. EE 5 got the ball rolling with @Resource, @EJB, etc. and EE 6 introduced 330 and CDI with @Inject. If you use @ManagedBean, you use one set of annotations, if you use CDI, another :(

 JAX-RS did not help the cause by introducing @Context (and ContextResolver). So using CDI and JAX-RS, we get:

@Path(…)
class MyResource {
  @Inject MyBean bean;
  @Context UriInfo ui;
… }

 :(
 
> BTW, AFAIK, DI can't handle parameter injection. @Inject isn't even parameter scoped.

> So I don't see why we should mix the two until that is at least resolved. Also, I"m not sure, but I don't think CDI supports parameter injection either.

 CDI supports parameter injection for things called by its container. E.g., using @Inject for constructors and setters [1], as well as parameter injection for producers, observers, etc. These are not unlike resource methods in JAX-RS. As pointed out by Marek, using @Inject at method level introduces some challenges like discerning entity params (without qualifiers).

 In summary, although I acknowledge the issues, I'm not convinced we should drop this altogether. In fact, better integration with CDI and (at least some) support for 330 are not completely disconnected IMO.

-- Santiago

[1] http://docs.jboss.org/weld/reference/latest/en-US/html/injection.html