Fluent.Unions.Polly
1.1.0
dotnet add package Fluent.Unions.Polly --version 1.1.0
NuGet\Install-Package Fluent.Unions.Polly -Version 1.1.0
<PackageReference Include="Fluent.Unions.Polly" Version="1.1.0" />
<PackageVersion Include="Fluent.Unions.Polly" Version="1.1.0" />
<PackageReference Include="Fluent.Unions.Polly" />
paket add Fluent.Unions.Polly --version 1.1.0
#r "nuget: Fluent.Unions.Polly, 1.1.0"
#:package Fluent.Unions.Polly@1.1.0
#addin nuget:?package=Fluent.Unions.Polly&version=1.1.0
#tool nuget:?package=Fluent.Unions.Polly&version=1.1.0
![]()
Fluent.Unions.Polly
Connects Result<T> to Polly resilience strategies, so a retry can react to the error inside a result. It builds on Fluent.Unions and adds no retry logic of its own.
Installation
dotnet add package Fluent.Unions.Polly
Usage
Retry on the error in a result. HandleError reads only the result state. Cancellation is never turned into an error: it throws as usual.
using Polly;
using Polly.Retry;
using Fluent.Unions.Polly;
var pipeline = new ResiliencePipelineBuilder<Result<Payment>>()
.AddRetry(new RetryStrategyOptions<Result<Payment>>
{
ShouldHandle = new PredicateBuilder<Result<Payment>>()
.HandleError(error => error is HttpRequestException),
MaxRetryAttempts = 3,
})
.Build();
Run an operation through the pipeline. A thrown exception or a cancelled token becomes an error instead of being thrown.
Result<Payment> payment = await pipeline.ExecuteResultAsync(ct => ChargeAsync(order, ct), cancellationToken);
// an Ok payment after the last attempt, or the last HttpRequestException as the error
With your own result type
Your own result type works with the same members, but HandleError<TResult, TError>() and ExecuteResultAsync<TResult, TError>(...) need explicit type arguments, because Polly's builders carry only the result type. See your own result type.
ShouldHandle = new PredicateBuilder<Result<Payment>>()
.HandleError<Result<Payment>, DomainException>(error => error is PaymentDeclined),
Result<Payment> payment = await pipeline
.ExecuteResultAsync<Result<Payment>, DomainException>(ct => ChargeAsync(order, ct), cancellationToken);
Convert the outcome that Polly passes to callbacks such as OnRetry.
OnRetry = args =>
{
Result<Payment> attempt = args.Outcome.ToResult<Result<Payment>, DomainException>();
return ValueTask.CompletedTask;
},
Documentation
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Fluent.Unions (>= 1.1.0)
- Polly.Core (>= 8.9.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.