Muonroi.Resilience 2.0.2

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

Muonroi.Resilience

Polly-based resilience patterns optimized for Muonroi with built-in telemetry tracking.

NuGet License

Overview

The Muonroi.Resilience package provides a standardized approach to fault tolerance in distributed systems using Polly. In a microservices architecture, transient failures (e.g., brief network outages, temporary database unavailability) are common. This package abstracts the setup of robust Retry, Circuit Breaker, Timeout, and Bulkhead policies.

Crucially, it extends standard Polly functionality by integrating deeply with Muonroi's telemetry ecosystem. State transitions (e.g., a Circuit Breaker opening) and execution retries are automatically logged and emitted as OpenTelemetry metrics, ensuring full visibility into the stability of downstream dependencies.

Use this package when your application needs to reliably communicate with external APIs, databases, or message brokers over unreliable networks.

Features

  • Pre-configured Resilience Pipelines: Offers AddMuonroiResilience() which registers standard policy wrappers tailored for common scenarios.
  • Retry Policies: Automatically retries failed operations using configurable exponential backoff strategies to avoid overwhelming struggling services, explicitly handling MTransientException.
  • Circuit Breaker: Detects when a downstream service is fundamentally unhealthy and fails fast, preventing cascading failures across the system.
  • Timeouts: Ensures that slow dependencies don't consume all available threads in the calling application via AddTimeout.
  • Telemetry Integration: Policy executions and state changes automatically emit OTel events and structured logs via MuonroiMetrics.RetryAttemptCount and IMLog.

Installation

dotnet add package Muonroi.Resilience

Quick Start

Basic Configuration

Register the standard Muonroi resilience policies in your dependency injection container. This will make the ResiliencePipelineProvider available to your services.

using Microsoft.Extensions.DependencyInjection;
using Muonroi.Resilience;

var builder = WebApplication.CreateBuilder(args);

// Register standard resilience pipeline ("muonroi-standard")
builder.Services.AddMuonroiResilience();

Manual Policy Execution

If you need to wrap arbitrary code (e.g., a database connection attempt or a file system operation) in a resilience policy, you can resolve the ResiliencePipelineProvider.

using Polly.Registry;
using System.Threading.Tasks;

public class DatabaseInitializer
{
    private readonly ResiliencePipelineProvider<string> _pipelineProvider;

    public DatabaseInitializer(ResiliencePipelineProvider<string> pipelineProvider)
    {
        _pipelineProvider = pipelineProvider;
    }

    public async Task InitializeAsync()
    {
        // Get the predefined 'muonroi-standard' pipeline
        var pipeline = _pipelineProvider.GetPipeline("muonroi-standard");

        // Execute the unstable operation within the pipeline
        await pipeline.ExecuteAsync(async token => 
        {
            await RunMigrationLogicAsync();
        });
    }
}

API Reference

Configuration Extensions

  • MuonroiResilienceExtensions: Contains AddMuonroiResilience() which populates the DI container with ResiliencePipelineBuilder configurations standard to the ecosystem.

Pipeline Handlers

  • PolicyHandler: Internal handlers that wire Polly's events to Muonroi's IMLog and OpenTelemetry metrics abstractions.

Ecosystem Combinations

+ Muonroi.Observability → Resiliency Metrics

By combining these, Polly events such as retries are automatically intercepted and exported via MuonroiMetrics.RetryAttemptCount, allowing operators to set up Grafana alerts when internal services begin to destabilize before complete failure.

+ Muonroi.Logging.Abstractions → Structured Resilience Logs

The resilience pipeline extracts IMLog from the IServiceProvider at runtime to emit structured logs containing the precise exception types and retry attempts when a transient error is caught and retried.

Full Resilience Stack

builder.Services
    .AddMuonroiResilience()
    .AddMuonroiObservability(config);

Samples

License

Apache 2.0 — see LICENSE-APACHE.

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 (2)

Showing the top 2 NuGet packages that depend on Muonroi.Resilience:

Package Downloads
Muonroi.Http

HTTP client utilities for Muonroi: resilient client factory, tenant header propagation, and typed client base.

Muonroi.BuildingBlock.All

Metapackage for Muonroi Building Block - Includes all sub-packages for a complete infrastructure setup.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.2 146 8/26/2026
2.0.1 152 8/26/2026
2.0.0 182 8/14/2026
1.0.0-alpha.2 73 3/26/2026