Edition 0 Updated to asp. Net core 0


Benefits of using IHttpClientFactory



Yüklə 11,82 Mb.
Pdf görüntüsü
səhifə256/288
tarix12.07.2023
ölçüsü11,82 Mb.
#136458
1   ...   252   253   254   255   256   257   258   259   ...   288
Benefits of using IHttpClientFactory 
The current implementation of 
IHttpClientFactory
, that also implements 
IHttpMessageHandlerFactory

offers the following benefits: 

Provides a central location for naming and configuring logical 
HttpClient
objects. For example, 
you may configure a client (Service Agent) that’s pre
-configured to access a specific 
microservice. 

Codify the concept of outgoing middleware via delegating handlers in 
HttpClient
and 
implementing Polly-
based middleware to take advantage of Polly’s policies for resiliency.

HttpClient
already has the concept of delegating handlers that could be linked together for 
outgoing HTTP requests. You can register HTTP clients into the factory and you can use a Polly 
handler to use Polly policies for Retry, CircuitBreakers, and so on. 

Manage the lifetime of 
HttpMessageHandler
 to avoid the mentioned problems/issues that can 
occur when managing 
HttpClient
lifetimes yourself. 
Tip 
The 
HttpClient
instances injected by DI can be disposed of safely, because the associated 
HttpMessageHandler
is managed by the factory. Injected 
HttpClient
instances are 
Transient
from a 
DI perspective, while 
HttpMessageHandler
instances can be regarded as 
Scoped

HttpMessageHandler
instances have their own DI scopes, 
separate
from the application scopes (for example, ASP.NET 
incoming request scopes). For more information, see 
Using HttpClientFactory in .NET



301 
CHAPTER 7 | Implement resilient applications 
Note 
The implementation of 
IHttpClientFactory
(
DefaultHttpClientFactory
) is tightly tied to the DI 
implementation in the 
Microsoft.Extensions.DependencyInjection
NuGet package. If you need to 
use 
HttpClient
without DI or with other DI implementations, consider using a 
static
or singleton 
HttpClient
with 
PooledConnectionLifetime
set up. For more information, see 
HttpClient guidelines 
for .NET


Yüklə 11,82 Mb.

Dostları ilə paylaş:
1   ...   252   253   254   255   256   257   258   259   ...   288




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin