views:

24

answers:

1

Hi all,

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

A: 

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();
   }
}
Bozho
Right, ok, I think I remember Pete showing this example. I think this will work for me.
I have another use case, I am thinking that I will write an extension. When the server starts up, I will determine if I want to install or register that bean at that point in time. If I don't, I'll simply remove that definition from the container. So, I am thinking that I would add an annotation indicating when to install it, if it shouldn't be installed, it is removed ...