[cdi-dev] Minutes/Notes from CDI EG meeting (hangout) on 13th August
pmuir at redhat.com
Wed Aug 15 09:20:01 EDT 2012
On 15 Aug 2012, at 12:10, Pete Muir wrote:
> Multiple Annotated Types
> We then moved on to discuss https://issues.jboss.org/browse/CDI-58. This concerns whether there can be greater than one annotated type per class instance in the JVM. Gavin intended there should be, principally to support an XML configuration dialect, which could introduce multiple versions of a class, each with a different qualifier. However, this is not TCK tested, and implementations vary in how they support this.
> We discussed that this makes an implementation considerably more complex (as there is no easy way to uniquely identify an annotated type e.g. for serialization), and also is pretty confusing for a user (as you now get multiple ProcessAnnotatedType events for each class, making it hard to know which one you want to change).
> We looked at alternative solutions, and concluded that if all use cases can be satisfied by adding a new bean, rather than a new annotated type, we would like to explicitly specify that there is only one annotated type per class instance. In CDI 1.1 it is already much easier to add and manipulate beans from annotated types, so we believe that the correct thing here is take this route.
> Action: Pete to contact extension authoring groups, and verify that this approach will work and have minimum impact on existing extensions
Team, on digging into this I've noticed that this doesn't necessarily pass properly through the ProcessBeanAttributes event (which is what allows modification of a bean metadata) as 11.5.10 says
"1.5.10. ProcessBeanAttributes event
The container must fire an event for each enabled bean, interceptor or decorator deployed in a bean archive, before registering the Bean object."
And as outlined in , this bean is not "deployed in a bean archive" but added via addBean().
There are possible ways to fix this, including explicitly stating that calling createBean() with a BeanAttributes will file a PBA event...
BeanAttributes ba = beanManager.cerateBeanAttributes(annotatedType);
InjectionTarget it = beanmanager.createInjectionTarget(annotatedType);
Bean b = beanManager.createBean(ba, clazz, it);
BeanAttributes ba = beanManager.cerateBeanAttributes(annotatedFieldOrMethod);
Producer p = beanmanager.createProducer(annotatedFieldOrMethod);
Bean b = beanManager.createBean(ba, clazz, p);
The Bean can then be registered using
More information about the cdi-dev