3
Based on that website and also in some answers from Stackoverflow [en] I came to the conclusion that I shouldn’t use the class HttpClient in a block using despite the same implement IDisposable. This would help in the reuse of the already instantiated object and bring performance improvements among others.
But consider the following code snippet:
public class MyServiceController : ApiController
{
private static HttpClient _httpClient = new HttpClient();
public void Post()
{
// ...
var result = await _httpClient.GetAsync("https://answall.com");
// ...
}
}
My API is consuming another service, but if when we talk about the life cycle of MyServiceController, there would be no reuse since each request of the Post will create a new instance of the class, correct? In that case I could implement normally using the block using?
If you make it public and start at startup
– Leandro Angelo
@Leandroangelo thanks for your comment. Leaving the
HttpClientclass audiencestartupcould not bring me trouble ifMyServiceControllerreceive many simultaneous requests?– Jedaias Rodrigues