1. 从 IDeviceManagementService 接口中移除了 OnDeviceChanged 事件

2. 在 DeviceManagementService 中添加了对 IEventService 的依赖
   3. 在 DeviceManagementService 的三个内存操作方法中,将直接事件触发改为通过 _eventService.RaiseDeviceChanged 方法触发
   4. EventService 本身已经实现了 OnDeviceChanged 事件和对应的 RaiseDeviceChanged 方法
This commit is contained in:
2025-10-01 18:15:51 +08:00
parent 2dda2029bd
commit 62ce7093cf
2 changed files with 7 additions and 13 deletions

View File

@@ -5,10 +5,7 @@ namespace DMS.Application.Interfaces.Management;
public interface IDeviceManagementService
{
/// <summary>
/// 当设备数据发生变化时触发
/// </summary>
event EventHandler<DeviceChangedEventArgs> OnDeviceChanged;
/// <summary>
/// 异步根据ID获取设备DTO。

View File

@@ -14,16 +14,13 @@ public class DeviceManagementService : IDeviceManagementService
{
private readonly IDeviceAppService _deviceAppService;
private readonly IAppDataStorageService _appDataStorageService;
private readonly IEventService _eventService;
/// <summary>
/// 当设备数据发生变化时触发
/// </summary>
public event EventHandler<DeviceChangedEventArgs> OnDeviceChanged;
public DeviceManagementService(IDeviceAppService deviceAppService,IAppDataStorageService appDataStorageService)
public DeviceManagementService(IDeviceAppService deviceAppService, IAppDataStorageService appDataStorageService, IEventService eventService)
{
_deviceAppService = deviceAppService;
_appDataStorageService = appDataStorageService;
_eventService = eventService;
}
/// <summary>
@@ -113,7 +110,7 @@ public class DeviceManagementService : IDeviceManagementService
{
if (_appDataStorageService.Devices.TryAdd(deviceDto.Id, deviceDto))
{
OnDeviceChanged?.Invoke(this,new DeviceChangedEventArgs(DataChangeType.Added, deviceDto));
_eventService.RaiseDeviceChanged(this, new DeviceChangedEventArgs(DataChangeType.Added, deviceDto));
}
}
@@ -123,7 +120,7 @@ public class DeviceManagementService : IDeviceManagementService
public void UpdateDeviceInMemory(DeviceDto deviceDto)
{
_appDataStorageService.Devices.AddOrUpdate(deviceDto.Id, deviceDto, (key, oldValue) => deviceDto);
OnDeviceChanged?.Invoke(this,new DeviceChangedEventArgs(DataChangeType.Updated, deviceDto));
_eventService.RaiseDeviceChanged(this, new DeviceChangedEventArgs(DataChangeType.Updated, deviceDto));
}
/// <summary>
@@ -145,7 +142,7 @@ public class DeviceManagementService : IDeviceManagementService
_appDataStorageService.Devices.TryRemove(deviceId, out _);
OnDeviceChanged?.Invoke(this,new DeviceChangedEventArgs(DataChangeType.Deleted, deviceDto));
_eventService.RaiseDeviceChanged(this, new DeviceChangedEventArgs(DataChangeType.Deleted, deviceDto));
}
}