😎调整 MTQTT 服务注入与接口

This commit is contained in:
zuohuaijun 2025-02-20 13:04:05 +08:00
parent 42dc3b479f
commit 9a4407017d
3 changed files with 6 additions and 8 deletions

View File

@ -17,10 +17,10 @@ using System.Threading.Tasks;
/// <summary>
/// MQTT 服务
/// </summary>
public class MqttHostedService(IOptions<MqttOptions> mqttOptions, ISqlSugarClient db) : IHostedService, ITransient
public class MqttHostedService(IOptions<MqttOptions> mqttOptions, ISqlSugarClient db) : IHostedService, ISingleton
{
private const string ServerClientId = "Admin.NET.MQTT";
public MqttServer MqttServer { get; set; }
public static MqttServer MqttServer { get; set; }
private readonly MqttOptions _mqttOptions = mqttOptions.Value;
private readonly ISqlSugarClient _db = db;

View File

@ -12,10 +12,8 @@ namespace Admin.NET.Core.Service;
/// 系统 MQTT 服务 🧩
/// </summary>
[ApiDescriptionSettings(Order = 90, Description = "MQTT 服务")]
public class SysMqttService(MqttHostedService mqttHostedService) : IDynamicApiController, ITransient
public class SysMqttService() : IDynamicApiController, ITransient
{
private readonly MqttHostedService _mqttHostedService = mqttHostedService;
/// <summary>
/// 获取客户端列表 🔖
/// </summary>
@ -23,9 +21,9 @@ public class SysMqttService(MqttHostedService mqttHostedService) : IDynamicApiCo
[DisplayName("获取客户端列表")]
public async Task<IList<MqttClientStatus>> GetClients()
{
if (_mqttHostedService.MqttServer == null)
if (MqttHostedService.MqttServer == null)
throw Oops.Oh("【MQTT】服务未启动");
return await _mqttHostedService.MqttServer.GetClientsAsync();
return await MqttHostedService.MqttServer.GetClientsAsync();
}
}

View File

@ -74,7 +74,7 @@
"vue-router": "^4.5.0",
"vue-signature-pad": "^3.0.2",
"vue3-tree-org": "^4.2.2",
"vxe-pc-ui": "^4.3.90",
"vxe-pc-ui": "^4.3.91",
"vxe-table": "^4.10.0",
"vxe-table-plugin-element": "^4.0.4",
"vxe-table-plugin-export-xlsx": "^4.0.7",