0% found this document useful (0 votes)
3 views

?????????????????

HttpClientFactory creates new HttpClient instances while reusing SocketsHttpHandler from a pool to optimize connection management and solve socket issues. It disposes of handlers after about 2 minutes to address DNS changes. HttpClientFactory also offers features like logical client configuration, support for Typed and Named Clients, and integration with different APIs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

?????????????????

HttpClientFactory creates new HttpClient instances while reusing SocketsHttpHandler from a pool to optimize connection management and solve socket issues. It disposes of handlers after about 2 minutes to address DNS changes. HttpClientFactory also offers features like logical client configuration, support for Typed and Named Clients, and integration with different APIs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Ajay Patel NET

HttpClientFactory

HttpClientFactory

instantiates

HttpClient

Use handler from pool

HttpMessageHandler
Pool

API
2
Ajay Patel

HttpClientFactory creates new HttpClient


instance.

But, instead of recreating


SocketsHttpHandler, it takes one from a pool.

SocketsHttpHandler call the API.

So, any request for a new HttpClient can share


a previously created handler thus connection
as well.

Reusing handler allows reusing underlying


connection, which solves the socket issue.
3
Ajay Patel

SocketsHttpHandler instance is only


around for about 2 mins, unless it’s in
use.

Disposing the handler after 2 mins


solves the DNS issue.

Once a new new instance of the handler


is used, DNS changes are taken into
account.
4
Ajay Patel

Using HttpClientFactory
5
Ajay Patel

Features of HttpClientFactory

HttpClientFactory provides a central location


for naming and configuring logical HttpClients.

Useful when you need to integrate with


different API’s from your client.

We can configure handlers and polices


through something like polly.

Supports Typed Clients for better


encapsulation and dependency injection.

Supports Named Client, allows for creating


clients with specific configurations.
Ajay Patel NET

Knowledge is
contagious,
let’s spread it!
DO YOU LIKE THIS POST?

REPOST IT!

THANKS FOR READING

You might also like