ExecutionStrategy ExecutionStrategy Class

The base class for IExecutionStrategy implementations.

Syntax

Declaration

public abstract class ExecutionStrategy : IExecutionStrategyPublic MustInherit Class ExecutionStrategy
    Implements IExecutionStrategy

Inheritance Hierarchy

  • System.Object
    System.Object
  • ExecutionStrategy
    ExecutionStrategy

Inherited Members

ToString(),
ToString(),
Equals(Object),
Equals(Object),
Equals(Object, Object),
Equals(Object, Object),
ReferenceEquals(Object, Object),
ReferenceEquals(Object, Object),
GetHashCode(),
GetHashCode(),
GetType(),
GetType(),
MemberwiseClone()
MemberwiseClone()

Constructors summary

Creates a new instance of ExecutionStrategy.

Fields summary

The default maximum time delay between retries, must be nonnegative.

The default number of retry attempts.

Properties summary

The context on which the operations will be invoked.

The list of exceptions that caused the operation to be retried so far.

The logger for this ExecutionStrategy.

The maximum number of retry attempts.

The maximum delay in milliseconds between retries.

A pseudo-random number generater that can be used to vary the delay between retries.

Indicates whether this IExecutionStrategy might retry the execution after a failure.

Indicates whether the strategy is suspended. The strategy is typically suspending while executing to avoid recursive execution from nested operations.

Methods summary

Executes the specified operation and returns the result.

Executes the specified asynchronous operation and returns the result.

Determines whether the operation should be retried and the delay before the next attempt.

Method called before the first operation execution

Method called before retrying the operation execution

Determines whether the specified exception represents a transient failure that can be compensated by a retry.

Recursively gets InnerException from exception as long as it's an exception created by Entity Framework and passes it to exceptionHandler

Constructors

  • ExecutionStrategy(ExecutionStrategyContext, Int32, TimeSpan)
    ExecutionStrategy(ExecutionStrategyContext, Int32, TimeSpan)

    Creates a new instance of ExecutionStrategy.

    protected ExecutionStrategy(ExecutionStrategyContext context, int maxRetryCount, TimeSpan maxRetryDelay)Protected Sub New(context As ExecutionStrategyContext, maxRetryCount As Integer, maxRetryDelay As TimeSpan)

    Parameters

    • context

      The required dependencies.

    • maxRetryCount
      System.Int32
      System.Int32

      The maximum number of retry attempts.

    • maxRetryDelay
      System.TimeSpan
      System.TimeSpan

      The maximum delay in milliseconds between retries.

Fields

  • DefaultMaxDelay
    DefaultMaxDelay

    The default maximum time delay between retries, must be nonnegative.

    protected static readonly TimeSpan DefaultMaxDelayProtected Shared ReadOnly DefaultMaxDelay As TimeSpan
  • DefaultMaxRetryCount
    DefaultMaxRetryCount

    The default number of retry attempts.

    protected static readonly int DefaultMaxRetryCountProtected Shared ReadOnly DefaultMaxRetryCount As Integer

Properties

  • Context
    Context

    The context on which the operations will be invoked.

    protected virtual DbContext Context { get; }Protected Overridable ReadOnly Property Context As DbContext

    Property Value

  • ExceptionsEncountered
    ExceptionsEncountered

    The list of exceptions that caused the operation to be retried so far.

    protected virtual List<Exception> ExceptionsEncountered { get; }Protected Overridable ReadOnly Property ExceptionsEncountered As List(Of Exception)

    Property Value

    • System.Collections.Generic.List<T><System.Exception>
      System.Collections.Generic.List<T>(Of System.Exception)
  • Logger
    Logger

    The logger for this ExecutionStrategy.

    protected virtual ILogger<IExecutionStrategy> Logger { get; }Protected Overridable ReadOnly Property Logger As ILogger(Of IExecutionStrategy)

    Property Value

  • MaxRetryCount
    MaxRetryCount

    The maximum number of retry attempts.

    protected virtual int MaxRetryCount { get; }Protected Overridable ReadOnly Property MaxRetryCount As Integer

    Property Value

    • System.Int32
      System.Int32
  • MaxRetryDelay
    MaxRetryDelay

    The maximum delay in milliseconds between retries.

    protected virtual TimeSpan MaxRetryDelay { get; }Protected Overridable ReadOnly Property MaxRetryDelay As TimeSpan

    Property Value

    • System.TimeSpan
      System.TimeSpan
  • Random
    Random

    A pseudo-random number generater that can be used to vary the delay between retries.

    protected virtual Random Random { get; }Protected Overridable ReadOnly Property Random As Random

    Property Value

    • System.Random
      System.Random
  • RetriesOnFailure
    RetriesOnFailure

    Indicates whether this IExecutionStrategy might retry the execution after a failure.

    public virtual bool RetriesOnFailure { get; }Public Overridable ReadOnly Property RetriesOnFailure As Boolean

    Property Value

    • System.Boolean
      System.Boolean
  • Suspended
    Suspended

    Indicates whether the strategy is suspended. The strategy is typically suspending while executing to avoid recursive execution from nested operations.

    protected static bool Suspended { get; set; }Protected Shared Property Suspended As Boolean

    Property Value

    • System.Boolean
      System.Boolean

Methods

  • Execute<TState, TResult>(Func<TState, TResult>, TState)
    Execute(Of TState, TResult)(Func(Of TState, TResult), TState)

    Executes the specified operation and returns the result.

    public virtual TResult Execute<TState, TResult>(Func<TState, TResult> operation, TState state)Public Overridable Function Execute(Of TState, TResult)(operation As Func(Of TState, TResult), state As TState) As TResult

    Parameters

    • operation
      System.Func<T, TResult><TState, TResult>
      System.Func<T, TResult>(Of TState, TResult)

      A delegate representing an executable operation that returns the result of type TResult.

    • state
      TState
      TState

      The state that will be passed to the operation.

    Returns

    • TResult
      TResult

      The result from the operation.

  • ExecuteAsync<TState, TResult>(Func<TState, CancellationToken, Task<TResult>>, TState, CancellationToken)
    ExecuteAsync(Of TState, TResult)(Func(Of TState, CancellationToken, Task(Of TResult)), TState, CancellationToken)

    Executes the specified asynchronous operation and returns the result.

    public virtual Task<TResult> ExecuteAsync<TState, TResult>(Func<TState, CancellationToken, Task<TResult>> operation, TState state, CancellationToken cancellationToken = null)Public Overridable Function ExecuteAsync(Of TState, TResult)(operation As Func(Of TState, CancellationToken, Task(Of TResult)), state As TState, cancellationToken As CancellationToken = Nothing) As Task(Of TResult)

    Parameters

    • operation
      System.Func<T1, T2, TResult><TState, System.Threading.CancellationToken, System.Threading.Tasks.Task<TResult><TResult>>
      System.Func<T1, T2, TResult>(Of TState, System.Threading.CancellationToken, System.Threading.Tasks.Task<TResult>(Of TResult))

      A function that returns a started task of type TResult.

    • state
      TState
      TState

      The state that will be passed to the operation.

    • cancellationToken
      System.Threading.CancellationToken
      System.Threading.CancellationToken

      A cancellation token used to cancel the retry operation, but not operations that are already in flight or that already completed successfully.

    Returns

    • System.Threading.Tasks.Task<TResult><TResult>
      System.Threading.Tasks.Task<TResult>(Of 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.

  • GetNextDelay(Exception)
    GetNextDelay(Exception)

    Determines whether the operation should be retried and the delay before the next attempt.

    protected virtual TimeSpan? GetNextDelay(Exception lastException)Protected Overridable Function GetNextDelay(lastException As Exception) As TimeSpan?

    Parameters

    • lastException
      System.Exception
      System.Exception

      The exception thrown during the last execution attempt.

    Returns

    • System.Nullable<T><System.TimeSpan>
      System.Nullable<T>(Of System.TimeSpan)

      Returns the delay indicating how long to wait for before the next execution attempt if the operation should be retried; null otherwise

  • OnFirstExecution()
    OnFirstExecution()

    Method called before the first operation execution

    protected virtual void OnFirstExecution()Protected Overridable Sub OnFirstExecution
  • OnRetry()
    OnRetry()

    Method called before retrying the operation execution

    protected virtual void OnRetry()Protected Overridable Sub OnRetry
  • ShouldRetryOn(Exception)
    ShouldRetryOn(Exception)

    Determines whether the specified exception represents a transient failure that can be compensated by a retry.

    protected abstract bool ShouldRetryOn(Exception exception)Protected MustOverride Function ShouldRetryOn(exception As Exception) As Boolean

    Parameters

    • exception
      System.Exception
      System.Exception

      The exception object to be verified.

    Returns

    • System.Boolean
      System.Boolean

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

  • UnwrapAndHandleException<T>(Exception, Func<Exception, T>)
    UnwrapAndHandleException(Of T)(Exception, Func(Of Exception, T))

    Recursively gets InnerException from exception as long as it's an exception created by Entity Framework and passes it to exceptionHandler

    public static T UnwrapAndHandleException<T>(Exception exception, Func<Exception, T> exceptionHandler)Public Shared Function UnwrapAndHandleException(Of T)(exception As Exception, exceptionHandler As Func(Of Exception, T)) As T

    Parameters

    • exception
      System.Exception
      System.Exception

      The exception to be unwrapped.

    • exceptionHandler
      System.Func<T, TResult><System.Exception, T>
      System.Func<T, TResult>(Of System.Exception, T)

      A delegate that will be called with the unwrapped exception.

    Returns

    • T
      T

      The result from exceptionHandler.

Details

Assembly

Microsoft.EntityFrameworkCore.dll