Class NpgsqlRetryingExecutionStrategy
- Namespace
- Npgsql.EntityFrameworkCore.PostgreSQL
- Assembly
- Npgsql.EntityFrameworkCore.PostgreSQL.dll
An IExecutionStrategy implementation for retrying failed executions on PostgreSQL.
public class NpgsqlRetryingExecutionStrategy : ExecutionStrategy, IExecutionStrategy
- Inheritance
-
NpgsqlRetryingExecutionStrategy
- Implements
- Inherited Members
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
NpgsqlRetryingExecutionStrategy(DbContext)
Creates a new instance of NpgsqlRetryingExecutionStrategy.
public NpgsqlRetryingExecutionStrategy(DbContext context)
Parameters
context
DbContextThe context on which the operations will be invoked.
Remarks
The default retry limit is 6, which means that the total amount of time spent before failing is about a minute.
NpgsqlRetryingExecutionStrategy(DbContext, int)
Creates a new instance of NpgsqlRetryingExecutionStrategy.
public NpgsqlRetryingExecutionStrategy(DbContext context, int maxRetryCount)
Parameters
context
DbContextThe context on which the operations will be invoked.
maxRetryCount
intThe maximum number of retry attempts.
NpgsqlRetryingExecutionStrategy(DbContext, int, TimeSpan, ICollection<string>?)
Creates a new instance of NpgsqlRetryingExecutionStrategy.
public NpgsqlRetryingExecutionStrategy(DbContext context, int maxRetryCount, TimeSpan maxRetryDelay, ICollection<string>? errorCodesToAdd)
Parameters
context
DbContextThe context on which the operations will be invoked.
maxRetryCount
intThe maximum number of retry attempts.
maxRetryDelay
TimeSpanThe maximum delay between retries.
errorCodesToAdd
ICollection<string>Additional error codes that should be considered transient.
NpgsqlRetryingExecutionStrategy(ExecutionStrategyDependencies)
Creates a new instance of NpgsqlRetryingExecutionStrategy.
public NpgsqlRetryingExecutionStrategy(ExecutionStrategyDependencies dependencies)
Parameters
dependencies
ExecutionStrategyDependenciesParameter object containing service dependencies.
NpgsqlRetryingExecutionStrategy(ExecutionStrategyDependencies, ICollection<string>?)
Creates a new instance of NpgsqlRetryingExecutionStrategy.
public NpgsqlRetryingExecutionStrategy(ExecutionStrategyDependencies dependencies, ICollection<string>? errorCodesToAdd)
Parameters
dependencies
ExecutionStrategyDependenciesParameter object containing service dependencies.
errorCodesToAdd
ICollection<string>Additional error codes that should be considered transient.
NpgsqlRetryingExecutionStrategy(ExecutionStrategyDependencies, int)
Creates a new instance of NpgsqlRetryingExecutionStrategy.
public NpgsqlRetryingExecutionStrategy(ExecutionStrategyDependencies dependencies, int maxRetryCount)
Parameters
dependencies
ExecutionStrategyDependenciesParameter object containing service dependencies.
maxRetryCount
intThe maximum number of retry attempts.
NpgsqlRetryingExecutionStrategy(ExecutionStrategyDependencies, int, TimeSpan, ICollection<string>?)
Creates a new instance of NpgsqlRetryingExecutionStrategy.
public NpgsqlRetryingExecutionStrategy(ExecutionStrategyDependencies dependencies, int maxRetryCount, TimeSpan maxRetryDelay, ICollection<string>? errorCodesToAdd)
Parameters
dependencies
ExecutionStrategyDependenciesParameter object containing service dependencies.
maxRetryCount
intThe maximum number of retry attempts.
maxRetryDelay
TimeSpanThe maximum delay between retries.
errorCodesToAdd
ICollection<string>Additional SQL error numbers that should be considered transient.
Methods
ShouldRetryOn(Exception?)
Determines whether the specified exception represents a transient failure that can be compensated by a retry.
protected override bool ShouldRetryOn(Exception? exception)
Parameters
exception
ExceptionThe exception object to be verified.
Returns
Remarks
See Connection resiliency and database retries for more information and examples.