LiteRetry 0.0.4
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package LiteRetry --version 0.0.4
NuGet\Install-Package LiteRetry -Version 0.0.4
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="LiteRetry" Version="0.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LiteRetry" Version="0.0.4" />
<PackageReference Include="LiteRetry" />
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 LiteRetry --version 0.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LiteRetry, 0.0.4"
#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 LiteRetry@0.0.4
#: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=LiteRetry&version=0.0.4
#tool nuget:?package=LiteRetry&version=0.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
LiteRetry
LiteRetry is a lightweight, fluent, and extensible retry utility for .NET.
It helps developers eliminate repetitive try/catch blocks and build resilient code with ease.
๐ Installation
dotnet add package LiteRetry
โจ Features
- Configurable automatic retries
- Delay strategies: Fixed, Exponential, and Exponential with Jitter
- Exception filtering (by type or predicate)
- Retry hook (
onRetryAsync
) for logging, metrics, etc. CancellationToken
support- Fluent API via
RetryBuilder
- Fully unit tested and reliable
๐ ๏ธ Basic Usage
var result = await RetryExecutor.ExecuteAsync<string>(
operation: async ct =>
{
// Logic that might fail
return await Task.FromResult("Hello World");
}
);
โ๏ธ Advanced Usage
var result = await RetryExecutor.ExecuteAsync<string>(
operation: async ct =>
{
// Simulated failure
throw new HttpRequestException("503");
},
maxAttempts: 5,
baseDelay: TimeSpan.FromMilliseconds(200),
delayStrategy: DelayStrategy.ExponentialWithJitter,
shouldRetry: ex => ex is HttpRequestException,
onRetryAsync: ctx =>
{
Console.WriteLine($"Retry #{ctx.Attempt} after {ctx.Delay.TotalMilliseconds}ms");
return Task.CompletedTask;
}
);
๐งช Fluent API with RetryBuilder
await RetryBuilder.Configure()
.WithMaxAttempts(5)
.WithBaseDelay(TimeSpan.FromMilliseconds(300))
.WithStrategy(DelayStrategy.Exponential)
.WithFilterByType<HttpRequestException>()
.OnRetryAsync(ctx =>
{
Console.WriteLine($"Retry {ctx.Attempt}: {ctx.Exception.Message}");
return Task.CompletedTask;
})
.RunAsync(async ct =>
{
// Operation that may throw
throw new HttpRequestException("Timeout");
});
๐ฆ Class Overview
RetryExecutor
โ Static class with core retry logicRetryBuilder
โ Fluent API for easy configurationRetryContext
โ Info for each retry attemptRetryResult<T>
โ Contains result, success flag, attempts, timingRetryFailedException
โ Thrown after all retries failDelayStrategy
โ Enum with all supported strategies
๐งพ License
MIT โ free for personal and commercial use.
๐ Author
Created by Javier Angosto Barjollo
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- 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.