Looks like the interface IDestructible is only available in XF.
I'm looking for a way to unsubscribe from events of objects injected to the VM before the VM needs to get collected/disposed of in WPF.
Is there a different way to achieve this?
*Some event sources aren't IoC ruled and EventAggregator is not always a feasible solution.
Subscribe has an overload which has a predicate to control the subscription. Check IsActive on the predicate then it will not fire when view is not active.
Subscribe(action, ThreadOption.PublisherThread, false, payload=> IsActive);
Would still be nice to have IDestructible in WPF too, to give us a hint on VM tear-down.
You can write a custom region behavior to accomplish this in your app. This will most likely not be included in Prism as I cannot assume that when a view is removed from a region that it will not be reused again.
I've actually decided to include this. If someone is trying to reuse VM's after they have been removed from a Region, then it is the developers responsibility not to "clean them up" or even implement this interface.
Done!
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
I've actually decided to include this. If someone is trying to reuse VM's after they have been removed from a Region, then it is the developers responsibility not to "clean them up" or even implement this interface.