ViewModelBaseWithoutServices.Close() Doesn't Remove InterestedIn

Dec 14, 2011 at 6:14 AM

I think this is a bug in Catel 2.4 - Calling Close() on a ViewModel that is decorated with an IsInterestedAttribute doesn't seem to unsubscribe from change notifications on the "interested in" viewmodel type. 

Looking at the source code, ViewModelBaseWithoutServices.Close() calls UnregisterCommands() but doesn't do anything to remove the InterestedInAttribute. 

In fact, I see in ViewModelManager that there is a method, RemoveInterestedViewModelInstance whose summary states,

"...The <see cref="IViewModel"/> class will automatically unregister itself from the manager by using this method when decorated with the <see cref="InterestedInAttribute"/>."

However, right-clicking this method and choosing "Call Hierarchy" shows that all calls to this method are from ViewModelManagerTest.

Am I wrong in thinking that the Close() method should call ViewModelManager.RemoveInterestedViewModelInstance?

Coordinator
Dec 14, 2011 at 12:37 PM
Edited Dec 14, 2011 at 12:37 PM

In the Dispose of the ViewModelBaseWithoutService, it unsubscribes:

        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposeManagedResources"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected override void Dispose(bool disposeManagedResources)
        {
            if (disposeManagedResources)
            {
                ViewModelManager.UnregisterViewModelInstance(this);
            }

            base.Dispose(disposeManagedResources);
        }

But I agree this should be implement somewhere else (for example, the Close, and if the user fails to call that, the Dispose)

Dec 14, 2011 at 2:06 PM

Thanks, Geert.  For that matter, shouldn't the Close method call Dispose?

Coordinator
Dec 14, 2011 at 2:07 PM

No, a view model might be closed, but you still need to be able to access it. For example, think of a data window that is closed, but you are interested in the resulting view model. If it would be disposed already, it would be hard to get any data.

Dec 14, 2011 at 2:10 PM

Makes sense.  I guess the Close method should just unsubscribe from events, then.

Coordinator
Dec 14, 2011 at 2:12 PM

I will check this in tomorrow evening (tonight I have something else to do). I see you are getting very acquainted with Catel, good job :)

If you have any feature requests or whatsoever, just let me know!

Dec 14, 2011 at 2:16 PM

I am getting there, but you keep adding features faster than I can learn them! :)

You have done an amazing job with this framework.  I don't know how you find the time to develop it and be so responsive here.