I have a C # library that makes calls for a relaxed web service using HttpClient.
The class library is used inside the MVC application, which can run for several weeks without restarting.
Is singleton a good way to create an HttpClient, so I only have one HttpClient for a very long lifetime MVC application?
I singleton will save the HttpClientapplication for life, but I would ask why you want to do this. This is not a good practice.
HttpClient
HttpClient IDisposable, , . using :
IDisposable
using (var client = new HttpClient()) { // Do something }
, , , . HttpClient , .
HttpClient?
. HttpClient, :
"HttpClient - . HttpClient HTTP-, HttpClient, ."
, singleton HttpClient, , :
CancelPendingRequests DeleteAsync GetAsync GetByteArrayAsync GetStreamAsync GetStringAsync PostAsync PutAsync SendAsync
: