Files
DMS/DMS.Infrastructure/Services/Mqtt/MqttServiceFactory.cs

44 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using DMS.Infrastructure.Interfaces.Services;
using Microsoft.Extensions.Logging;
namespace DMS.Infrastructure.Services.Mqtt
{
/// <summary>
/// MQTT服务工厂实现类用于创建MQTT服务实例
/// </summary>
public class MqttServiceFactory : IMqttServiceFactory
{
private readonly ILogger<MqttService> _logger;
/// <summary>
/// 构造函数,注入日志记录器
/// </summary>
/// <param name="logger">MQTT服务日志记录器</param>
public MqttServiceFactory(ILogger<MqttService> logger)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
/// <summary>
/// 创建MQTT服务实例
/// </summary>
/// <returns>IMqttService实例</returns>
public IMqttService CreateService()
{
return new MqttService(_logger);
}
/// <summary>
/// 根据MQTT服务器配置创建MQTT服务实例
/// </summary>
/// <param name="mqttServer">MQTT服务器配置</param>
/// <returns>IMqttService实例</returns>
public IMqttService CreateService(Core.Models.MqttServer mqttServer)
{
if (mqttServer == null)
throw new ArgumentNullException(nameof(mqttServer));
return new MqttService(_logger);
}
}
}