PollyHttpClientBuilderExtensions.AddPolicyHandler 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
AddPolicyHandler(IHttpClientBuilder, IAsyncPolicy<HttpResponseMessage>) |
新增 PolicyHttpMessageHandler,其會將提供的 IAsyncPolicy`1 以要求執行括住。 |
AddPolicyHandler(IHttpClientBuilder, Func<IServiceProvider,HttpRequestMessage,IAsyncPolicy<HttpResponseMessage>>) |
新增會以 |
AddPolicyHandler(IHttpClientBuilder, Func<HttpRequestMessage,IAsyncPolicy<HttpResponseMessage>>) |
新增會以 |
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>>)
新增會以 policySelector
所傳回原則括住要求執行的 PolicyHttpMessageHandler。
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>>)
新增會以 policySelector
所傳回原則括住要求執行的 PolicyHttpMessageHandler。
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 備註。