LiteRetry 0.0.4

There is a newer version of this package available.
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" />
                    
Directory.Packages.props
<PackageReference Include="LiteRetry" />
                    
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 LiteRetry --version 0.0.4
                    
#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
                    
Install as a Cake Addin
#tool nuget:?package=LiteRetry&version=0.0.4
                    
Install as a Cake Tool

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 logic
  • RetryBuilder โ†’ Fluent API for easy configuration
  • RetryContext โ†’ Info for each retry attempt
  • RetryResult<T> โ†’ Contains result, success flag, attempts, timing
  • RetryFailedException โ†’ Thrown after all retries fail
  • DelayStrategy โ†’ Enum with all supported strategies

๐Ÿงพ License

MIT โ€” free for personal and commercial use.


๐Ÿ™Œ Author

Created by Javier Angosto Barjollo

Product 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.

Version Downloads Last Updated
1.0.0 152 5/8/2025
0.0.12 142 5/5/2025
0.0.11 145 5/4/2025
0.0.10 139 5/4/2025
0.0.9 143 5/4/2025
0.0.8 113 5/4/2025
0.0.7 104 5/4/2025
0.0.6 105 5/4/2025
0.0.5 110 5/4/2025
0.0.4 106 5/4/2025
0.0.3 70 5/3/2025
0.0.2 77 5/3/2025
0.0.1 76 5/3/2025