So you are only annotating the class with @Alternative in order for them not to be automatically picked up and used as beans? If you don't have discovery mode all, then you shouldn't need this at all. If you do have it, then Weld will discover these anyway, it will just not enable them (and you might as well just listen for these beans in ProcessAnnotatedType observer and conditionally remove the annotation there which will result in the bean being picked up and used without any manual registration). Furthermore, if you mean to have them as classes that are normally left alone by discovery, then you can use @Vetoed instead. And last thing I can think of is that you can also specify filters in beans.xml that exclude certain packages from discovery - that way you could leave out the alternative annotation and not have the beans picked up a Why am I explaining that? To illustrate what happens with your current solution (assuming discovery mode "all") - Weld will discover the class annotated with @Alternative on its own a register it, the bean isn't enabled, so it isn't used. The you come in and register another annotated type manually (for the same class) and that one comes without @Alternative and will be used. So you are basically duplicating that class as a bean (but there will be no clash in this case).
.addAnnotatedType(it, null)
Don't use null in place of ID, pick some; even if it's equal to bean's class name plus some suffix. The reason for ID is that there is a situation where you can have multiple annotated types for one underlying class (if I recall correctly). bq as addAnnotatedType(AnnotatedType<?>, String) does not return an AnnotatedTypeConfigurator where I could remove the @Alternative annotation. Using configurator is just as fine, but like I said above, you might want to look into other ways to conditionally add a bean. Hope this isn't too confusing |