ViewModel in my MVVM Light application has some resourse, that must be dispose when application is closing. I have CleanUp method in ViewModelLocator to do it. Where is right place in my application to call CleanUp method.
public class ViewModelLocator
{
/// <summary>
/// Initializes a new instance of the ViewModelLocator class.
/// </summary>
public ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
SimpleIoc.Default.Register<MainViewModel>();
}
public MainViewModel Main
{
get
{
return SimpleIoc.Default.GetInstance<MainViewModel>();
}
}
public static void Cleanup()
{
var main=SimpleIoc.Default.GetInstance<MainViewModel>();
main.Dispose();
}
}
public class MainViewModel:ViewModelBase, IDisposable
{
public void Dispose()
{
disposableResoure.Dispose();
}
}