Dispose the RootViewModel when Bootstrapper disposed

The Bootstrapper owns the RootViewModel, so this is the right thing
to do
This commit is contained in:
Antony Male 2016-01-08 11:47:37 +00:00
parent 97c841178f
commit 5d752f1fa9
3 changed files with 25 additions and 4 deletions

View File

@ -82,8 +82,9 @@ namespace Stylet
/// </summary>
public override void Dispose()
{
this.Container.Dispose();
// Dispose the container last
base.Dispose();
this.Container.Dispose();
}
}
}

View File

@ -147,6 +147,9 @@ namespace Stylet
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public virtual void Dispose() { }
public virtual void Dispose()
{
ScreenExtensions.TryDispose(this.RootViewModel);
}
}
}

View File

@ -9,7 +9,15 @@ namespace StyletUnitTests
[TestFixture, RequiresSTA]
public class BootstrapperBaseTests
{
private class RootViewModel { }
private class RootViewModel : IDisposable
{
public bool DisposeCalled;
public void Dispose()
{
this.DisposeCalled = true;
}
}
private class MyBootstrapperBase : BootstrapperBase
{
@ -29,9 +37,11 @@ namespace StyletUnitTests
get { return base.Application; }
}
public readonly RootViewModel MyRootViewModel = new BootstrapperBaseTests.RootViewModel();
protected override object RootViewModel
{
get { return new RootViewModel(); }
get { return this.MyRootViewModel; }
}
public bool GetInstanceCalled;
@ -136,5 +146,12 @@ namespace StyletUnitTests
this.bootstrapper.Start(new string[0]);
Assert.True(this.bootstrapper.OnStartCalled);
}
[Test]
public void DisposesRootViewModel()
{
this.bootstrapper.Dispose();
Assert.True(this.bootstrapper.MyRootViewModel.DisposeCalled);
}
}
}