Question

I have several components which are application scoped. Depending on which environment I am in, I want to install one or the other. In JBoss Seam, I would use @Install(false), then configure the bean that I wanted through components.xml.

Is there a similar method for doing this in CDI / WELD?

Thanks,

Walter

Was it helpful?

Solution

Well, you can always use a producer method and decide which implementation to instantiate based on some configuration of yours. Remember that in CDI the amount of xml is put to minimum.

So, something like:

@Produces
public Component createComponent() {
   if (configuration.isSomething()) {
       return new ComponentImpl1();
   } else {
       return new ComponentImpl2();
   }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top