namespace Evergreen.Health.Application.Health.Scenes; public interface ILightOffHandler { Task HandleAsync(CancellationToken cancellationToken); } /// 跨设备联动由场景层分发;灯具不需要知道其他家具实体。 public sealed class LightOffDispatcher { private readonly IReadOnlyList _handlers; public LightOffDispatcher(IEnumerable handlers) => _handlers = handlers.ToArray(); public async Task NotifyAsync(CancellationToken cancellationToken) { var failures = new List(); foreach (var handler in _handlers) { cancellationToken.ThrowIfCancellationRequested(); try { await handler.HandleAsync(cancellationToken); } catch (Exception exception) when (exception is not OperationCanceledException) { failures.Add(exception); } } if (failures.Count > 0) throw new AggregateException("灯光已关闭,但部分安全联动未完成", failures); } }