C#
C#

help

Root Question Message

VINI JR
VINI JR10/14/2022
HttpClient DI or USING()

Which one is the best, Dependency injection or instance by using
VINI JR
VINI JR10/14/2022
I will use this althrough my service
Ero
Ero10/14/2022
will you be using clients a lot throughout your app?
VINI JR
VINI JR10/14/2022
specific in one service
Cisien
Cisien10/14/2022
Avoid using
Ero
Ero10/14/2022
i'd just have one static client then
Cisien
Cisien10/14/2022
Keep the client around for a long time
Cisien
Cisien10/14/2022
There are tradeoffs to be aware of.keeping a client around a long time can lead to issues with dns
Cisien
Cisien10/14/2022
Clients cache dns resolutions and dont refresh the cache
Cisien
Cisien10/14/2022
But disposing the http handler frequently leads to resource exhaustion
VINI JR
VINI JR10/14/2022
Request wont be frequently
Cisien
Cisien10/14/2022
The solution is the Microsoft.Extensions.HttpClientFactory nuget
Message Not Public

Sign In and Join Server To See

10/14/2022
Cisien
Cisien10/14/2022
If its infrequent, as in less than once every minute or two than its fine
VINI JR
VINI JR10/14/2022
you mean its fine DI ?
Cisien
Cisien10/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
Cisien10/14/2022
If its frequent, register as singleton, otherwise transient
Cisien
Cisien10/14/2022
HttpClientFactory is nice because it makes it easy to set up specific http clients for each service you need
VINI JR
VINI JR10/14/2022
I need to do dispose or something specific ?
Cisien
Cisien10/14/2022
Not in di
Cisien
Cisien10/14/2022
Di handles the dispose
VINI JR
VINI JR10/14/2022
awesome
Message Not Public

Sign In and Join Server To See

10/14/2022
VINI JR
VINI JR10/14/2022
thanks a lot
Message Not Public

Sign In and Join Server To See

10/14/2022
VINI JR
VINI JR10/14/2022
already did by this way?
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy