2 Replies Latest reply on Jun 27, 2011 3:25 PM by haye

    How to destroy an object that was created via @Produces ?

    craig

      I have sessionContext bean that observes when a user logs in and then produces this user when other bean request injection.


      The user produced is session scope.


      Is there any way of destroying this so that when I swap to a new user (same observer method called) this new user is then produced?


      Thanks


      Craig

        • 1. Re: How to destroy an object that was created via @Produces ?
          haye

          If the user is session scoped, then the container will destroy it when the session is either ended (logout) or timed out.If you want to take control of the destruction then you can create a disposer method in the same class as the producer. The reference documentation has http://docs.jboss.org/weld/reference/latest/en-US/html/producermethods.html.


          When an injection point requires a user object in a different session (new browser window or after logout/login) the producer method will be called. The returned user will be the one used throughout the rest of the session for all injection points.


          If you want a new user object within the same session, annotate the injection point with @New and you will get a new dependent-scoped user object.



          • 2. Re: How to destroy an object that was created via @Produces ?
            haye

            Zak S wrote on Jun 27, 2011 15:23:


            If the user is session scoped, then the container will destroy it when the session is either ended (logout) or timed out.If you want to take control of the destruction then you can create a disposer method in the same class as the producer. The reference documentation has http://docs.jboss.org/weld/reference/latest/en-US/html/producermethods.html.

            When an injection point requires a user object in a different session (new browser window or after logout/login) the producer method will be called. The returned user will be the one used throughout the rest of the session for all injection points.

            If you want a new user object within the same session, annotate the injection point with @New and you will get a new dependent-scoped user object.





            Oops. The link should say The reference documentation has a section on producer methods under the Producers chapter and point to http://docs.jboss.org/weld/reference/latest/en-US/html/producermethods.html