Poolz.Finance.CSharp.Polly.Extensions
1.0.0
dotnet add package Poolz.Finance.CSharp.Polly.Extensions --version 1.0.0
NuGet\Install-Package Poolz.Finance.CSharp.Polly.Extensions -Version 1.0.0
<PackageReference Include="Poolz.Finance.CSharp.Polly.Extensions" Version="1.0.0" />
<PackageVersion Include="Poolz.Finance.CSharp.Polly.Extensions" Version="1.0.0" />
<PackageReference Include="Poolz.Finance.CSharp.Polly.Extensions" />
paket add Poolz.Finance.CSharp.Polly.Extensions --version 1.0.0
#r "nuget: Poolz.Finance.CSharp.Polly.Extensions, 1.0.0"
#:package Poolz.Finance.CSharp.Polly.Extensions@1.0.0
#addin nuget:?package=Poolz.Finance.CSharp.Polly.Extensions&version=1.0.0
#tool nuget:?package=Poolz.Finance.CSharp.Polly.Extensions&version=1.0.0
Poolz.Finance.CSharp.Polly.Extensions
Poolz.Finance.CSharp.Polly.Extensions is a lightweight helper library that adds ready-to-use retry primitives on top of Polly. It targets .NET Standard 2.1, so it can be consumed from modern .NET and .NET Core applications, background services, and libraries.
Features
- Sensible defaults for
RetryStrategyOptions<T>viaDefaultRetryStrategyOptions<T>. - Built-in logging hook with optional custom formatter for retry attempts.
- Ignores
OperationCanceledExceptionby default so cooperative cancellation is preserved. IRetryExecutor/RetryExecutorwrapper to execute synchronous and asynchronous delegates without manually composing aResiliencePipeline<T>.- Works seamlessly with existing Polly pipelines and can be registered in dependency injection containers.
Default retry configuration
DefaultRetryStrategyOptions<T> ships with the following values out of the box:
| Setting | Default value |
|---|---|
| Name | "Retry" |
| Max retry attempts | 3 |
| Backoff type | DelayBackoffType.Constant |
| Initial delay | TimeSpan.FromMilliseconds(250) |
| Use jitter | false |
| Retryable exceptions | Any exception except OperationCanceledException |
A logging callback can be supplied, as well as a custom formatter that receives Polly's OnRetryArguments<T> and returns the message to emit. When no formatter is provided the library uses the built-in message: "[Retry] Attempt={n}, Delay={delay}, Exception={type}: {message}".
Installation
dotnet add package Poolz.Finance.CSharp.Polly.Extensions
The library depends on Polly (currently 8.6.x). If you build from source, run dotnet restore followed by dotnet build or dotnet test.
Getting started
Creating a retry pipeline with the defaults
using Polly;
using Poolz.Finance.CSharp.Polly.Extensions;
var options = new DefaultRetryStrategyOptions<HttpResponseMessage>(Console.WriteLine);
var pipeline = new ResiliencePipelineBuilder<HttpResponseMessage>()
.AddRetry(options)
.Build();
var response = await pipeline.ExecuteAsync(async token =>
{
// Replace with your real operation.
return await httpClient.SendAsync(request, token);
}, CancellationToken.None);
The log delegate (Console.WriteLine in the sample) will be invoked for every retry attempt. When no logger is provided the retries still occur silently.
Executing work via RetryExecutor
using Poolz.Finance.CSharp.Polly.Extensions;
IRetryExecutor retryExecutor = new RetryExecutor();
var user = await retryExecutor.ExecuteAsync(async token =>
{
return await httpClient.GetFromJsonAsync<UserDto>("/users/42", cancellationToken: token);
});
var invoice = retryExecutor.Execute(_ =>
{
// Synchronous operations are supported too.
return invoiceService.GenerateInvoice();
});
RetryExecutor automatically constructs a ResiliencePipeline<T> using the provided options (or the defaults when none are passed) and forwards the CancellationToken that you supply.
Customising retry behaviour
using Poolz.Finance.CSharp.Polly.Extensions;
var options = new DefaultRetryStrategyOptions<int>(
log: message => logger.LogWarning(message),
format: args =>
$"Attempt {args.AttemptNumber + 1} failed after {args.RetryDelay.TotalMilliseconds} ms"
)
{
MaxRetryAttempts = 5,
BackoffType = DelayBackoffType.Exponential,
UseJitter = true
};
You can further tweak the retry strategy by updating the properties inherited from Polly's RetryStrategyOptions<T>. The supplied format delegate is optional�omit it to use the default message.
Dependency injection registration
services.AddSingleton<IRetryExecutor, RetryExecutor>();
Registering the executor in your DI container makes it trivial to consume resilient execution from any service that requires it.
Development
Clone the repository and execute the tests to validate your changes:
dotnet test
License
This project is licensed under the MIT License. See the LICENSE file for more information.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Polly (>= 8.6.3)
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 | 845 | 9/19/2025 |