Migration von Polly nach microsoft.extensions.http.resilience - Erweiterung sollte HANDLEC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Migration von Polly nach microsoft.extensions.http.resilience - Erweiterung sollte HANDLE

Post by Anonymous »

Ich möchte von Polly auf microsoft.extensions.http.resilience addStandardResilienceHandler migrieren. Mein verkürzter Polly -Code ist der folgende: < /p>

Code: Select all

services.AddHttpClient()
.AddPolicyHandler((_, _) =>
{
return HttpPolicyExtensions.HandleTransientHttpError()
.Or(exception => exception.StatusCode == HttpStatusCode.Conflict)
.WaitAndRetryAsync(3, sleepDurationProvider: i => TimeSpan.FromSeconds(i * 2));
});
Der entscheidende Teil hier ist httppolicextensions.handletransientHttTerRor (). Oder (Exception => Ausnahme. Ich weiß wirklich, wie man dies in die neue Konfiguration umwandelt. Microsofts Standardimplementierung von SollHandle sieht so aus:

Code: Select all

public static readonly Func HandleOutcome = args => args.Outcome.Exception switch
{
OperationCanceledException => PredicateResult.False(),
Exception => PredicateResult.True(),
_ => PredicateResult.False()
};
< /code>
Meine aktuelle Konfiguration sieht so aus: < /p>
services.AddHttpClient()
.AddStandardResilienceHandler()
.Configure((options, _) =>
{
options.Retry.ShouldHandle = args =>
{
if (args.Outcome.Result?.StatusCode == HttpStatusCode.Conflict)
{
return PredicateResult.True();
}

return args.Outcome.Exception switch
{
OperationCanceledException => PredicateResult.False(),
not null => PredicateResult.True(),
_ => PredicateResult.False()
};
};
});
Ist dies der ersten Polly -Implementierung entspricht?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post