DmitryLegostaev.Polly.ActionRetry 1.0.0

dotnet add package DmitryLegostaev.Polly.ActionRetry --version 1.0.0
NuGet\Install-Package DmitryLegostaev.Polly.ActionRetry -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DmitryLegostaev.Polly.ActionRetry" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DmitryLegostaev.Polly.ActionRetry --version 1.0.0
#r "nuget: DmitryLegostaev.Polly.ActionRetry, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DmitryLegostaev.Polly.ActionRetry as a Cake Addin
#addin nuget:?package=DmitryLegostaev.Polly.ActionRetry&version=1.0.0

// Install DmitryLegostaev.Polly.ActionRetry as a Cake Tool
#tool nuget:?package=DmitryLegostaev.Polly.ActionRetry&version=1.0.0

DmitryLegostaev.Polly.ActionRetry

A small class library to provide Action Retry functionality using Polly v7 library.

Usage

Obtaining ActionRetry object instance

Explicitly create ActionRetry object

var actionRetrier = new ActionRetry();

or use a DI to obtain ActionRetry object.

(optional) Configuration of default RetryCount and BackOffDelay

You can configure default retry count and backoffdelay for ActionRetry object through its constructor. Defaults are 5/1s

var actionRetrier = new ActionRetry(20, TimeSpan.FromSeconds(2));

or set environment variables

Environment.SetEnvironmentVariable("ActionRetry__defaultRetryCount", 20.ToString());
Environment.SetEnvironmentVariable("ActionRetry__defaultBackOffDelay", TimeSpan.FromSeconds(2).ToString());

Configuration priority is: Constructor parameters → Environment variables → Pre-defined defaults (5/1s)

Actual usage

Each method require Action or Func to execute within its body. WaitForPredicateAndGetResult requires a predicate to be passed as argument in addition to Func.

// Do action with default amount of retries and default back off delay
actionRetrier.DoWithRetry(() => 2 + 2 == 4);

// Do action with default amount of retries and default back off delay and return action result
var actionResult = actionRetrier.DoWithRetry<T>(() => 2 + 2);

Each method could consume IWaitConfiguration object or RetryCount/BackOffDelay. If 2nd option is chosen but RetryCount or BackOffDelay is missing, then it will be obtained from ActionRetry defaults defined during ActionRetry object instantiation.

actionRetrier.DoWithRetry(() => 2 + 2 == 4,
    new ActionRetryConfiguration(20, TimeSpan.FromSeconds(2)));

actionRetrier.DoWithRetry(() => 2 + 2 == 4,
    20, TimeSpan.FromSeconds(2));
    
actionRetrier.DoWithRetry(() => 2 + 2 == 4,
    retryCount: 20);
    
actionRetrier.DoWithRetry(() => 2 + 2 == 4,
    backoffDelay: TimeSpan.FromSeconds(2));

Also ActionRetry methods consume some optional arguments:

Argument name Type Purpose
exceptionsToIgnore IList<Type> List with Exception types (derived from System.Exception) to be ignored during ActionRetry execution
failReason string String to be added to ActionRetry timed out exception message
codePurpose string String to be added to each retry attempt message (doesn't work without logger)
logger ILogger Microsoft.Extensions.Logging object to add debug outputs during ActionRetry execution
ActionRetryConfiguration

To create ActionRetryConfiguration object you should pass int RetryCount and TimeSpan BackOffDelay to its constructor. Also you can set Factor and BackoffType to customize main ActionRetry behaviour based on WaitAndRetry policy.

ActionRetryConfiguration could be mapped from .NET Configuration by Microsoft.Extensions.Configuration.ConfigurationBinder.

To understand more about ActionRetryConfiguration capabilities visit https://github.com/Polly-Contrib/Polly.Contrib.WaitAndRetry

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 164 7/24/2023