C
C#

help

HttpClient DI or USING()

VVinicius10/14/2022
Which one is the best, Dependency injection or instance by using
VVinicius10/14/2022
I will use this althrough my service
Eero10/14/2022
will you be using clients a lot throughout your app?
VVinicius10/14/2022
specific in one service
CCisien10/14/2022
Avoid using
Eero10/14/2022
i'd just have one static client then
CCisien10/14/2022
Keep the client around for a long time There are tradeoffs to be aware of.keeping a client around a long time can lead to issues with dns Clients cache dns resolutions and dont refresh the cache But disposing the http handler frequently leads to resource exhaustion
VVinicius10/14/2022
Request wont be frequently
CCisien10/14/2022
The solution is the Microsoft.Extensions.HttpClientFactory nuget
UUUnknown User10/14/2022
Message Not Public
Sign In & Join Server To View
CCisien10/14/2022
If its infrequent, as in less than once every minute or two than its fine
VVinicius10/14/2022
you mean its fine DI ?
CCisien10/14/2022
Yeah, use di
UUUnknown User10/14/2022
3 Messages Not Public
Sign In & Join Server To View
CCisien10/14/2022
If its frequent, register as singleton, otherwise transient HttpClientFactory is nice because it makes it easy to set up specific http clients for each service you need
VVinicius10/14/2022
I need to do dispose or something specific ?
CCisien10/14/2022
Not in di Di handles the dispose
VVinicius10/14/2022
awesome
UUUnknown User10/14/2022
Message Not Public
Sign In & Join Server To View
VVinicius10/14/2022
thanks a lot
UUUnknown User10/14/2022
Message Not Public
Sign In & Join Server To View
VVinicius10/14/2022
already did by this way?

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
Wanna make a program were people get infected by a disease [Answered]if one person is infected i want him to infect someone else and that else to infect another one, andError validation [Answered]``` [Required] [MinLength(8, ErrorMessage = "Password too short")] [MaxLength(32, ErrorMesSignalR ConnectionManager SingletonHey, does anyone have any experience creating a ConnectionManager for SignalR? Right now I feel likeTask.Run swallows the exceptions [Answered]Pretty self explanatory. The minimal reproducible example throws an exception in the `Task.Run(...)`MSBUILD Tools error with npm installI am trying to run `npm install` on an Angular app. The earliest error with any useful information iChocolatey has Generic MSI ErrorI'm trying to use chocolatey to install the vcbuildtools package, and it spits out first the followi'The viewmanager.activeview must be a view contained within the viewmanager.window profile'What's causing this error? Googling it throws a bunch of threads without any conclusive responses IAny way to declare these variables more efficiently?Just curious as it doesnt look too cleanWhy is mscorlib 2.0 an ExplicitReference in the Initial Items when running msbuild? [Answered]I'm trying to build a project that has some dependencies on `mscorlib` version 4.0, but something abWhat's the difference between these two libraries? [Answered]In nuget there are two completely different .data.SQLclient libraries which seem to do the same thinContactForm Not Sending Me GmailI recently had to reset my PC, but made no changes to my code. Took me awhile to get my code up andWhy are out parameters inside an if statement condition not local to the if block? [Answered]```cs if (dictionary.TryGetValue(key, out var val)) { } // why can I access val here? ``` Is thiCannot set readonly field in inherited constructor [Answered]Title says it all really, I'm not really sure why given this is clearly a constructor. ```cs public AddHostedService Implementation choosen on startupI was fiddling around with a solution to add 1 HostedService, depending on a enum value(config settiData Reading SuggestionGood afternoon, I have a text file filled with data that I am not meant to directly change. I need tUpdate Variable Between ScriptsHey there, this isnt my first time updating between scripts so I dont entirely know the issue. I havWPF revalidate the object on any property change [Answered]```xml <DataGridTemplateColumn Header="Has Owner"> <DataGridTemplateColumn.CellTemplate> Cannot create comparer [Answered]I'm trying to make a comparer to pass around but it's refusing to let me define it. Here's the code Net core 6 Web api update-add collections to a created entity [Answered]I am trying to update an entity that has a collection, when creating it with 1 item in the collectioAdding a library [Answered]Hello. I very rarely work in the console, but now I've started doing so I've found myself needing to