Deila með


PollyHttpClientBuilderExtensions.AddTransientHttpErrorPolicy Method

Definition

Adds a PolicyHttpMessageHandler which will surround request execution with a Policy created by executing the provided configuration delegate. The policy builder will be preconfigured to trigger application of the policy for requests that fail with conditions that indicate a transient failure.

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IHttpClientBuilder ^ AddTransientHttpErrorPolicy(Microsoft::Extensions::DependencyInjection::IHttpClientBuilder ^ builder, Func<Polly::PolicyBuilder<System::Net::Http::HttpResponseMessage ^> ^, Polly::IAsyncPolicy<System::Net::Http::HttpResponseMessage ^> ^> ^ configurePolicy);
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddTransientHttpErrorPolicy (this Microsoft.Extensions.DependencyInjection.IHttpClientBuilder builder, Func<Polly.PolicyBuilder<System.Net.Http.HttpResponseMessage>,Polly.IAsyncPolicy<System.Net.Http.HttpResponseMessage>> configurePolicy);
static member AddTransientHttpErrorPolicy : Microsoft.Extensions.DependencyInjection.IHttpClientBuilder * Func<Polly.PolicyBuilder<System.Net.Http.HttpResponseMessage>, Polly.IAsyncPolicy<System.Net.Http.HttpResponseMessage>> -> Microsoft.Extensions.DependencyInjection.IHttpClientBuilder
<Extension()>
Public Function AddTransientHttpErrorPolicy (builder As IHttpClientBuilder, configurePolicy As Func(Of PolicyBuilder(Of HttpResponseMessage), IAsyncPolicy(Of HttpResponseMessage))) As IHttpClientBuilder

Parameters

configurePolicy
Func<PolicyBuilder<HttpResponseMessage>,IAsyncPolicy<HttpResponseMessage>>

A delegate used to create a IAsyncPolicy`1.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

See the remarks on PolicyHttpMessageHandler for guidance on configuring policies.

The PolicyBuilder`1 provided to configurePolicy has been preconfigured errors to handle errors in the following categories:

  • Network failures (as HttpRequestException)
  • HTTP 5XX status codes (server errors)
  • HTTP 408 status code (request timeout)

The policy created by configurePolicy will be cached indefinitely per named client. Policies are generally designed to act as singletons, and can be shared when appropriate. To share a policy across multiple named clients, first create the policy and then pass it to multiple calls to AddPolicyHandler(IHttpClientBuilder, IAsyncPolicy<HttpResponseMessage>) as desired.

Applies to