|
18 | 18 | <Docs> |
19 | 19 | <summary>A <see cref="T:System.Net.Http.DelegatingHandler" /> implementation that executes request processing surrounded by a <see cref="T:Polly.Policy" />.</summary> |
20 | 20 | <remarks> |
21 | | - <para> |
22 | | - This message handler implementation supports the use of policies provided by the Polly library for |
23 | | - transient-fault-handling and resiliency. |
24 | | - </para> |
25 | | - <para> |
26 | | - The documentation provided here is focused guidance for using Polly together with the <see cref="T:System.Net.Http.IHttpClientFactory" />. |
27 | | - See the Polly project and its documentation (https://github.com/app-vnext/Polly) for authoritative information on Polly. |
28 | | - </para> |
29 | | - <para> |
30 | | - The extension methods on <see cref="T:Microsoft.Extensions.DependencyInjection.PollyHttpClientBuilderExtensions" /> are designed as a convenient and correct |
31 | | - way to create a <see cref="T:Microsoft.Extensions.Http.PolicyHttpMessageHandler" />. |
32 | | - </para> |
33 | | - <para> |
34 | | - The <see cref="M:Microsoft.Extensions.DependencyInjection.PollyHttpClientBuilderExtensions.AddPolicyHandler(Microsoft.Extensions.DependencyInjection.IHttpClientBuilder,Polly.IAsyncPolicy{System.Net.Http.HttpResponseMessage})" /> |
35 | | - method supports the creation of a <see cref="T:Microsoft.Extensions.Http.PolicyHttpMessageHandler" /> for any kind of policy. This includes |
36 | | - non-reactive policies, such as Timeout or Cache, which don't require the underlying request to fail first. |
37 | | - </para> |
38 | | - <para> |
39 | | - <see cref="T:Microsoft.Extensions.Http.PolicyHttpMessageHandler" /> and the <see cref="T:Microsoft.Extensions.DependencyInjection.PollyHttpClientBuilderExtensions" /> convenience methods |
40 | | - only accept the generic <see cref="T:Polly.IAsyncPolicy`1" />. Generic policy instances can be created |
41 | | - by using the generic methods on <see cref="T:Polly.Policy" /> such as <see cref="M:Polly.Policy.TimeoutAsync``1(System.Int32)" />. |
42 | | - </para> |
43 | | - <para> |
44 | | - To adapt an existing non-generic <see cref="T:Polly.IAsyncPolicy" />, use code like the following: |
45 | | - <example> |
46 | | - Converting a non-generic <c>IAsyncPolicy policy</c> to <see cref="T:Polly.IAsyncPolicy`1" />. |
47 | | - <code> |
48 | | - policy.AsAsyncPolicy<HttpResponseMessage>() |
49 | | - </code></example></para> |
50 | | - <para> |
51 | | - The <see cref="M:Microsoft.Extensions.DependencyInjection.PollyHttpClientBuilderExtensions.AddTransientHttpErrorPolicy(Microsoft.Extensions.DependencyInjection.IHttpClientBuilder,System.Func{Polly.PolicyBuilder{System.Net.Http.HttpResponseMessage},Polly.IAsyncPolicy{System.Net.Http.HttpResponseMessage}})" /> |
52 | | - method is an opinionated convenience method that supports the application of a policy for requests that fail due |
53 | | - to a connection failure or server error (5XX HTTP status code). This kind of method supports only reactive policies |
54 | | - such as Retry, Circuit-Breaker or Fallback. This method is only provided for convenience; we recommend creating |
55 | | - your own policies as needed if this does not meet your requirements. |
56 | | - </para> |
57 | | - <para> |
58 | | - Take care when using policies such as Retry or Timeout together as HttpClient provides its own timeout via |
59 | | - <see cref="P:System.Net.Http.HttpClient.Timeout" />. When combining Retry and Timeout, <see cref="P:System.Net.Http.HttpClient.Timeout" /> will act as a |
60 | | - timeout across all tries; a Polly Timeout policy can be configured after a Retry policy in the configuration sequence, |
61 | | - to provide a timeout-per-try. |
62 | | - </para> |
63 | | - <para> |
64 | | - All policies provided by Polly are designed to be efficient when used in a long-lived way. Certain policies such as the |
65 | | - Bulkhead and Circuit-Breaker maintain state and should be scoped across calls you wish to share the Bulkhead or Circuit-Breaker state. |
66 | | - Take care to ensure the correct lifetimes when using policies and message handlers together in custom scenarios. The extension |
67 | | - methods provided by <see cref="T:Microsoft.Extensions.DependencyInjection.PollyHttpClientBuilderExtensions" /> are designed to assign a long lifetime to policies |
68 | | - and ensure that they can be used when the handler rotation feature is active. |
69 | | - </para> |
70 | | - <para> |
71 | | - The <see cref="T:Microsoft.Extensions.Http.PolicyHttpMessageHandler" /> will attach a context to the <see cref="T:System.Net.Http.HttpRequestMessage" /> prior |
72 | | - to executing a <see cref="T:Polly.Policy" />, if one does not already exist. The <see cref="T:Polly.Context" /> will be provided |
73 | | - to the policy for use inside the <see cref="T:Polly.Policy" /> and in other message handlers. |
74 | | - </para> |
| 21 | + <format type="text/markdown">< for authoritative information on Polly. |
| 27 | +
|
| 28 | +The extension methods on <xref:Microsoft.Extensions.DependencyInjection.PollyHttpClientBuilderExtensions> are designed as a convenient and correct way to create a <xref:Microsoft.Extensions.Http.PolicyHttpMessageHandler>. |
| 29 | +
|
| 30 | +The <xref:Microsoft.Extensions.DependencyInjection.PollyHttpClientBuilderExtensions.AddPolicyHandler(Microsoft.Extensions.DependencyInjection.IHttpClientBuilder,Polly.IAsyncPolicy{System.Net.Http.HttpResponseMessage})> method supports the creation of a <xref:Microsoft.Extensions.Http.PolicyHttpMessageHandler> for any kind of policy. This includes non-reactive policies, such as Timeout or Cache, which don't require the underlying request to fail first. |
| 31 | +
|
| 32 | +<xref:Microsoft.Extensions.Http.PolicyHttpMessageHandler> and the <xref:Microsoft.Extensions.DependencyInjection.PollyHttpClientBuilderExtensions> convenience methods only accept the generic <xref:Polly.IAsyncPolicy`1>. Generic policy instances can be created by using the generic methods on <xref:Polly.Policy> such as <xref:Polly.Policy.TimeoutAsync``1(System.Int32)>. |
| 33 | +
|
| 34 | +To adapt an existing non-generic <xref:Polly.IAsyncPolicy>, use code like the following: |
| 35 | + |
| 36 | +``` |
| 37 | +policy.AsAsyncPolicy<HttpResponseMessage>() |
| 38 | +``` |
| 39 | +
|
| 40 | +The <xref:Microsoft.Extensions.DependencyInjection.PollyHttpClientBuilderExtensions.AddTransientHttpErrorPolicy(Microsoft.Extensions.DependencyInjection.IHttpClientBuilder,System.Func{Polly.PolicyBuilder{System.Net.Http.HttpResponseMessage},Polly.IAsyncPolicy{System.Net.Http.HttpResponseMessage}})> method is an opinionated convenience method that supports the application of a policy for requests that fail due to a connection failure or server error (5XX HTTP status code). This kind of method supports only reactive policies such as Retry, Circuit-Breaker or Fallback. This method is only provided for convenience; we recommend creating your own policies as needed if this does not meet your requirements. |
| 41 | +
|
| 42 | +Take care when using policies such as Retry or Timeout together, as HttpClient provides its own timeout via <xref:System.Net.Http.HttpClient.Timeout>. When combining Retry and Timeout, <xref:System.Net.Http.HttpClient.Timeout> will act as a timeout across all tries; a Polly Timeout policy can be configured after a Retry policy in the configuration sequence, to provide a timeout-per-try. |
| 43 | +
|
| 44 | +All policies provided by Polly are designed to be efficient when used in a long-lived way. Certain policies such as the Bulkhead and Circuit-Breaker maintain state and should be scoped across calls you wish to share the Bulkhead or Circuit-Breaker state. Take care to ensure the correct lifetimes when using policies and message handlers together in custom scenarios. The extension methods provided by <xref:Microsoft.Extensions.DependencyInjection.PollyHttpClientBuilderExtensions> are designed to assign a long lifetime to policies and ensure that they can be used when the handler rotation feature is active. |
| 45 | +
|
| 46 | +The <xref:Microsoft.Extensions.Http.PolicyHttpMessageHandler> will attach a context to the <xref:System.Net.Http.HttpRequestMessage> prior to executing a <xref:Polly.Policy>, if one does not already exist. The <xref:Polly.Context> will be provided to the policy for use inside the <xref:Polly.Policy> and in other message handlers. |
| 47 | + ]]></format> |
75 | 48 | </remarks> |
76 | 49 | </Docs> |
77 | 50 | <Members> |
|
0 commit comments