// 摘自 MediatR 14.2.0,许可声明与修改记录见 LICENSE.md 和 UPSTREAM.md。
using System.Threading;
using System.Threading.Tasks;
namespace MAX.Notification;
///
/// 定义通知处理器。
///
/// 要处理的通知类型。
public interface INotificationHandler
where TNotification : INotification
{
///
/// 处理通知。
///
/// 要处理的通知。
/// 取消令牌。
Task Handle(TNotification notification, CancellationToken cancellationToken);
}
///
/// 同步通知处理器的基类。
///
/// 通知类型。
public abstract class NotificationHandler : INotificationHandler
where TNotification : INotification
{
Task INotificationHandler.Handle(TNotification notification, CancellationToken cancellationToken)
{
Handle(notification);
return Task.CompletedTask;
}
///
/// 在派生类中重写此方法,实现同步通知处理逻辑。
///
/// 要处理的通知。
protected abstract void Handle(TNotification notification);
}