diff --git a/src/EFCore.PG/Storage/Internal/NpgsqlDataSourceManager.cs b/src/EFCore.PG/Storage/Internal/NpgsqlDataSourceManager.cs index bd67b7689..94718f27d 100644 --- a/src/EFCore.PG/Storage/Internal/NpgsqlDataSourceManager.cs +++ b/src/EFCore.PG/Storage/Internal/NpgsqlDataSourceManager.cs @@ -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. /// - public void Dispose() + /// when disposed from Dispose(), false when called from DisposeAsync(). + 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(); + } } } } @@ -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. /// - public async ValueTask DisposeAsync() + public void Dispose() + { + Dispose(disposing: true); + GC.SuppressFinalize(this); + } + + /// + /// 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. + /// + protected virtual async ValueTask DisposeAsyncCore() { if (Interlocked.CompareExchange(ref _isDisposed, 1, 0) == 0) { @@ -191,4 +207,17 @@ public async ValueTask DisposeAsync() } } } + + /// + /// 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. + /// + public async ValueTask DisposeAsync() + { + await DisposeAsyncCore().ConfigureAwait(false); + Dispose(disposing: false); + GC.SuppressFinalize(this); + } }