users@jax-rs-spec.java.net

[jax-rs-spec users] Re: Using ContextResolver for getting custom contexts injected

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Wed, 15 Jul 2015 14:57:52 +0200

Hi Sergey,

I would instead suggest people to turn to CDI if they need custom injection. Iím not convinced that we should do any additional work on JAX-RS specific injection now that DI and CDI is around. Better DI and CDI integration is, of course a different question - we should invest into improvements on that front IMO.

Cheers,
Marek

> On 29 Jun 2015, at 14:12, Sergey Beryozkin <sberyozkin_at_talend.com> wrote:
>
> That of course would imply that its JavaDocs would need to be clarified a bit, example, the typical case is where ContextResolver<JAXBContext> is injected and then it is asked to create JAXBContext for a class like Book, etc.
>
> So the text would have to say that it is the resolver specific action as to how to act to contextResolver.getContext(T.class), example, given ContextResolver<JAXBContext> and contextResolver.getContext(JAXBContext.class) returns null, while given ContextResolver<CustomContext> and contextResolver.getContext(CustomContext.class) is expected to return CustomContext.
>
> Besides, the fact ContextResolver can have @Produces does not help as far as its use as a generic context injection mechanism is concerned but again it can be noted which resolvers might want to use @Producers.
>
> It is a bit unfortunate but I guess this would imply a bit of overloading of the original ContextResolver idea. I reckon the careful wording might make it reasonable and save on introducing some new interface/mechanism to support the injection of custom contexts in 2.0. Not insisting but wondering what other think...
>
> Sergey
>
>
>
>
> ________________________________________
> From: Sergey Beryozkin <sberyozkin_at_talend.com>
> Sent: 24 June 2015 13:19
> To: jsr370-experts_at_jax-rs-spec.java.net
> Subject: Using ContextResolver for getting custom contexts injected
>
> Hi
>
> is there any reason why the spec can not be enhanced to support using ContextResolver to have the custom contexts injected:
>
> @Path("rs")
> public class Root {
> @Context CustomContext context;
>
> }
>
> MyContextResolver implements ContextResolver<CustomContext> ?
>
>
>
> It appears some users expect it to work this way ?
> As far as I know ContextResolver is mainly used with JAXB providers to help resolve JAXB contexts, but may be it can be reasonable to reuse it for injecting the custom contexts too as opposed to coming up with some new standard mechanism to support the injection of custom contexts ?
>
> Sergey