New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Call Dispose in RegionNavigationService if View/View Model implements IDisposable #7
Comments
Thanks for the suggestion. We will have to research the best way to handle that scenario as it is a common need. We may provide a mechanism which allows you to hook into the process and clean up however you like which won't require the use of IDispose. This can be achieve with a simple RegionBehavior if you need this functionality now. |
Thank you for suggesting RegionBehavior. Here is my
|
I think the RegionBehavior is probably the best way with current code base because I don't think the Region/RegionManager currently track whether a contained view was provided as an instance (via Region.Add or RegionManager.AddToRegion or RegisterViewWtihRegion (factory method version) or whether RegionManager created it (through RequestNavigate or RegisterViewWithRegion - type variant). If we added tracking of that, then it seems it would make sense to check for IDisposable and call it if the View/ViewModel had IRegionMemberLifetime.KeepAlive=false. Possibly a simpler and more straightforward way would be to add another property to IRegionMemberLifetime.DisposeOnDeactivate and do it based on that? I do think this would be a very useful extension for us to add. |
Yikes to a behavior-based boolean, IMO. It is simpler/straight-forward but leads to booleanitis. If we can get away with checking for IDisposable when !ShouldKeepAlive(), that would be my preference/vote if it is possible. |
@Michael-DST Do you mean something like this? https://compositewpf.codeplex.com/SourceControl/network/forks/jalalx/LightPrism/changeset/aa8902f73326aa3fde7b0375cefe6ce14bda3a60 |
Yes! :) |
I forget to call |
The problem as I mentioned is that if the view was provided to the region by the module code, then the module may still hold a reference to the view itself and is therefore the lifetime owner of that object and it would be inappropriate for the region manager to dispose it. |
Ahhhh... Team Brian has better perspective on this matter, of course. :) I just hate seeing booleans used where something stronger can be utilized, but that's me. If that's the best answer here, then that's the best answer. 👍 |
I'm sure once we dig into this feature and get more information about the internals, we will find a solution that will work for everyone. |
We have decided that using a custom region behavior is the solution for this scenario. |
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. |
I have checked source code of RegionNavigationService.cs, and It seems there is no such mechanism. I think it would be a good idea to dispose view/view model when
IRegionMemberLifetime.KeepAlive
isfalse
. This is a good practice to put all clean ups inDispose
method such as unregistering staticCompositeCommand
s or disposingDbContext
instance in view model (yes, I'm not a fan of Repository pattern :P).The text was updated successfully, but these errors were encountered: