EonaCat.SmartRetry
1.0.0
Prefix Reserved
dotnet add package EonaCat.SmartRetry --version 1.0.0
NuGet\Install-Package EonaCat.SmartRetry -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="EonaCat.SmartRetry" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EonaCat.SmartRetry" Version="1.0.0" />
<PackageReference Include="EonaCat.SmartRetry" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EonaCat.SmartRetry --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: EonaCat.SmartRetry, 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.
#:package EonaCat.SmartRetry@1.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EonaCat.SmartRetry&version=1.0.0
#tool nuget:?package=EonaCat.SmartRetry&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
EonaCat.SmartRetry
EonaCat.SmartRetry is a powerful and flexible .NET library for building resilient applications.
It provides retry policies, circuit breakers, fallbacks, jittered backoff, async/sync support, and more
Features
- Retry on exceptions or result conditions
- Configurable retry count and max retry duration
- Exponential, linear, or custom backoff strategies
- Jitter support to prevent thundering herd
- Circuit breaker with open, half-open, and closed states
- Sync and async fallback actions
- Retry with cancellation tokens
- Logging and async callbacks for retries and circuit breaker events
- Thread-safe for multi-threaded operations
- Named policies for reusable resilience configurations
Installation
Install via NuGet:
dotnet add package EonaCat.SmartRetry
Or via Package Manager:
Install-Package EonaCat.SmartRetry
Usage Examples
Basic Retry with Fallback
using EonaCat.SmartRetry;
var policy = SmartRetryPolicy.Policy()
.Handle<TimeoutException>()
.Retry(3)
.WithExponentialBackoff(1, 2)
.WithFallbackAsync(async () =>
{
Console.WriteLine("Executing fallback...");
await Task.Delay(50);
// fallback value
return 42;
});
int result = await policy.ExecuteAsync<int>(async () =>
{
Console.WriteLine("Attempting operation...");
await Task.Delay(50);
throw new TimeoutException("Simulated failure");
});
// Outputs: 42
Console.WriteLine($"Result: {result}");
Retry with Circuit Breaker, Jitter, and Logging
var policy = SmartRetryPolicy.Policy()
.Handle<TimeoutException>()
.Retry(5)
.WithExponentialBackoff(1, 2)
.WithJitter(0.2)
.WithCircuitBreaker(failureThreshold: 3, openDuration: TimeSpan.FromSeconds(10))
.WithFallbackAsync(async () =>
{
Console.WriteLine("Executing fallback...");
await Task.Delay(50);
return -1;
})
.OnRetry((attempt, ex) => Console.WriteLine($"Retry {attempt}: {ex.Message}"))
.OnCircuitOpen(() => Console.WriteLine("Circuit breaker opened"))
.OnCircuitClose(() => Console.WriteLine("Circuit breaker closed"));
int result = await policy.ExecuteAsync<int>(async (ct) =>
{
Console.WriteLine("Attempting operation...");
await Task.Delay(50, ct);
throw new TimeoutException("Simulated failure");
});
Console.WriteLine($"Result: {result}");
Retry Based on Result Condition
var policy = SmartRetryPolicy.Policy()
.RetryIf<int>(value => value < 0) // retry if result is negative
.Retry(3)
.WithLinearBackoff(0.5)
.WithFallback(() => 0);
int result = policy.Execute(() =>
{
Console.WriteLine("Returning -1 to trigger retry...");
return -1;
});
// Outputs: 0 (fallback)
Console.WriteLine($"Result: {result}");
Advanced Features
- Max Retry Duration: Stop retrying after a total duration.
- CancellationToken Support: Cancel retry loops gracefully.
- Custom Backoff Functions: Provide your own delay logic.
- Async Logging Hooks: Integrate with metrics or monitoring systems.
- Named Policies: Standardize retry/circuit-breaker behavior across your app.
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- No dependencies.
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 | 312 | 12/15/2025 |