Engine.SmartRetry 1.0.0

There is a newer version of this package available.
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
                    
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="Engine.SmartRetry" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Engine.SmartRetry" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Engine.SmartRetry" />
                    
Project file
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 Engine.SmartRetry --version 1.0.0
                    
#r "nuget: Engine.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 Engine.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=Engine.SmartRetry&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Engine.SmartRetry&version=1.0.0
                    
Install as a Cake Tool

๐Ÿ“ฆ 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 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. 
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.1 199 5/2/2025
1.0.0 184 5/2/2025