PollyMediatR 1.0.0
dotnet add package PollyMediatR --version 1.0.0
NuGet\Install-Package PollyMediatR -Version 1.0.0
<PackageReference Include="PollyMediatR" Version="1.0.0" />
<PackageVersion Include="PollyMediatR" Version="1.0.0" />
<PackageReference Include="PollyMediatR" />
paket add PollyMediatR --version 1.0.0
#r "nuget: PollyMediatR, 1.0.0"
#:package PollyMediatR@1.0.0
#addin nuget:?package=PollyMediatR&version=1.0.0
#tool nuget:?package=PollyMediatR&version=1.0.0
PollyMediatR
Polly v8 resilience pipelines for MediatR — add retry, timeout, circuit-breaker, rate-limiting, hedging and chaos engineering to any MediatR request handler with a single line of registration. No changes to handler code required.
services.AddPollyMediatR(pipeline =>
pipeline
.AddRetry(new RetryStrategyOptions
{
MaxRetryAttempts = 3,
Delay = TimeSpan.FromMilliseconds(200),
ShouldHandle = new PredicateBuilder().Handle<Exception>(),
})
.AddTimeout(TimeSpan.FromSeconds(5)));
Every IRequest<T> handler is now automatically wrapped with retry + timeout — zero changes to existing handlers.
Why PollyMediatR?
MediatR's IPipelineBehavior<TRequest, TResponse> is the natural place to apply cross-cutting resilience concerns, but wiring it up with Polly v8 requires boilerplate. PollyMediatR does the wiring for you.
| Without PollyMediatR | With PollyMediatR |
|---|---|
Write a custom IPipelineBehavior per pipeline |
One AddPollyMediatR(...) call |
Manually inject ResiliencePipeline into each behavior |
Pipeline registered & injected automatically |
| Duplicate retry/timeout logic across query & command handlers | Single pipeline applied to all handlers |
| Must update handlers to apply new resilience policies | Zero changes to existing handlers |
Installation
dotnet add package PollyMediatR
Targets net6.0, net8.0, and net9.0.
Dependencies: Polly.Core 8.*, MediatR 12.*, Microsoft.Extensions.DependencyInjection.Abstractions 8.*
Quick start
1. Register with an inline builder (recommended)
using Polly.Retry;
using PollyMediatR;
services.AddPollyMediatR(pipeline =>
pipeline.AddRetry(new RetryStrategyOptions
{
MaxRetryAttempts = 3,
Delay = TimeSpan.FromMilliseconds(200),
BackoffType = DelayBackoffType.Exponential,
ShouldHandle = new PredicateBuilder().Handle<Exception>(),
}));
2. Register with a pre-built pipeline
var pipeline = new ResiliencePipelineBuilder()
.AddRetry(new RetryStrategyOptions { ... })
.AddTimeout(TimeSpan.FromSeconds(10))
.Build();
services.AddPollyMediatR(pipeline);
3. Use normally with MediatR — nothing changes
// Handler — no Polly code needed
public class GetOrderHandler : IRequestHandler<GetOrderQuery, Order>
{
public async Task<Order> Handle(GetOrderQuery request, CancellationToken ct)
{
return await _db.Orders.FindAsync(request.Id, ct); // retried automatically
}
}
// At the call site — identical to normal MediatR usage
var order = await mediator.Send(new GetOrderQuery(id));
ASP.NET Core example
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMediatR(cfg =>
cfg.RegisterServicesFromAssemblyContaining<Program>());
builder.Services.AddPollyMediatR(pipeline =>
pipeline
.AddRetry(new RetryStrategyOptions
{
MaxRetryAttempts = 3,
Delay = TimeSpan.FromMilliseconds(100),
BackoffType = DelayBackoffType.Exponential,
ShouldHandle = new PredicateBuilder()
.Handle<HttpRequestException>()
.Handle<TimeoutException>(),
})
.AddTimeout(TimeSpan.FromSeconds(30))
.AddCircuitBreaker(new CircuitBreakerStrategyOptions
{
FailureRatio = 0.5,
MinimumThroughput = 10,
SamplingDuration = TimeSpan.FromSeconds(30),
BreakDuration = TimeSpan.FromSeconds(15),
}));
Pipeline order
Polly strategies are applied outer-to-inner (left-to-right). The recommended order is:
[Timeout] → [Retry] → [Circuit Breaker] → [Handler]
pipeline
.AddTimeout(TimeSpan.FromSeconds(10)) // 1. Overall deadline
.AddRetry(retryOptions) // 2. Retry on failure
.AddCircuitBreaker(cbOptions) // 3. Open circuit if overloaded
Combining with chaos engineering (PollyChaos)
Use PollyChaos to harden your handlers in test/staging:
services.AddPollyMediatR(pipeline =>
pipeline
.AddRetry(retryOptions)
.AddChaosFault(injectionRate: 0.1)); // inject faults 10% of the time
Related packages
| Package | Downloads | Description |
|---|---|---|
| PollyBackoff | Jitter, linear & custom backoff for Polly v8 retry | |
| PollyChaos | Fault & latency injection (Simmy for Polly v8) | |
| PollyCaching | Cache-aside resilience strategy for Polly v8 | |
| PollyBulkhead | Bulkhead / concurrency limiter for Polly v8 | |
| PollyOpenTelemetry | OpenTelemetry metrics & tracing for Polly v8 |
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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 is compatible. 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. |
-
net6.0
- MediatR (>= 12.5.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Polly.Core (>= 8.7.0)
-
net8.0
- MediatR (>= 12.5.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Polly.Core (>= 8.7.0)
-
net9.0
- MediatR (>= 12.5.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Polly.Core (>= 8.7.0)
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 | 46 | 6/23/2026 |
1.0.0: Initial release. ResiliencePipelineBehavior<TRequest,TResponse> wraps any MediatR request in a Polly v8 ResiliencePipeline. Supports net6.0, net8.0, and net9.0.