Deli z drugimi prek


PollyHttpClientBuilderExtensions.AddPolicyHandler Method

Definition

Overloads

AddPolicyHandler(IHttpClientBuilder, IAsyncPolicy<HttpResponseMessage>)

Adds a PolicyHttpMessageHandler which will surround request execution with the provided IAsyncPolicy`1.

AddPolicyHandler(IHttpClientBuilder, Func<IServiceProvider,HttpRequestMessage,IAsyncPolicy<HttpResponseMessage>>)

Adds a PolicyHttpMessageHandler which will surround request execution with a policy returned by the policySelector.

AddPolicyHandler(IHttpClientBuilder, Func<HttpRequestMessage,IAsyncPolicy<HttpResponseMessage>>)

Adds a PolicyHttpMessageHandler which will surround request execution with a policy returned by the policySelector.

AddPolicyHandler(IHttpClientBuilder, Func<IServiceProvider,HttpRequestMessage, String,IAsyncPolicy<HttpResponseMessage>>, Func<HttpRequestMessage, String>)

Adds a PolicyHttpMessageHandler which will surround request execution with a policy returned by executing provided key selection logic keySelector and policyFactory.

AddPolicyHandler(IHttpClientBuilder, IAsyncPolicy<HttpResponseMessage>)

Adds a PolicyHttpMessageHandler which will surround request execution with the provided IAsyncPolicy`1.

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

Parameters

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

See the remarks on PolicyHttpMessageHandler for guidance on configuring policies.

Applies to

AddPolicyHandler(IHttpClientBuilder, Func<IServiceProvider,HttpRequestMessage,IAsyncPolicy<HttpResponseMessage>>)

Adds a PolicyHttpMessageHandler which will surround request execution with a policy returned by the policySelector.

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

Parameters

policySelector
Func<IServiceProvider,HttpRequestMessage,IAsyncPolicy<HttpResponseMessage>>

Selects an IAsyncPolicy`1 to apply to the current request.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

See the remarks on PolicyHttpMessageHandler for guidance on configuring policies.

Applies to

AddPolicyHandler(IHttpClientBuilder, Func<HttpRequestMessage,IAsyncPolicy<HttpResponseMessage>>)

Adds a PolicyHttpMessageHandler which will surround request execution with a policy returned by the policySelector.

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

Parameters

policySelector
Func<HttpRequestMessage,IAsyncPolicy<HttpResponseMessage>>

Selects an IAsyncPolicy`1 to apply to the current request.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

See the remarks on PolicyHttpMessageHandler for guidance on configuring policies.

Applies to

AddPolicyHandler(IHttpClientBuilder, Func<IServiceProvider,HttpRequestMessage, String,IAsyncPolicy<HttpResponseMessage>>, Func<HttpRequestMessage, String>)

Adds a PolicyHttpMessageHandler which will surround request execution with a policy returned by executing provided key selection logic keySelector and policyFactory.

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IHttpClientBuilder ^ AddPolicyHandler(Microsoft::Extensions::DependencyInjection::IHttpClientBuilder ^ builder, Func<IServiceProvider ^, System::Net::Http::HttpRequestMessage ^, System::String ^, Polly::IAsyncPolicy<System::Net::Http::HttpResponseMessage ^> ^> ^ policyFactory, Func<System::Net::Http::HttpRequestMessage ^, System::String ^> ^ keySelector);
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddPolicyHandler (this Microsoft.Extensions.DependencyInjection.IHttpClientBuilder builder, Func<IServiceProvider,System.Net.Http.HttpRequestMessage,string,Polly.IAsyncPolicy<System.Net.Http.HttpResponseMessage>> policyFactory, Func<System.Net.Http.HttpRequestMessage,string> keySelector);
static member AddPolicyHandler : Microsoft.Extensions.DependencyInjection.IHttpClientBuilder * Func<IServiceProvider, System.Net.Http.HttpRequestMessage, string, Polly.IAsyncPolicy<System.Net.Http.HttpResponseMessage>> * Func<System.Net.Http.HttpRequestMessage, string> -> Microsoft.Extensions.DependencyInjection.IHttpClientBuilder
<Extension()>
Public Function AddPolicyHandler (builder As IHttpClientBuilder, policyFactory As Func(Of IServiceProvider, HttpRequestMessage, String, IAsyncPolicy(Of HttpResponseMessage)), keySelector As Func(Of HttpRequestMessage, String)) As IHttpClientBuilder

Parameters

policyFactory
Func<IServiceProvider,HttpRequestMessage,String,IAsyncPolicy<HttpResponseMessage>>

Selects an IAsyncPolicy`1 to apply to the current request based on key selection.

keySelector
Func<HttpRequestMessage,String>

A delegate used to generate a policy key based on the HttpRequestMessage.

Returns

An IHttpClientBuilder that can be used to configure the client.

Remarks

Key generated by policyFactory is first used to lookup existing policies from IPolicyRegistry. If policy does not exist in the registry, create a new policy with policyFactory and add it in IPolicyRegistry.

See the remarks on PolicyHttpMessageHandler for guidance on configuring policies.

Applies to