[cdi-dev] adding generic producers to CDI 2.0?

Romain Manni-Bucau rmannibucau at gmail.com
Fri Feb 12 12:23:27 EST 2016


2016-02-12 18:18 GMT+01:00 Mark Struberg <struberg at yahoo.de>:

> I think that would need a multi-pass ‚coercion‘ like it’s done in the jvm.
>

Nop cause of the constraint I associated to @generic


> Currently it’s a getBeans(type) (+ resolve).
> And after that only a single candidate must be left.
>
> To support your desired case we would need to do a ’nearest’ search means
> if you have the following producers
>
> @Produces List<String> ..
> @Produces List<?> ..
> @Produces Object ..
>
>
This would fail at deploy time if they all have @generic, if not then the
@Generic producer is just ignored and overriden with the rules with have
today if it matches (see @Generic as a fallback if nothing matched but the
qualifier).


>
> @Inject List<String> x; // first producer would be taken
> @Inject List<Integer> x; // second producer would be taken
> @Inject BlaBla x; // third producer would be taken;
>
> We’ve discussed similar things back then in CDI-304 I think.
>
> Of course that would only work if the producer has a chance to inspect the
> injection point. Means those producers would need to be @Dependent I guess?
>
>
Yep


> Do we go down this route? Or is this an overkill? No idea yet… Might be
> very powerful but maybe also very fragile?
>
> LieGrue,
> strub
>
>
> > Am 12.02.2016 um 17:56 schrieb Romain Manni-Bucau <rmannibucau at gmail.com
> >:
> >
> > Hi guys,
> >
> > could CDI 2 do step forward for generic producers?
> >
> > The need is to produce any type (with a particular qualifier) without
> the need of an extension:
> >
> > @Produces
> > @MyQualifier
> > Object create(InjectionPoint ip) { ... }
> >
> > This is actually a common pattern (for configuration, or to integrate
> with 3rd party libs) and today the only hope to do so is to write an
> extension which is a bit technical and verbose for the result IMO.
> >
> > I guess for compatibility reason we would need to do something like:
> >
> > @Produces
> > @MyQualifier
> > @Generic
> > Object create(InjectionPoint ip) { ... }
> >
> > and say that if there is a unique resolved bean thanks to qualifiers
> which is annotated @Generic then use this producer.
> >
> > wdyt?
> >
> > Romain Manni-Bucau
> > @rmannibucau |  Blog | Github | LinkedIn | Tomitriber
> > _______________________________________________
> > cdi-dev mailing list
> > cdi-dev at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/cdi-dev
> >
> > Note that for all code provided on this list, the provider licenses the
> code under the Apache License, Version 2 (
> http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas
> provided on this list, the provider waives all patent and other
> intellectual property rights inherent in such information.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/cdi-dev/attachments/20160212/866863c7/attachment.html 


More information about the cdi-dev mailing list