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

Mark Struberg struberg at yahoo.de
Fri Feb 12 12:18:44 EST 2016


I think that would need a multi-pass ‚coercion‘ like it’s done in the jvm. 
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 ..


@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?

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.




More information about the cdi-dev mailing list