Dispose of Injected HttpClient
问题 Our MVC application calls a WebAPI action using HttpClient. I decided to inject the HttpClient using StructureMap and override dispose in the controller public HomeController(HttpClient httpClient) { _httpClient = httpClient; } protected override void Dispose(bool disposing) { if (disposing && _httpClient != null) { _httpClient.Dispose(); } base.Dispose(disposing); } The StructureMap ObjectInitialize basically looks like this.. x.For<HttpClient>().Use(() => new HttpClient() { BaseAddress =