diff --git a/src/EFCore.Cosmos/Storage/Internal/CosmosTransactionManager.cs b/src/EFCore.Cosmos/Storage/Internal/CosmosTransactionManager.cs index 06986ea1ba3..aef46426aad 100644 --- a/src/EFCore.Cosmos/Storage/Internal/CosmosTransactionManager.cs +++ b/src/EFCore.Cosmos/Storage/Internal/CosmosTransactionManager.cs @@ -91,7 +91,8 @@ public virtual void ResetState() /// 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 virtual ValueTask ResetStateAsync() + /// A to observe while waiting for the task to complete. + public virtual Task ResetStateAsync(CancellationToken cancellationToken = default) { ResetState(); diff --git a/src/EFCore.InMemory/Storage/Internal/InMemoryTransactionManager.cs b/src/EFCore.InMemory/Storage/Internal/InMemoryTransactionManager.cs index 1a031a9ee1c..e8d13937caa 100644 --- a/src/EFCore.InMemory/Storage/Internal/InMemoryTransactionManager.cs +++ b/src/EFCore.InMemory/Storage/Internal/InMemoryTransactionManager.cs @@ -133,7 +133,8 @@ public virtual void ResetState() /// 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 virtual ValueTask ResetStateAsync() + /// A to observe while waiting for the task to complete. + public virtual Task ResetStateAsync(CancellationToken cancellationToken = default) { ResetState(); diff --git a/src/EFCore.Relational/Storage/RelationalConnection.cs b/src/EFCore.Relational/Storage/RelationalConnection.cs index da9512bc862..1a216edc4e8 100644 --- a/src/EFCore.Relational/Storage/RelationalConnection.cs +++ b/src/EFCore.Relational/Storage/RelationalConnection.cs @@ -726,7 +726,7 @@ private bool ShouldClose() void IResettableService.ResetState() => Dispose(); - ValueTask IResettableService.ResetStateAsync() => DisposeAsync(); + Task IResettableService.ResetStateAsync(CancellationToken cancellationToken) => DisposeAsync().AsTask(); /// /// Gets a semaphore used to serialize access to this connection. diff --git a/src/EFCore/ChangeTracking/ChangeTracker.cs b/src/EFCore/ChangeTracking/ChangeTracker.cs index bc48253f614..717ffecd9e1 100644 --- a/src/EFCore/ChangeTracking/ChangeTracker.cs +++ b/src/EFCore/ChangeTracking/ChangeTracker.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Linq; +using System.Threading; using System.Threading.Tasks; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; @@ -380,7 +381,7 @@ void IResettableService.ResetState() DeleteOrphansTiming = CascadeTiming.Immediate; } - ValueTask IResettableService.ResetStateAsync() + Task IResettableService.ResetStateAsync(CancellationToken cancellationToken) { ((IResettableService)this).ResetState(); diff --git a/src/EFCore/ChangeTracking/Internal/StateManager.cs b/src/EFCore/ChangeTracking/Internal/StateManager.cs index 0bf240396d6..fdf1d284ff5 100644 --- a/src/EFCore/ChangeTracking/Internal/StateManager.cs +++ b/src/EFCore/ChangeTracking/Internal/StateManager.cs @@ -709,7 +709,8 @@ public virtual void ResetState() /// 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 virtual ValueTask ResetStateAsync() + /// A to observe while waiting for the task to complete. + public virtual Task ResetStateAsync(CancellationToken cancellationToken = default) { ResetState(); diff --git a/src/EFCore/DbContext.cs b/src/EFCore/DbContext.cs index cfebe0f4c5c..eaabafe678b 100644 --- a/src/EFCore/DbContext.cs +++ b/src/EFCore/DbContext.cs @@ -661,7 +661,7 @@ void IDbContextPoolable.Resurrect(DbContextPoolConfigurationSnapshot configurati /// 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. /// - void IDbContextPoolable.ResetState() + void IResettableService.ResetState() { foreach (var service in GetResettableServices()) { @@ -677,11 +677,12 @@ void IDbContextPoolable.ResetState() /// 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. /// - async ValueTask IDbContextPoolable.ResetStateAsync() + /// A to observe while waiting for the task to complete. + async Task IResettableService.ResetStateAsync(CancellationToken cancellationToken) { foreach (var service in GetResettableServices()) { - await service.ResetStateAsync(); + await service.ResetStateAsync(cancellationToken); } _disposed = true; diff --git a/src/EFCore/Infrastructure/IResettableService.cs b/src/EFCore/Infrastructure/IResettableService.cs index 940460945ec..2dfeeb496b9 100644 --- a/src/EFCore/Infrastructure/IResettableService.cs +++ b/src/EFCore/Infrastructure/IResettableService.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; @@ -33,7 +34,8 @@ public interface IResettableService /// /// Resets the service so that it can be used from the pool. /// + /// A to observe while waiting for the task to complete. /// A task that represents the asynchronous operation. - ValueTask ResetStateAsync(); + Task ResetStateAsync(CancellationToken cancellationToken = default); } } diff --git a/src/EFCore/Internal/IDbContextPoolable.cs b/src/EFCore/Internal/IDbContextPoolable.cs index d7e281c28ce..766522c05e4 100644 --- a/src/EFCore/Internal/IDbContextPoolable.cs +++ b/src/EFCore/Internal/IDbContextPoolable.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Threading.Tasks; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Infrastructure; namespace Microsoft.EntityFrameworkCore.Internal { @@ -12,7 +12,7 @@ namespace Microsoft.EntityFrameworkCore.Internal /// 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 interface IDbContextPoolable + public interface IDbContextPoolable : IResettableService { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -37,21 +37,5 @@ public interface IDbContextPoolable /// doing so can result in application failures when updating to a new Entity Framework Core release. /// void Resurrect([NotNull] DbContextPoolConfigurationSnapshot configurationSnapshot); - - /// - /// 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. - /// - void ResetState(); - - /// - /// 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. - /// - ValueTask ResetStateAsync(); } } diff --git a/src/EFCore/Internal/InternalDbSet.cs b/src/EFCore/Internal/InternalDbSet.cs index 604bd8944a0..81319fa190d 100644 --- a/src/EFCore/Internal/InternalDbSet.cs +++ b/src/EFCore/Internal/InternalDbSet.cs @@ -391,7 +391,8 @@ IServiceProvider IInfrastructure.Instance /// 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. /// - ValueTask IResettableService.ResetStateAsync() + /// A to observe while waiting for the task to complete. + Task IResettableService.ResetStateAsync(CancellationToken cancellationToken) { ((IResettableService)this).ResetState(); diff --git a/test/EFCore.Relational.Tests/RelationalDatabaseFacadeExtensionsTest.cs b/test/EFCore.Relational.Tests/RelationalDatabaseFacadeExtensionsTest.cs index 963d744a969..d5986794afc 100644 --- a/test/EFCore.Relational.Tests/RelationalDatabaseFacadeExtensionsTest.cs +++ b/test/EFCore.Relational.Tests/RelationalDatabaseFacadeExtensionsTest.cs @@ -153,7 +153,7 @@ public void ResetState() { } - public ValueTask ResetStateAsync() => default; + public Task ResetStateAsync(CancellationToken cancellationToken = default) => Task.CompletedTask; public IDbContextTransaction BeginTransaction() { diff --git a/test/EFCore.Relational.Tests/RelationalEventIdTest.cs b/test/EFCore.Relational.Tests/RelationalEventIdTest.cs index 61c7f200068..7eb752ed91d 100644 --- a/test/EFCore.Relational.Tests/RelationalEventIdTest.cs +++ b/test/EFCore.Relational.Tests/RelationalEventIdTest.cs @@ -167,7 +167,7 @@ public Task OpenAsync(CancellationToken cancellationToken, bool errorsExpe throw new NotImplementedException(); public void ResetState() => throw new NotImplementedException(); - public ValueTask ResetStateAsync() => throw new NotImplementedException(); + public Task ResetStateAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException(); public void RollbackTransaction() => throw new NotImplementedException(); public IDbContextTransaction UseTransaction(DbTransaction transaction) => throw new NotImplementedException(); diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/BadDataSqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/BadDataSqliteTest.cs index 1eba7b0a3a1..8cc596175f0 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/BadDataSqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/BadDataSqliteTest.cs @@ -354,7 +354,7 @@ public void ResetState() { } - public ValueTask ResetStateAsync() => default; + public Task ResetStateAsync(CancellationToken cancellationToken = default) => Task.CompletedTask; public IDbContextTransaction BeginTransaction() => throw new NotImplementedException(); diff --git a/test/EFCore.Tests/DatabaseFacadeTest.cs b/test/EFCore.Tests/DatabaseFacadeTest.cs index 5bb6cefffa5..c72a88b9bd6 100644 --- a/test/EFCore.Tests/DatabaseFacadeTest.cs +++ b/test/EFCore.Tests/DatabaseFacadeTest.cs @@ -171,7 +171,7 @@ public Task BeginTransactionAsync(CancellationToken cance public void EnlistTransaction(Transaction transaction) => throw new NotImplementedException(); public void ResetState() => throw new NotImplementedException(); - public ValueTask ResetStateAsync() => throw new NotImplementedException(); + public Task ResetStateAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException(); } private class FakeDbContextTransaction : IDbContextTransaction diff --git a/test/EFCore.Tests/Infrastructure/EntityFrameworkServicesBuilderTest.cs b/test/EFCore.Tests/Infrastructure/EntityFrameworkServicesBuilderTest.cs index 876fe9f81ef..adab826b9e7 100644 --- a/test/EFCore.Tests/Infrastructure/EntityFrameworkServicesBuilderTest.cs +++ b/test/EFCore.Tests/Infrastructure/EntityFrameworkServicesBuilderTest.cs @@ -345,7 +345,7 @@ public void ResetState() { } - public ValueTask ResetStateAsync() => default; + public Task ResetStateAsync(CancellationToken cancellationToken = default) => Task.CompletedTask; } private static DbContext CreateContext(IServiceProvider serviceProvider) diff --git a/test/EFCore.Tests/TestUtilities/FakeStateManager.cs b/test/EFCore.Tests/TestUtilities/FakeStateManager.cs index b7ac88d130f..dd07e4f4e06 100644 --- a/test/EFCore.Tests/TestUtilities/FakeStateManager.cs +++ b/test/EFCore.Tests/TestUtilities/FakeStateManager.cs @@ -34,7 +34,7 @@ public void ResetState() { } - public ValueTask ResetStateAsync() => default; + public Task ResetStateAsync(CancellationToken cancellationToken = default) => Task.CompletedTask; public void Unsubscribe() {