Answer
Ove
rf
low
Sign In With Discord
C#
help
Join
Root Question Message
VINI JR
10/14/2022
HttpClient DI or USING()
Which one is the best, Dependency injection or instance by using
VINI JR
10/14/2022
I will use this althrough my service
Ero
10/14/2022
will you be using clients a lot throughout your app?
VINI JR
10/14/2022
specific in one service
Cisien
10/14/2022
Avoid using
Ero
10/14/2022
i'd just have one static client then
Cisien
10/14/2022
Keep the client around for a long time
Cisien
10/14/2022
There are tradeoffs to be aware of.keeping a client around a long time can lead to issues with dns
Cisien
10/14/2022
Clients cache dns resolutions and dont refresh the cache
Cisien
10/14/2022
But disposing the http handler frequently leads to resource exhaustion
VINI JR
10/14/2022
Request wont be frequently
Cisien
10/14/2022
The solution is the Microsoft.Extensions.HttpClientFactory nuget
Message Not Public
Sign In and Join Server To See
10/14/2022
Cisien
10/14/2022
If its infrequent, as in less than once every minute or two than its fine
VINI JR
10/14/2022
you mean its fine DI ?
Cisien
10/14/2022
Yeah, use di
Message Not Public
Sign In and Join Server To See
10/14/2022
Message Not Public
Sign In and Join Server To See
10/14/2022
Message Not Public
Sign In and Join Server To See
10/14/2022
Cisien
10/14/2022
If its frequent, register as singleton, otherwise transient
Cisien
10/14/2022
HttpClientFactory is nice because it makes it easy to set up specific http clients for each service you need
VINI JR
10/14/2022
I need to do dispose or something specific ?
Cisien
10/14/2022
Not in di
Cisien
10/14/2022
Di handles the dispose
VINI JR
10/14/2022
awesome
Message Not Public
Sign In and Join Server To See
10/14/2022
VINI JR
10/14/2022
thanks a lot
Message Not Public
Sign In and Join Server To See
10/14/2022
VINI JR
10/14/2022
already did by this way?
Contact
Frequently Asked Questions
Join The Discord
Bugs & Feature Requests
Terms & Privacy