-
1. Re: Multiple simultaneous instances of @Dependent classes
mbarkley May 20, 2016 9:57 AM (in response to vwjugow)Hi Victor,
Dependent beans should be destroyed when the beans they are injected into are destroyed. If your observer beans are injected into an Errai Navigation page they should be destroyed when you navigate away from the page (otherwise you've found a bug). If you're creating your own instances of beans with the bean manager or an Instance<T> then you need to destroy those beans yourself when you're done with them, otherwise those beans and any dependent beans injected into them will continue being in service.
-
2. Re: Multiple simultaneous instances of @Dependent classes
vwjugow May 20, 2016 11:03 AM (in response to mbarkley)Thanks mbarkley
We do have some Instance<T> but I didn't know what you mentioned. I will try to remove those but it will take time. I'll try to get back to this post when that happens.
But on the navigation topic you mentioned, with 'Errai Navigation page' you mean a Class annotated with @Page? We have those pages also annotated with @ApplicationScope, is that okay? not okay? is it meaningless?
-
3. Re: Multiple simultaneous instances of @Dependent classes
mbarkley May 20, 2016 11:20 AM (in response to vwjugow)Hi Victor,
No need to remove the Instance<T>, just make sure you use Instance#destroy for any dependent beans you make when you're done with them.
By Errai Navigation page I meant an @Page. Making a page @ApplicationScoped isn't wrong per se, but it means that your page will still exist after you navigate away from it. If the app scoped page has dependent instances injected into it, those instances will also still exist and observe events.
My personal recommendation is that widgets/views should almost always be dependent, and @ApplicationScoped should be saved for stateful services that views/presenters can query when constructed. But that's just an opinion so take it as you will.