IoT 中心服务 SDK 是否应该 RegistryManager (和 ServiceClient )用作单例(HttpClient 模式)或者是 using var registryManager = ...
首选?
更多
查看RegistryManager的source code它创建自己的 HttpClientHelper 的非静态实例它创建了自己的 HttpClient
的非静态实例这看起来像是一个反模式。这表明RegistryManager 的一个实例是首选,并且查看其代码让我认为多个用户应该没问题。
但是,我无法对一份说明 RegistryManager
的一个实例的文档进行罚款。应该用作整个应用程序的单例。
最佳答案
现已记录此内容
/// This client creates lifetime long instances of <see cref="HttpClient"/> that are tied to the URI of the
/// IoT hub specified, configure any proxy settings, and connection lease timeout.
/// For that reason, the instances are not static and an application using this client
/// should create and save it for all use. Repeated creation may cause
/// <see href="https://learn.microsoft.com/azure/architecture/antipatterns/improper-instantiation/">socket exhaustion</see>.
关于c# - Azure IoT 中心的RegistryManager 和服务客户端- 单例与否?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72455338/