使用asp.net核心在HttpRequestMessage和HttpResponseMessage上调用Dispose(或不调用)的最佳实践是什么?
例子:
protected override async Task<AuthenticationTicket> CreateTicketAsync(ClaimsIdentity identity, AuthenticationProperties properties, OAuthTokenResponse tokens)
{
// Get the Google user
var request = new HttpRequestMessage(HttpMethod.Get, Options.UserInformationEndpoint);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokens.AccessToken);
var response = await Backchannel.SendAsync(request, Context.RequestAborted);
response.EnsureSuccessStatusCode();
var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
...
}
Run Code Online (Sandbox Code Playgroud)
和
https://github.com/aspnet/Security/blob/1.0.0/src/Microsoft.AspNetCore.Authentication.Facebook/FacebookHandler.cs#L37-L40
这两个例子都没有调用Dispose
这可能是遗漏吗?或者它背后是否有正当理由,可能是因为该方法是异步的?当然,CG最终会最终确定它们,但这是在这种情况下这样做的最佳做法,为什么?请注意,上面的示例是ASP.NET Core Middleware组件的一部分.