[cdi-dev] Proposal: Improve producer method signature capability by accepting qualifier annotations
Pete Muir
pmuir at redhat.com
Tue Aug 5 07:26:48 EDT 2014
HI Mark,
Thanks for the suggestion. Can you file a JIRA (http://issues.jboss.org/browse/CDI) so we don’t loose this?
Pete
On 1 Aug 2014, at 19:16, Mark Paluch <mpaluch at paluch.biz> wrote:
> CDI supports producer methods which accept the InjectionPoint as argument which allows to access all metadata to the injection point. The InjectionPoint approach adds a certain complexity which is not needed when only qualifier metadata has to be processed. I propose to allow annotation types within the producer method signatures. Code example for a use case:
>
> {code}
> @HttpParam("username") @Inject String username
> {code}
>
> {code}
> import javax.enterprise.inject.Produces;
> import javax.enterprise.inject.spi.InjectionPoint;
>
> class HttpParams
> @Produces
>
> String getParamValue(HttpParam httpParam) {
>
> ServletRequest request = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
>
> return request.getParameter(httpParam.value());
>
> // current support looks like:
> // String getParamValue(InjectionPoint ip) {
> // return request.getParameter(ip.getAnnotated().getAnnotation(HttpParam.class).value());
>
> }
> }
> {code}
>
> Producer methods accepting qualifier annotations ensure to have always an annotation instance, this helps to prevent null pointer access since InjectionPoint.getAnnotated().getAnnotation(java.lang.Class<T>) may return null.
>
> Best regards, Mark
>
> --
>
> PALUCH.biz
> Heckenpfad 14 // 69469 Weinheim
> T. 0 62 01/65 04 24-0 // F. 0 62 01/65 04 24-9
> mpaluch at paluch.biz
> http://www.paluch.biz
>
> _______________________________________________
> cdi-dev mailing list
> cdi-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/cdi-dev
More information about the cdi-dev
mailing list