PollyHttpClientBuilderExtensions.AddPolicyHandler 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重载
AddPolicyHandler(IHttpClientBuilder, IAsyncPolicy<HttpResponseMessage>) |
添加 PolicyHttpMessageHandler,它将使用提供的 IAsyncPolicy`1 将请求执行涵盖在内。 |
AddPolicyHandler(IHttpClientBuilder, Func<IServiceProvider,HttpRequestMessage,IAsyncPolicy<HttpResponseMessage>>) |
添加 PolicyHttpMessageHandler,它将使用 |
AddPolicyHandler(IHttpClientBuilder, Func<HttpRequestMessage,IAsyncPolicy<HttpResponseMessage>>) |
添加 PolicyHttpMessageHandler,它将使用 |
AddPolicyHandler(IHttpClientBuilder, Func<IServiceProvider,HttpRequestMessage, String,IAsyncPolicy<HttpResponseMessage>>, Func<HttpRequestMessage, String>) |
添加一个 , PolicyHttpMessageHandler 它将使用通过执行提供的密钥选择逻辑 |
AddPolicyHandler(IHttpClientBuilder, IAsyncPolicy<HttpResponseMessage>)
添加 PolicyHttpMessageHandler,它将使用提供的 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
参数
- builder
- IHttpClientBuilder
返回
可用于配置客户端的 IHttpClientBuilder。
注解
有关配置策略的指导,请参阅 上的 PolicyHttpMessageHandler 说明。
适用于
AddPolicyHandler(IHttpClientBuilder, Func<IServiceProvider,HttpRequestMessage,IAsyncPolicy<HttpResponseMessage>>)
添加 PolicyHttpMessageHandler,它将使用 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
参数
- builder
- IHttpClientBuilder
- policySelector
- Func<IServiceProvider,HttpRequestMessage,IAsyncPolicy<HttpResponseMessage>>
选择要应用到当前请求的 IAsyncPolicy`1。
返回
可用于配置客户端的 IHttpClientBuilder。
注解
有关配置策略的指导,请参阅 上的 PolicyHttpMessageHandler 说明。
适用于
AddPolicyHandler(IHttpClientBuilder, Func<HttpRequestMessage,IAsyncPolicy<HttpResponseMessage>>)
添加 PolicyHttpMessageHandler,它将使用 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
参数
- builder
- IHttpClientBuilder
- policySelector
- Func<HttpRequestMessage,IAsyncPolicy<HttpResponseMessage>>
选择要应用到当前请求的 IAsyncPolicy`1。
返回
可用于配置客户端的 IHttpClientBuilder。
注解
有关配置策略的指导,请参阅 上的 PolicyHttpMessageHandler 说明。
适用于
AddPolicyHandler(IHttpClientBuilder, Func<IServiceProvider,HttpRequestMessage, String,IAsyncPolicy<HttpResponseMessage>>, Func<HttpRequestMessage, String>)
添加一个 , PolicyHttpMessageHandler 它将使用通过执行提供的密钥选择逻辑 keySelector
和 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
参数
- builder
- IHttpClientBuilder
- policyFactory
- Func<IServiceProvider,HttpRequestMessage,String,IAsyncPolicy<HttpResponseMessage>>
根据所选密钥选择要应用于当前请求的 IAsyncPolicy`1。
- keySelector
- Func<HttpRequestMessage,String>
用于根据 HttpRequestMessage 生成策略密钥的委托。
返回
可用于配置客户端的 IHttpClientBuilder。
注解
生成的 policyFactory
密钥首先用于从 IPolicyRegistry 查找现有策略。 如果注册表中不存在策略,请使用 policyFactory
创建一个新策略,并将其添加到 IPolicyRegistry 中。
有关配置策略的指导,请参阅 上的 PolicyHttpMessageHandler 说明。