2 Replies Latest reply on Dec 15, 2013 12:28 PM by jdestef

    Question on Instance and Destroy usage

    jdestef

      Hi,

       

      I have a quick question about using instance and destroy. I have an app with observer methods in a classes which I use an injected Instance class to create (@Inject private Instance<ClassName> instanceFactory). When I switch pages through Errai Navigation the @PreDestoy methods of the created instances are not called. Also, the observer methods of the constructed class appear to still be receiving CDI events. It appears that the physical representation of the view widget (Elements etc..) are destroyed when I navigate but the logical (Templated class, widget) is not. I can get around this by specifically using a Destroy<ClassName> injected variable to destroy the created object before leaving the primary view page. Just confirming that this is the right approach for instances created with the Instance class?

       

       

      Thanks

        • 1. Re: Question on Instance and Destroy usage
          csa

          Hi John,

           

          Yes, using Instance<T>/Disposer<T> for creating/destroying beans manually is the right approach here to make sure your observers are unsubscribed and all the lifecycle methods get called.

           

          Errai could do this automatically when we introduce additional scopes (e.g. a page scope). This is on our road map. If you have suggestions/ideas please let us know.

           

          Cheers,

          Christian

          • 2. Re: Question on Instance and Destroy usage
            jdestef

            Hi Christian,

             

            Even with the ListWidget I think there are still many occasions where using Instance as a factory is useful. In the app I'm working on I have page annotated classes with injected components. In some of the components I'm using Instance to create additional widgets of the same type to add to different parts of the page. It would be great if if there was a context for page that would clean up all of the created objects within this scenario.

             

            Thanks