EventGridClient:它应该被处理掉吗?

EventGridClient: should it be disposed?

Azure 的 EventGridClient 实现了 IDisposable 接口。

用完后要dispose吗?

using (var client = new EventGridClient(_topicCredentials))
{
     await client.PublishEventsAsync(_topicHostName, events);
}

或者只有:

var client = new EventGridClient(_topicCredentials)
await client.PublishEventsAsync(_topicHostName, events);

在 Microsoft 的非常基本的示例中是第二种情况。

我知道如果 HttpClient 是由 IHttpClientFactory 创建的,则不应将其丢弃,因为在那种情况下会重用连接。但是,没有关于 EventGridClient 如何管理连接的信息。

此外,在Asp.Net核心应用中应该是TransientScoped还是Singleton

根据源代码,它会自动处理连接。请参阅 this line of code in PublishEventsWithHttpMessagesAsync method(the PublishEventsAsync 方法在内部调用此方法)。所以不需要添加 using statement.

这是您的答案 - 在 github source code here

的评论中

True: will dispose the provided httpClient on calling EventGridClient.Dispose(). False: will not dispose provided httpClient