Ensure the main realm context is closed when the factory is disposed

This commit is contained in:
Dean Herbert 2021-01-15 14:26:06 +09:00
parent 693602513e
commit 3e366b1f15
2 changed files with 12 additions and 0 deletions

View File

@ -83,6 +83,7 @@ namespace osu.Game.Tests.Database
[TearDown] [TearDown]
public void TearDown() public void TearDown()
{ {
realmContextFactory.Dispose();
storage.DeleteDirectory(string.Empty); storage.DeleteDirectory(string.Empty);
} }

View File

@ -36,6 +36,9 @@ namespace osu.Game.Database
{ {
get get
{ {
if (IsDisposed)
throw new InvalidOperationException($"Attempted to access {nameof(Context)} on a disposed context factory");
if (context == null) if (context == null)
{ {
context = createContext(); context = createContext();
@ -92,6 +95,14 @@ namespace osu.Game.Database
{ {
} }
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
context?.Dispose();
context = null;
}
/// <summary> /// <summary>
/// A transaction used for making changes to realm data. /// A transaction used for making changes to realm data.
/// </summary> /// </summary>