0 Replies Latest reply on Oct 24, 2011 9:14 PM by Andrew Hughes

    Programatic Lookup, Qualifiers and Assisted Injection

    Andrew Hughes Newbie

      Hi All,

      CDI does a great job of minimizing the boiler plate for qualified injection at compile time. Unfortunately, after becoming somewhat hooked on Guice's Assisted injection I can't see CDI can be anywhere near as clean and productive with runtime classification. I hope I am wrong....

      It's also easiest if I have a simple example. An online dynamic/realtime data service has just provided me with a Collection<Invention>. Because these are Inventions I don't know anything about them at compile time.

      Now, that I have the latest Invention's I want to use each Invention as a Qualifier to have the Invention's associated object's injected throughout my application. Which are then used to inject other objects and so on...

      How's this best achieved in CDI?

      •   Boilerplating the injection via AnnotationLiteral's, its instance thereof and Instance<XXX>.select() seems much heavier than Guice.

      • Arguably, the factory assisted interfaces that Guice generates the factory from -to- constructor (impl) leads to strongly typed/controlled factories. Exactly what assisted/classifier arguments ARE or ARE NOT required at the Injection point aren't stipulated in CDI and could be prone to breakage (but I see the alternative argument is that it is not flexible and thats why we have @Producers).

      • @Qualifer annotation's can only hold primitive/final values String, int, double, Class Enum... I find it's usefulness a little too primitive. To discard the Invention object and have to use a primitive String/int/double to identify the object as a classifier's value implies more boilerplating.

      Perhaps I am asking too much, and this is not really what CDI is used for. Perhaps it is appropriate to use Guice's assisted Injection underneath CDI.

      I'm really unsure about all this, but that is stating the obvious.

      Anyone care to share their experience with this (or align my brain with how CDI resolves such a problem)?