2 Replies Latest reply on Feb 27, 2017 2:46 AM by Martin Kouba

    Should an observer method's parameters show up in its bean's injection points?

    Laird Nelson Apprentice

      Playing around with portable extensions and such.


      If I get all the beans the container knows about (in AfterBeanDiscovery, so before validation) via beanManager.getBeans(Object.class, Any.Literal.INSTANCE), and then call getInjectionPoints() on each one, should I get "implicit" injection points as well?


      For example, I have a bean that @Observes @Initialized(ApplicationScoped.class) Object event, and has another parameter in that observer method.  I am not seeing an injection point representing that parameter in the return value of getInjectionPoints() on my bean's Bean representation.


      That may be OK or by design; I just wasn't sure.  Section 10.4.2 (JSR 365: Contexts and Dependency Injection for Java 2.0) seems to indicate that all injection points should be returned.


      (Thanks as always for your responses; I know I ask a lot of questions!)

        • 1. Re: Should an observer method's parameters show up in its bean's injection points?
          Tomas Remes Expert

          Hi Laird,

          Yes I think you should get all injection points including injection points for producer, disposer and observer method. This could be a bug. I will try later today.

          • 2. Re: Should an observer method's parameters show up in its bean's injection points?
            Martin Kouba Master

            Hi guys,

            I don't think that Bean.getInjectionPoints() should return the injection points declared on observer, producer and disposer methods. First of all, Bean.getInjectionPoints() should only return injection points that do belong to a specific bean. A producer method itself defines a bean, so all the paremeter injection points of a producer should be returned from the Bean represented by this producer. As for disposer and observer methods - these have a special lifecycle. See for example:


            5.2.2. Unsatisfied and ambiguous dependencies:

            "The container must validate all injection points of all enabled beans, all observer methods and all disposer methods when the application is initialized to ensure that there are no unsatisfied or unresolvable ambiguous dependencies."

            6.5.7. Injectable reference validity:

            "A reference to a bean injected into a disposer method or observer method is only valid until the invocation of the method completes."

            6.4.2. Destruction of objects with scope @Dependent:

            "All @Dependent scoped contextual instances injected into method parameters of a disposer method or an observer method are destroyed when the invocation completes".