Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions src/EFCore.PG/Storage/Internal/NpgsqlDataSourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,17 @@ enumDefinition.StoreTypeSchema is null
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public void Dispose()
/// <param name="disposing"><see langword="true"/> when disposed from Dispose(), false when called from DisposeAsync().</param>
protected virtual void Dispose(bool disposing)
{
if (Interlocked.CompareExchange(ref _isDisposed, 1, 0) == 0)
if (disposing)
{
foreach (var dataSource in _dataSources.Values)
if (Interlocked.CompareExchange(ref _isDisposed, 1, 0) == 0)
{
dataSource.Dispose();
foreach (var dataSource in _dataSources.Values)
{
dataSource.Dispose();
}
}
}
}
Expand All @@ -181,7 +185,19 @@ public void Dispose()
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public async ValueTask DisposeAsync()
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected virtual async ValueTask DisposeAsyncCore()
{
if (Interlocked.CompareExchange(ref _isDisposed, 1, 0) == 0)
{
Expand All @@ -191,4 +207,17 @@ public async ValueTask DisposeAsync()
}
}
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public async ValueTask DisposeAsync()
{
await DisposeAsyncCore().ConfigureAwait(false);
Dispose(disposing: false);
GC.SuppressFinalize(this);
}
}