Skip to content

Commit 8844aab

Browse files
Adding an example of a HttpMessageHandler's Lifetime to 5 minutes in the pool. The default lifetime of HttpMessageHandler instances in the pool is 2 minutes.
1 parent 460fc99 commit 8844aab

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/Web/WebMVC/Startup.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,12 @@ public static IServiceCollection AddHttpClientServices(this IServiceCollection s
182182
services.AddTransient<HttpClientAuthorizationDelegatingHandler>();
183183
services.AddTransient<HttpClientRequestIdDelegatingHandler>();
184184

185-
//add http client servicse
185+
services.AddHttpClient("extendedhandlerlifetime").SetHandlerLifetime(TimeSpan.FromMinutes(5));
186+
187+
//add http client services
186188
services.AddHttpClient<IBasketService, BasketService>()
187189
.AddHttpMessageHandler<HttpClientAuthorizationDelegatingHandler>()
190+
.SetHandlerLifetime(TimeSpan.FromMinutes(5)) //Sample. Default lifetime is 2 minutes
188191
.AddPolicyHandler(retriesWithExponentialBackoff)
189192
.AddPolicyHandler(circuitBreaker);
190193

0 commit comments

Comments
 (0)