mirror of https://github.com/AMT-Cheif/Stylet.git
Dispose the RootViewModel when Bootstrapper disposed
The Bootstrapper owns the RootViewModel, so this is the right thing to do
This commit is contained in:
parent
97c841178f
commit
5d752f1fa9
|
@ -82,8 +82,9 @@ namespace Stylet
|
|||
/// </summary>
|
||||
public override void Dispose()
|
||||
{
|
||||
this.Container.Dispose();
|
||||
// Dispose the container last
|
||||
base.Dispose();
|
||||
this.Container.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue