// Copyright (c) 2025-2026 GeWuYou // SPDX-License-Identifier: Apache-2.0 using GFramework.Cqrs.Abstractions.Cqrs; namespace GFramework.Cqrs.Notification; /// /// 通过内部回调桥接 dispatcher 执行逻辑的通知发布上下文。 /// /// 通知类型。 /// 执行单个处理器所需的内部状态类型。 internal sealed class DelegatingNotificationPublishContext : NotificationPublishContext where TNotification : INotification { private readonly NotificationHandlerExecutor _handlerExecutor; private readonly TState _state; /// /// 初始化一个委托驱动的通知发布上下文。 /// /// 当前通知。 /// 当前发布调用已解析到的处理器集合。 /// 执行处理器时需要的内部状态。 /// 执行单个处理器时调用的内部回调。 /// /// 。 /// internal DelegatingNotificationPublishContext( TNotification notification, IReadOnlyList handlers, TState state, NotificationHandlerExecutor handlerExecutor) : base(notification, handlers) { ArgumentNullException.ThrowIfNull(handlerExecutor); _state = state; _handlerExecutor = handlerExecutor; } /// /// 通过默认 dispatcher 提供的内部回调执行单个处理器。 /// /// 要执行的处理器实例。 /// 取消令牌。 /// 表示当前处理器执行完成的值任务。 /// public override ValueTask InvokeHandlerAsync(object handler, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(handler); return _handlerExecutor(handler, Notification, _state, cancellationToken); } }