using GFramework.Core.Abstractions.Cqrs; using GFramework.Core.Abstractions.Rule; using GFramework.Core.Cqrs.Extensions; namespace GFramework.Core.Extensions; /// /// 提供对 接口的 CQRS 统一接口扩展方法。 /// 该类型保留旧名称以兼容历史调用点;新代码应改用 。 /// [Obsolete("Use GFramework.Core.Cqrs.Extensions.ContextAwareCqrsExtensions instead.")] public static class ContextAwareMediatorExtensions { /// /// 发送请求(统一处理 Command/Query) /// /// 响应类型 /// 实现 IContextAware 接口的对象 /// 要发送的请求 /// 取消令牌 /// 请求结果 /// 当 contextAware 或 request 为 null 时抛出 public static ValueTask SendRequestAsync(this IContextAware contextAware, IRequest request, CancellationToken cancellationToken = default) { return ContextAwareCqrsExtensions.SendRequestAsync( contextAware, request, cancellationToken); } /// /// 发送请求(同步版本,不推荐) /// /// 响应类型 /// 实现 IContextAware 接口的对象 /// 要发送的请求 /// 请求结果 /// 当 contextAware 或 request 为 null 时抛出 public static TResponse SendRequest(this IContextAware contextAware, IRequest request) { return ContextAwareCqrsExtensions.SendRequest(contextAware, request); } /// /// 发布通知(一对多事件) /// /// 通知类型 /// 实现 IContextAware 接口的对象 /// 要发布的通知 /// 取消令牌 /// 异步任务 /// 当 contextAware 或 notification 为 null 时抛出 public static ValueTask PublishAsync(this IContextAware contextAware, TNotification notification, CancellationToken cancellationToken = default) where TNotification : INotification { return ContextAwareCqrsExtensions.PublishAsync( contextAware, notification, cancellationToken); } /// /// 创建流式请求(用于大数据集) /// /// 响应类型 /// 实现 IContextAware 接口的对象 /// 流式请求 /// 取消令牌 /// 异步响应流 /// 当 contextAware 或 request 为 null 时抛出 public static IAsyncEnumerable CreateStream(this IContextAware contextAware, IStreamRequest request, CancellationToken cancellationToken = default) { return ContextAwareCqrsExtensions.CreateStream( contextAware, request, cancellationToken); } /// /// 发送命令(无返回值) /// /// 命令类型 /// 实现 IContextAware 接口的对象 /// 要发送的命令 /// 取消令牌 /// 异步任务 /// 当 contextAware 或 command 为 null 时抛出 public static ValueTask SendAsync(this IContextAware contextAware, TCommand command, CancellationToken cancellationToken = default) where TCommand : IRequest { return ContextAwareCqrsExtensions.SendAsync( contextAware, command, cancellationToken); } /// /// 发送命令(有返回值) /// /// 响应类型 /// 实现 IContextAware 接口的对象 /// 要发送的命令 /// 取消令牌 /// 命令执行结果 /// 当 contextAware 或 command 为 null 时抛出 public static ValueTask SendAsync(this IContextAware contextAware, IRequest command, CancellationToken cancellationToken = default) { return ContextAwareCqrsExtensions.SendAsync( contextAware, command, cancellationToken); } }