Pragmatic.Resilience
Native, AOT-safe resilience for .NET 10 — strategy composition, a fluent builder, DI integration, and source-generator support. No Polly dependency.
The Problem
Section titled “The Problem”Distributed systems fail: calls time out, databases go down, APIs error. The usual fix — Polly policies or hand-rolled retry loops — scatters resilience across the codebase, pulls in external dependencies, and treats every failure the same, whether it’s transient (a network blip) or permanent (a validation error).
// Without Pragmatic: manual composition, repeated at every call sitevar combined = Policy.WrapAsync( Policy.TimeoutAsync(10), Policy.Handle<HttpRequestException>().CircuitBreakerAsync(5, TimeSpan.FromSeconds(30)), Policy.Handle<HttpRequestException>().WaitAndRetryAsync(3, a => TimeSpan.FromMilliseconds(200 * Math.Pow(2, a))));await combined.ExecuteAsync(ct => http.PostAsJsonAsync("/charges", request, ct), ct);The Solution
Section titled “The Solution”Declare a policy name; the generator composes the pipeline. One attribute, several strategies, zero
manual wiring — and it distinguishes transient exceptions (retry/break) from Result failures
(validation, not-found), which pass through unchanged.
[DomainAction][ResiliencePolicy("payment-gateway")]public partial class ChargeCustomerAction : DomainAction<PaymentResult>{ public override async Task<Result<PaymentResult, IError>> Execute(CancellationToken ct) { // wrapped by the "payment-gateway" pipeline automatically: // retry + circuit breaker + timeout on exceptions; Result failures pass through var response = await _http.PostAsJsonAsync("/charges", _request, ct); response.EnsureSuccessStatusCode(); return await response.Content.ReadFromJsonAsync<PaymentResult>(ct)!; }}Installation
Section titled “Installation”dotnet add package Pragmatic.ResilienceStrategies — retry (with backoff + jitter), circuit breaker, timeout, hedging, fallback, rate limiter,
bulkhead — compose in a defined pipeline order; configure named policies in Program.cs or via the
fluent builder. See Policies.
Status
Section titled “Status”The strategy set, pipeline composition, DI integration, and the [ResiliencePolicy] generator are
functional within the 0.8 preview. See the roadmap.
| Concepts | Strategy model, pipeline order, transient vs permanent failures | | Getting Started | Declare a policy, wrap an action/call | | Policies | Every strategy, parameters, configuration, named policies | | Common Mistakes | The most frequent resilience pitfalls | | Troubleshooting | Problem/solution guide |
Requirements
Section titled “Requirements”- .NET 10.0+
License
Section titled “License”Part of the Pragmatic.Design ecosystem — see Licensing. Pragmatic.Resilience is MIT-licensed.