Nyxalon.Resilience 1.0.0-beta.145

This is a prerelease version of Nyxalon.Resilience.
dotnet add package Nyxalon.Resilience --version 1.0.0-beta.145
                    
NuGet\Install-Package Nyxalon.Resilience -Version 1.0.0-beta.145
                    
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="Nyxalon.Resilience" Version="1.0.0-beta.145" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nyxalon.Resilience" Version="1.0.0-beta.145" />
                    
Directory.Packages.props
<PackageReference Include="Nyxalon.Resilience" />
                    
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 Nyxalon.Resilience --version 1.0.0-beta.145
                    
#r "nuget: Nyxalon.Resilience, 1.0.0-beta.145"
                    
#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 Nyxalon.Resilience@1.0.0-beta.145
                    
#: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=Nyxalon.Resilience&version=1.0.0-beta.145&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Nyxalon.Resilience&version=1.0.0-beta.145&prerelease
                    
Install as a Cake Tool

Nyxalon.Resilience

A thin, opinionated resilience pipeline abstraction built on top of Polly, wired via Microsoft.Extensions.DependencyInjection.

Provides retry and circuit breaker policies behind a clean IResiliencePipeline interface — no Polly internals leaking into your application code.


Installation

dotnet add package Nyxalon.Resilience

Getting Started

Register pipelines in your Program.cs (or Startup.cs):

builder.Services.AddResilienceKit(options =>
{
    options.AddPipeline("default", builder =>
    {
        builder
            .AddRetry(new RetryOptions
            {
                RetryCount = 3,
                BaseDelayMilliseconds = 200
            })
            .AddCircuitBreaker(new CircuitBreakerOptions
            {
                FailureThreshold = 0.5,
                SamplingDurationSeconds = 30,
                MinimumThroughput = 10,
                BreakDurationSeconds = 60
            });
    });
});

Inject and use IResiliencePipelineProvider anywhere in your app:

public class OrderService(IResiliencePipelineProvider pipelines)
{
    public async Task PlaceOrderAsync(Order order, CancellationToken ct)
    {
        IResiliencePipeline pipeline = pipelines.GetPipeline("default");

        await pipeline.ExecuteAsync(async () =>
        {
            await _httpClient.PostAsJsonAsync("/orders", order, ct);
        }, ct);
    }
}

Policies

Retry

Retries a failed operation with linear back-off.

builder.AddRetry(new RetryOptions
{
    RetryCount = 3,           // number of retry attempts
    BaseDelayMilliseconds = 200  // delay = BaseDelay * attemptNumber
});
Property Default Description
RetryCount 3 How many times to retry after the first failure
BaseDelayMilliseconds 200 Base multiplier for the wait between retries

With the defaults, delays will be: 200ms → 400ms → 600ms.


Circuit Breaker

Opens the circuit when the failure rate exceeds the threshold, blocking calls for the break duration.

builder.AddCircuitBreaker(new CircuitBreakerOptions
{
    FailureThreshold = 0.5,        // 50% failure rate opens the circuit
    SamplingDurationSeconds = 30,  // measured over a 30s window
    MinimumThroughput = 10,        // at least 10 calls needed before measuring
    BreakDurationSeconds = 60      // circuit stays open for 60s
});
Property Default Description
FailureThreshold 0.5 Failure rate (0.0–1.0) that triggers the break
SamplingDurationSeconds 30 Rolling window to measure failures over
MinimumThroughput 10 Minimum calls in the window before the breaker can open
BreakDurationSeconds 60 How long the circuit stays open before going half-open

When the circuit is open, calls throw BrokenCircuitException immediately without reaching the underlying operation.


Combining Policies

Policies are applied in the order they are added — outermost first. The recommended order is retry wrapping circuit breaker:

options.AddPipeline("external-api", builder =>
{
    builder
        .AddRetry(new RetryOptions { RetryCount = 2, BaseDelayMilliseconds = 100 })
        .AddCircuitBreaker(new CircuitBreakerOptions { MinimumThroughput = 5 });
});

This means: retry up to 2 times, but if the circuit is already open, fail immediately without retrying.


Multiple Named Pipelines

Register as many pipelines as you need — each with its own policy configuration:

builder.Services.AddResilienceKit(options =>
{
    // Aggressive retry for internal services
    options.AddPipeline("internal", builder =>
    {
        builder.AddRetry(new RetryOptions { RetryCount = 5, BaseDelayMilliseconds = 50 });
    });

    // Conservative for third-party APIs
    options.AddPipeline("external", builder =>
    {
        builder
            .AddRetry(new RetryOptions { RetryCount = 2, BaseDelayMilliseconds = 500 })
            .AddCircuitBreaker(new CircuitBreakerOptions
            {
                FailureThreshold = 0.3,
                BreakDurationSeconds = 120
            });
    });

    // No-op pipeline for local/dev
    options.AddPipeline("noop", _ => { });
});

Return Values

ExecuteAsync has a generic overload for operations that return a value:

IResiliencePipeline pipeline = pipelines.GetPipeline("external");

Product? product = await pipeline.ExecuteAsync(async () =>
{
    return await _httpClient.GetFromJsonAsync<Product>($"/products/{id}");
});

License

MIT © Nyxalon

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.0-beta.145 80 3/23/2026
1.0.0-beta.144 64 3/23/2026