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
| Page | Description |
|---|---|
| Getting Started | Install, annotate an interface, register with DI |
| Attributes | [Retry], [Timeout], [RateLimit], [CircuitBreaker] reference |
| Source Generator | What the generator emits — annotated proxy example |
| Performance | Benchmark results and allocation profile |
Core Concepts
| Page | Description |
|---|---|
| Retry | Exponential backoff, jitter, per-attempt timeout, exhaustion behaviour |
| Timeout | Total timeout vs. per-attempt timeout, CTS lifecycle |
| Rate Limit | Token bucket, lock-free acquire, Shared vs Instance scope |
| Circuit Breaker | State machine, failure tracking, half-open probing, fallback |
| Execution Order | How policies compose: RateLimit → CB → Timeout → Retry |
Guides
| Page | Description |
|---|---|
| Fallback | Declare and implement circuit-breaker fallback methods |
| Method-Level Overrides | Per-method policy configuration |
| Result Return Types | Non-throwing failure path with Result<T> |
| DI Registration | Generated extension method, overrides, manual construction |
Diagnostics
| ID | Severity | Description |
|---|---|---|
| ZR0001 | Error | Fallback method not found or signature mismatch |
| ZR0002 | Warning | Timeout configured but method has no CancellationToken |