GFramework/GFramework.Core/Extensions/ContextAwareMediatorCommandExtensions.cs
GeWuYou a80ff59631 feat(cqrs): 添加CQRS运行时模块和兼容性扩展
- 新增ContextAwareMediatorCommandExtensions提供命令扩展方法的兼容性别名
- 新增ContextAwareMediatorExtensions提供CQRS统一接口扩展方法的兼容性别名
- 新增ContextAwareMediatorQueryExtensions提供查询扩展方法的兼容性别名
- 添加CqrsRuntimeModule用于注册CQRS运行时和处理器注册器到依赖注入容器
- 更新IArchitectureContext接口添加新版CQRS请求、命令、查询和通知的统一入口
- 添加架构上下文的CQRS处理器注册相关单元测试
- 配置项目文件以支持多目标框架和包引用管理
2026-04-15 19:42:08 +08:00

50 lines
2.3 KiB
C#

using System.ComponentModel;
using GFramework.Core.Abstractions.Rule;
using GFramework.Cqrs.Abstractions.Cqrs.Command;
using GFramework.Cqrs.Extensions;
namespace GFramework.Core.Extensions;
/// <summary>
/// 提供对 <see cref="IContextAware" /> 接口的 CQRS 命令扩展方法。
/// 该类型保留旧名称以兼容历史调用点;新代码应改用 <see cref="ContextAwareCqrsCommandExtensions" />。
/// 兼容层计划在未来的 major 版本中移除,因此不会继续承载新能力。
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete(
"Use GFramework.Core.Extensions.ContextAwareCqrsCommandExtensions instead. This compatibility alias will be removed in a future major version.")]
public static class ContextAwareMediatorCommandExtensions
{
/// <summary>
/// 发送命令的同步版本(不推荐,仅用于兼容性)
/// </summary>
/// <typeparam name="TResponse">命令响应类型</typeparam>
/// <param name="contextAware">实现 IContextAware 接口的对象</param>
/// <param name="command">要发送的命令对象</param>
/// <returns>命令执行结果</returns>
/// <exception cref="ArgumentNullException">当 contextAware 或 command 为 null 时抛出</exception>
public static TResponse SendCommand<TResponse>(this IContextAware contextAware,
ICommand<TResponse> command)
{
return ContextAwareCqrsCommandExtensions.SendCommand(contextAware, command);
}
/// <summary>
/// 异步发送命令并返回结果
/// </summary>
/// <typeparam name="TResponse">命令响应类型</typeparam>
/// <param name="contextAware">实现 IContextAware 接口的对象</param>
/// <param name="command">要发送的命令对象</param>
/// <param name="cancellationToken">取消令牌,用于取消操作</param>
/// <returns>包含命令执行结果的ValueTask</returns>
/// <exception cref="ArgumentNullException">当 contextAware 或 command 为 null 时抛出</exception>
public static ValueTask<TResponse> SendCommandAsync<TResponse>(this IContextAware contextAware,
ICommand<TResponse> command, CancellationToken cancellationToken = default)
{
return ContextAwareCqrsCommandExtensions.SendCommandAsync(
contextAware,
command,
cancellationToken);
}
}