1 Reply Latest reply on Mar 4, 2011 6:03 AM by nimo stephan

    Producer and parent bean.

    nimo stephan Master

      According to weld-spec:



      A producer method does not inherit the scope of the bean that declares the method. There are two different beans here: the producer method, and the bean which declares it. The scope of the producer method determines how often the method will be called, and the lifecycle of the objects returned by the method. The scope of the bean that declares the producer method determines the lifecycle of the object upon which the producer method is invoked.

      Especially this:



      The scope of the bean that declares the producer method determines the lifecycle of the object upon which the producer method is invoked.

      I have this question:


      Does this mean, that I cannot invoke my producer which is sessionscoped and lies in a bean which is request scoped, if the bean is not requested? If a Producer method is named, I can invoke it from elsewhere so it is totally independent of its bean in which the producer lies. Am I right?

        • 1. Re: Producer and parent bean.
          nimo stephan Master

          The strange thing is:


          @PostConstruct of a (dependent) bean in which the session scoped and named producer method lies, is called twice instead of once, when injecting the bean and its producer method separately. Is that a bug? So the bean is created twice only because I inject the producer method in which the bean lies - but the bean has another lifecycle and scope of the producer method, wo why is a instance of a bean also created?