# 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
  object
  ExecutionStrategy
  NpgsqlRetryingExecutionStrategy

Implements
  IExecutionStrategy

Inherited Members
  ExecutionStrategy.DefaultMaxRetryCount
  ExecutionStrategy.DefaultMaxDelay
  ExecutionStrategy.Execute<TState, TResult>(TState, Func<DbContext, TState, TResult>, Func<DbContext, TState, ExecutionResult<TResult>>)
  ExecutionStrategy.ExecuteAsync<TState, TResult>(TState, Func<DbContext, TState, CancellationToken, Task<TResult>>, Func<DbContext, TState, CancellationToken, Task<ExecutionResult<TResult>>>, CancellationToken)
  ExecutionStrategy.OnFirstExecution()
  ExecutionStrategy.OnRetry()
  ExecutionStrategy.GetNextDelay(Exception)
  ExecutionStrategy.ShouldVerifySuccessOn(Exception)
  ExecutionStrategy.CallOnWrappedException<TResult>(Exception, Func<Exception, TResult>)
  ExecutionStrategy.ExceptionsEncountered
  ExecutionStrategy.Random
  ExecutionStrategy.MaxRetryCount
  ExecutionStrategy.MaxRetryDelay
  ExecutionStrategy.Dependencies
  ExecutionStrategy.Current
  ExecutionStrategy.RetriesOnFailure
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

## 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` DbContext

  The 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` DbContext

  The context on which the operations will be invoked.

`maxRetryCount` int

  The 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` DbContext

  The context on which the operations will be invoked.

`maxRetryCount` int

  The maximum number of retry attempts.

`maxRetryDelay` TimeSpan

  The 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` ExecutionStrategyDependencies

  Parameter object containing service dependencies.

### NpgsqlRetryingExecutionStrategy(ExecutionStrategyDependencies, ICollection<string>?)

Creates a new instance of NpgsqlRetryingExecutionStrategy.

    public NpgsqlRetryingExecutionStrategy(ExecutionStrategyDependencies dependencies, ICollection<string>? errorCodesToAdd)

#### Parameters

`dependencies` ExecutionStrategyDependencies

  Parameter 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` ExecutionStrategyDependencies

  Parameter object containing service dependencies.

`maxRetryCount` int

  The 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` ExecutionStrategyDependencies

  Parameter object containing service dependencies.

`maxRetryCount` int

  The maximum number of retry attempts.

`maxRetryDelay` TimeSpan

  The 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` Exception

  The exception object to be verified.

#### Returns

bool

  true if the specified exception is considered as transient, otherwise false.

#### Remarks

See Connection resiliency and database retries for more information and examples.