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
contextDbContextThe 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
contextDbContextThe context on which the operations will be invoked.
maxRetryCountintThe 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
contextDbContextThe context on which the operations will be invoked.
maxRetryCountintThe maximum number of retry attempts.
maxRetryDelayTimeSpanThe maximum delay between retries.
errorCodesToAddICollection<string>Additional error codes that should be considered transient.
NpgsqlRetryingExecutionStrategy(ExecutionStrategyDependencies)
Creates a new instance of NpgsqlRetryingExecutionStrategy.
public NpgsqlRetryingExecutionStrategy(ExecutionStrategyDependencies dependencies)
Parameters
dependenciesExecutionStrategyDependenciesParameter object containing service dependencies.
NpgsqlRetryingExecutionStrategy(ExecutionStrategyDependencies, ICollection<string>?)
Creates a new instance of NpgsqlRetryingExecutionStrategy.
public NpgsqlRetryingExecutionStrategy(ExecutionStrategyDependencies dependencies, ICollection<string>? errorCodesToAdd)
Parameters
dependenciesExecutionStrategyDependenciesParameter object containing service dependencies.
errorCodesToAddICollection<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
dependenciesExecutionStrategyDependenciesParameter object containing service dependencies.
maxRetryCountintThe 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
dependenciesExecutionStrategyDependenciesParameter object containing service dependencies.
maxRetryCountintThe maximum number of retry attempts.
maxRetryDelayTimeSpanThe maximum delay between retries.
errorCodesToAddICollection<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
exceptionExceptionThe exception object to be verified.
Returns
Remarks
See Connection resiliency and database retries for more information and examples.