Class NonRetryingExecutionStrategy
- Namespace
- Microsoft.EntityFrameworkCore.Storage
- Assembly
- Microsoft.EntityFrameworkCore.dll
An implementation of IExecutionStrategy that does no retries.
public sealed class NonRetryingExecutionStrategy : IExecutionStrategy
- Inheritance
-
NonRetryingExecutionStrategy
- Implements
- Inherited Members
- Extension Methods
Remarks
The service lifetime is Scoped. This means that each DbContext instance will use its own instance of this service. The implementation may depend on other services registered with any lifetime. The implementation does not need to be thread-safe.
See Connection resiliency and database retries for more information and examples.
Constructors
NonRetryingExecutionStrategy(DbContext)
Constructs a new NonRetryingExecutionStrategy with the given context.
public NonRetryingExecutionStrategy(DbContext context)
Parameters
context
DbContextThe context on which the operations will be invoked.
NonRetryingExecutionStrategy(ExecutionStrategyDependencies)
Constructs a new NonRetryingExecutionStrategy with the given service dependencies.
public NonRetryingExecutionStrategy(ExecutionStrategyDependencies dependencies)
Parameters
dependencies
ExecutionStrategyDependenciesDependencies for this execution strategy.
Properties
RetriesOnFailure
Always returns false, since the NonRetryingExecutionStrategy does not perform retries.
public bool RetriesOnFailure { get; }
Property Value
Remarks
See Connection resiliency and database retries for more information and examples.
Methods
ExecuteAsync<TState, TResult>(TState, Func<DbContext, TState, CancellationToken, Task<TResult>>, Func<DbContext, TState, CancellationToken, Task<ExecutionResult<TResult>>>?, CancellationToken)
Executes the specified asynchronous operation and returns the result.
public Task<TResult> ExecuteAsync<TState, TResult>(TState state, Func<DbContext, TState, CancellationToken, Task<TResult>> operation, Func<DbContext, TState, CancellationToken, Task<ExecutionResult<TResult>>>? verifySucceeded, CancellationToken cancellationToken = default)
Parameters
state
TStateThe state that will be passed to the operation.
operation
Func<DbContext, TState, CancellationToken, Task<TResult>>A function that returns a started task of type
TResult
.verifySucceeded
Func<DbContext, TState, CancellationToken, Task<ExecutionResult<TResult>>>A delegate that tests whether the operation succeeded even though an exception was thrown.
cancellationToken
CancellationTokenA cancellation token used to cancel the retry operation, but not operations that are already in flight or that already completed successfully.
Returns
- Task<TResult>
A task that will run to completion if the original task completes successfully (either the first time or after retrying transient failures). If the task fails with a non-transient error or the retry limit is reached, the returned task will become faulted and the exception must be observed.
Type Parameters
TState
The type of the state.
TResult
The result type of the Task<TResult> returned by
operation
.
Remarks
See Connection resiliency and database retries for more information and examples.
Exceptions
- RetryLimitExceededException
The operation has not succeeded after the configured number of retries.
- OperationCanceledException
If the CancellationToken is canceled.
Execute<TState, TResult>(TState, Func<DbContext, TState, TResult>, Func<DbContext, TState, ExecutionResult<TResult>>?)
Executes the specified operation and returns the result.
public TResult Execute<TState, TResult>(TState state, Func<DbContext, TState, TResult> operation, Func<DbContext, TState, ExecutionResult<TResult>>? verifySucceeded)
Parameters
state
TStateThe state that will be passed to the operation.
operation
Func<DbContext, TState, TResult>A delegate representing an executable operation that returns the result of type
TResult
.verifySucceeded
Func<DbContext, TState, ExecutionResult<TResult>>A delegate that tests whether the operation succeeded even though an exception was thrown.
Returns
- TResult
The result from the operation.
Type Parameters
TState
The type of the state.
TResult
The return type of
operation
.
Remarks
See Connection resiliency and database retries for more information and examples.
Exceptions
- RetryLimitExceededException
The operation has not succeeded after the configured number of retries.