Engine.SmartRetry
1.0.0
See the version list below for details.
dotnet add package Engine.SmartRetry --version 1.0.0
NuGet\Install-Package Engine.SmartRetry -Version 1.0.0
<PackageReference Include="Engine.SmartRetry" Version="1.0.0" />
<PackageVersion Include="Engine.SmartRetry" Version="1.0.0" />
<PackageReference Include="Engine.SmartRetry" />
paket add Engine.SmartRetry --version 1.0.0
#r "nuget: Engine.SmartRetry, 1.0.0"
#:package Engine.SmartRetry@1.0.0
#addin nuget:?package=Engine.SmartRetry&version=1.0.0
#tool nuget:?package=Engine.SmartRetry&version=1.0.0
๐ฆ SmartRetry
SmartRetry is a lightweight, extensible retry mechanism for .NET, designed to handle transient faults with support for exponential backoff and jitter strategies.
Ideal for HTTP calls, database retries, and other retryable operations.
๐ Features
- โ Retry execution with custom logic
- ๐ Exponential backoff & jitter support
- โ๏ธ Configurable via
RetryOptions - ๐ Clean Dependency Injection (DI) integration
- ๐งช Unit & integration tested
- ๐ก๏ธ Follows SOLID design principles
๐ฆ Installation
Install via NuGet:
dotnet add package SmartRetry
โก Getting Started
1. Register in Program.cs
builder.Services.AddSmartRetry(); // Registers SmartRetry services
๐ Inject & Use the Retry Executor
You can inject IRetryExecutor into your service or controller:
public class MyService
{
private readonly IRetryExecutor _executor;
public MyService(IRetryExecutor executor)
{
_executor = executor;
}
public async Task CallExternalServiceAsync()
{
await _executor.ExecuteAsync(
async () =>
{
await httpClient.GetAsync("https://api.example.com");
});
}
}
โ๏ธ Custom Retry Options
You can customize retry behavior using RetryOptions:
var options = new RetryOptions
{
MaxRetries = 5,
BaseDelayMs = 200,
ShouldRetryOnException = ex => ex is TimeoutException || ex is HttpRequestException
};
await _executor.ExecuteAsync(
async () => await httpClient.GetAsync("https://api.example.com"),
options: options
);
๐ Backoff & Jitter Strategy
Built-in backoff strategies include:
- Exponential backoff
- Full jitter / equal jitter
You can implement your own by extending IBackoffStrategy.
๐งช Running Tests
Run Unit & Integration Tests with Coverage
dotnet test --collect:"XPlat Code Coverage"
The test results will be stored in a subfolder of /TestResults/.
๐ Generate Code Coverage Report
Use tools like ReportGenerator:
reportgenerator -reports:**/coverage.cobertura.xml -targetdir:coverage-report
Then open coverage-report/index.html in your browser to view results.
๐ SonarQube Integration
Optional support for SonarQube:
dotnet sonarscanner begin /k:"SmartRetry" /d:sonar.login="your_token"
dotnet build
dotnet test --collect:"XPlat Code Coverage"
dotnet sonarscanner end /d:sonar.login="your_token"
๐ Project Structure
SmartRetry/
โ
โโโ Abstractions/ # Interfaces like IRetryStrategy, IBackoffStrategy
โโโ Models/ # RetryOptions, RetryFailedException
โโโ Strategies/ # Built-in retry/backoff strategies
โโโ SmartRetry.csproj # Main library
โ
โโโ SmartRetry.Test/ # Unit tests
โโโ SmartRetry.IntegrationTests/ # Integration tests
๐ค Contributing
Feel free to submit issues or pull requests. All contributions are welcome and appreciated!
๐ License
This project is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. |
-
net8.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.