On Mar 19, 2013, at 7:24 AM, Chase <chase_at_osdev.org> wrote:
> 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?
Because it would be backward incompatible and would break all the existing JAX-RS applications. Note that the warning does not apply if you develop your resources as CDI beans.
>
> 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.
That's already possible in JAX-RS 2.0 - see
http://jax-rs-spec.java.net/nonav/2.0-SNAPSHOT/apidocs/javax/ws/rs/container/ResourceContext.html
Marek
>
> -Chase