See More

A very common reason is a wrong site baseUrl configuration.\n

Current configured baseUrl = / (default value)\n

We suggest trying baseUrl = \n\n',document.body.prepend(n);var e=document.getElementById("__docusaurus-base-url-issue-banner-suggestion-container"),s=window.location.pathname,o="/"===s.substr(-1)?s:s+"/";e.textContent=o}document.addEventListener("DOMContentLoaded",function(){void 0===window.docusaurus&&insertBanner()})

Skip to main content

ZeroAlloc.Resilience

Source-generated, zero-allocation resilience policies for .NET.

Add [Retry], [Timeout], [RateLimit], and [CircuitBreaker] to an interface; the generator emits a proxy composing all policies in declaration order with no heap allocation on the happy path.

Quick example

[Retry(MaxAttempts = 3, BackoffMs = 200, Jitter = true)]
[Timeout(Ms = 5_000)]
[CircuitBreaker(MaxFailures = 5, ResetMs = 1_000, HalfOpenProbes = 1, Fallback = nameof(FetchFallback))]
public interface IExternalService
{
ValueTask<string> FetchAsync(string id, CancellationToken ct);
ValueTask<string> FetchFallback(string id, CancellationToken ct);
}

// Register — one line
services.AddExternalServiceResilience<ExternalServiceImpl>();

// Inject IExternalService — all policies are wired automatically

Contents

PageDescription
Getting StartedInstall, annotate an interface, register with DI
Attributes[Retry], [Timeout], [RateLimit], [CircuitBreaker] reference
Source GeneratorWhat the generator emits — annotated proxy example
PerformanceBenchmark results and allocation profile

Core Concepts

PageDescription
RetryExponential backoff, jitter, per-attempt timeout, exhaustion behaviour
TimeoutTotal timeout vs. per-attempt timeout, CTS lifecycle
Rate LimitToken bucket, lock-free acquire, Shared vs Instance scope
Circuit BreakerState machine, failure tracking, half-open probing, fallback
Execution OrderHow policies compose: RateLimit → CB → Timeout → Retry

Guides

PageDescription
FallbackDeclare and implement circuit-breaker fallback methods
Method-Level OverridesPer-method policy configuration
Result Return TypesNon-throwing failure path with Result<T>
DI RegistrationGenerated extension method, overrides, manual construction

Diagnostics

IDSeverityDescription
ZR0001ErrorFallback method not found or signature mismatch
ZR0002WarningTimeout configured but method has no CancellationToken