c# - Azure IoT 中心的RegistryManager 和服务客户​​端- 单例与否?

标签 c# azure azure-iot-hub

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>.

https://github.com/Azure/azure-iot-sdk-csharp/pull/2423

关于c# - Azure IoT 中心的RegistryManager 和服务客户​​端- 单例与否?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72455338/

相关文章:

azure - Azure Web应用程序部署时出错

java - 使用 x509 正确配置 Azure IoT 中心 DPS 组注册

c# - 如何检索和更新服务的 Azure 配置文件?

Mysql 数据库大小增长超过 4 TB? Azure 最多支持 4 个

wcf - 使用 RESTSharp 上传图像(addFile)

适用于 Windows 服务的 Azure IoT 中心包更新

python - 在 Python 中为 Azure IoT 中心生成具有到期日的 SAS token

c# - 有没有更简单的方法来解析和解决 C# 中的表达式?

c# - 如果两个类继承一个静态字段,那么这些类的对象是否将共享相同的值?

c# - 在 C# 中将 View 组件的结果作为字符串返回