[cdi-dev] [JBoss JIRA] (CDI-109) Invalid beans should not be injectable into extensions

Jozef Hartinger (Reopened) (JIRA) jira-events at lists.jboss.org
Fri Nov 18 12:33:40 EST 2011

     [ https://issues.jboss.org/browse/CDI-109?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jozef Hartinger reopened CDI-109:

This requires further clarification.

The spec currently says that:
Service providers may have observer methods, which may observe any event, including any container lifecycle event, and
obtain an injected BeanManager reference. If other beans are injected into service providers, non-portable behavior results.

The first part clearly indicates, that it is the *observer method* who may obtain the BeanManager. However, the second part
If other beans are injected *into service providers*
suggests the service providers can receive other types of injection (e.g. field injection), which is not allowed by the specification.

The other issue is with the normal observer methods (those not observing a container lifecycle event). Such observer methods can be defined on extension and we should guarantee that if invoked at runtime, they behave the same as observer methods defined on other beans (i.e. injecting any bean is allowed).

Hopefully, this table illustrates the problem better:

|This table describes injection guarantee the container should provide for a given type of observer method defined on an Extension in a particular phase|*container lifecycle event observer method*|*normal observer method*|
|*container initialization*|BeanManager, injection of other beans non-portable|BeanManager, injection of other beans non-portable|
|*runtime*|N/A|any bean can be injected|
> Invalid beans should not be injectable into extensions
> ------------------------------------------------------
>                 Key: CDI-109
>                 URL: https://issues.jboss.org/browse/CDI-109
>             Project: CDI Specification Issues
>          Issue Type: Feature Request
>          Components: Portable Extensions
>    Affects Versions: 1.0, 1.1.EDR1
>            Reporter: John Ament
>            Assignee: Pete Muir
>            Priority: Minor
>             Fix For: 1.1 (Proposed)
> Currently, you can inject beans that may not be ready yet into the extension's call back methods.  As an example, I can inject something application scoped like this in to an extension, but it should really be throwing a definition exception (or similar):
> public void handleABD(@Observes AfterBeanDiscovery abd, MyApplicationScopedBean masb) {
> }
> Pete had noted that really the only safe thing to inject, other than the observed call back, is the bean manager.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the cdi-dev mailing list