users@jax-rs-spec.java.net

[jax-rs-spec users] Injection in JAX-RS

From: Chase <chase_at_osdev.org>
Date: Tue, 19 Mar 2013 01:24:41 -0500

The draft for JAX-RS (10.2.6 Additional Requirements) says that @Inject
might be used be used to inject JAX-RS annotated fields but must not be
required and should warn about it.

Shouldn't this be the other way around? CDI is the stand for DI in EE, why
not drop @Context or at least warn against its usage and require @Inject
for portable implementations?

It'd also be nice if something was done about field injection in resources
returned by sub-resource locator methods. Maybe support something like:

@Path("sub")
public SubResource getSub(@Inject SubResource sr) {
  //extra init
  return sr;
}

or

@Path("sub")
public SubResource getSub() {
  return JAXRSFactory.newInstance(SubResource.class);
}

Something along either of these lines would put the container in charge of
constructing sub resource class instances and allow for field injection to
work.

-Chase