Based on on this site and also on I came to the conclusion that I should not use the class HttpClient
in a using
block even though it implements IDisposable
. This would help reuse 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://pt.stackoverflow.com");
// ...
}
}
My API is consuming another service, but if when we talk about the MyServiceController
lifecycle, there would be no reuse since every request of Post
will create a new instance of the class, correct? In that case could I normally implement using the block using
?