From ffaace4538c51ad80944ec9f75bfee23ef526460 Mon Sep 17 00:00:00 2001
From: GeWuYou <95328647+GeWuYou@users.noreply.github.com>
Date: Wed, 4 Mar 2026 23:03:29 +0800
Subject: [PATCH] =?UTF-8?q?refactor(core):=20=E9=87=8D=E6=9E=84=E4=B8=8A?=
=?UTF-8?q?=E4=B8=8B=E6=96=87=E6=84=9F=E7=9F=A5=E5=91=BD=E4=BB=A4=E5=92=8C?=
=?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=89=A9=E5=B1=95=E6=96=B9=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 将原有的 ContextAwareCommandExtensions 中的 Mediator 相关方法分离到新的 ContextAwareMediatorCommandExtensions 类中
- 将原有的 ContextAwareQueryExtensions 中的 Mediator 相关方法分离到新的 ContextAwareMediatorQueryExtensions 类中
- 移除 ContextAwareCommandExtensions 中的异步命令方法 SendCommandAsync
- 移除 ContextAwareQueryExtensions 中的异步查询方法 SendQueryAsync
- 修复了 ContextAwareCommandExtensions 中的泛型类型参数引用问题
- 统一了代码格式和命名空间引用
- 保持了原有功能的向后兼容性
---
.../ContextAwareCommandExtensions.cs | 18 -------
.../ContextAwareMediatorCommandExtensions.cs | 48 +++++++++++++++++++
.../ContextAwareMediatorQueryExtensions.cs | 47 ++++++++++++++++++
.../extensions/ContextAwareQueryExtensions.cs | 18 -------
4 files changed, 95 insertions(+), 36 deletions(-)
create mode 100644 GFramework.Core/extensions/ContextAwareMediatorCommandExtensions.cs
create mode 100644 GFramework.Core/extensions/ContextAwareMediatorQueryExtensions.cs
diff --git a/GFramework.Core/extensions/ContextAwareCommandExtensions.cs b/GFramework.Core/extensions/ContextAwareCommandExtensions.cs
index 08de9bb..abcc307 100644
--- a/GFramework.Core/extensions/ContextAwareCommandExtensions.cs
+++ b/GFramework.Core/extensions/ContextAwareCommandExtensions.cs
@@ -59,24 +59,6 @@ public static class ContextAwareCommandExtensions
context.SendCommand(command);
}
- ///
- /// [Mediator] 异步发送命令并返回结果
- ///
- /// 命令响应类型
- /// 实现 IContextAware 接口的对象
- /// 要发送的命令对象
- /// 取消令牌,用于取消操作
- /// 包含命令执行结果的ValueTask
- /// 当 contextAware 或 command 为 null 时抛出
- public static ValueTask SendCommandAsync(this IContextAware contextAware,
- Mediator.ICommand command, CancellationToken cancellationToken = default)
- {
- ArgumentNullException.ThrowIfNull(contextAware);
- ArgumentNullException.ThrowIfNull(command);
-
- var context = contextAware.GetContext();
- return context.SendCommandAsync(command, cancellationToken);
- }
///
/// 发送并异步执行一个无返回值的命令
diff --git a/GFramework.Core/extensions/ContextAwareMediatorCommandExtensions.cs b/GFramework.Core/extensions/ContextAwareMediatorCommandExtensions.cs
new file mode 100644
index 0000000..80c308d
--- /dev/null
+++ b/GFramework.Core/extensions/ContextAwareMediatorCommandExtensions.cs
@@ -0,0 +1,48 @@
+using GFramework.Core.Abstractions.rule;
+using Mediator;
+
+namespace GFramework.Core.extensions;
+
+///
+/// 提供对 IContextAware 接口的 Mediator 命令扩展方法
+/// 使用 Mediator 库的命令模式
+///
+public static class ContextAwareMediatorCommandExtensions
+{
+ ///
+ /// [Mediator] 发送命令的同步版本(不推荐,仅用于兼容性)
+ ///
+ /// 命令响应类型
+ /// 实现 IContextAware 接口的对象
+ /// 要发送的命令对象
+ /// 命令执行结果
+ /// 当 contextAware 或 command 为 null 时抛出
+ public static TResponse SendCommand(this IContextAware contextAware,
+ ICommand command)
+ {
+ ArgumentNullException.ThrowIfNull(contextAware);
+ ArgumentNullException.ThrowIfNull(command);
+
+ var context = contextAware.GetContext();
+ return context.SendCommand(command);
+ }
+
+ ///
+ /// [Mediator] 异步发送命令并返回结果
+ ///
+ /// 命令响应类型
+ /// 实现 IContextAware 接口的对象
+ /// 要发送的命令对象
+ /// 取消令牌,用于取消操作
+ /// 包含命令执行结果的ValueTask
+ /// 当 contextAware 或 command 为 null 时抛出
+ public static ValueTask SendCommandAsync(this IContextAware contextAware,
+ ICommand command, CancellationToken cancellationToken = default)
+ {
+ ArgumentNullException.ThrowIfNull(contextAware);
+ ArgumentNullException.ThrowIfNull(command);
+
+ var context = contextAware.GetContext();
+ return context.SendCommandAsync(command, cancellationToken);
+ }
+}
\ No newline at end of file
diff --git a/GFramework.Core/extensions/ContextAwareMediatorQueryExtensions.cs b/GFramework.Core/extensions/ContextAwareMediatorQueryExtensions.cs
new file mode 100644
index 0000000..fe4b823
--- /dev/null
+++ b/GFramework.Core/extensions/ContextAwareMediatorQueryExtensions.cs
@@ -0,0 +1,47 @@
+using GFramework.Core.Abstractions.rule;
+using Mediator;
+
+namespace GFramework.Core.extensions;
+
+///
+/// 提供对 IContextAware 接口的 Mediator 查询扩展方法
+/// 使用 Mediator 库的查询模式
+///
+public static class ContextAwareMediatorQueryExtensions
+{
+ ///
+ /// [Mediator] 发送查询的同步版本(不推荐,仅用于兼容性)
+ ///
+ /// 查询响应类型
+ /// 实现 IContextAware 接口的对象
+ /// 要发送的查询对象
+ /// 查询结果
+ /// 当 contextAware 或 query 为 null 时抛出
+ public static TResponse SendQuery(this IContextAware contextAware, IQuery query)
+ {
+ ArgumentNullException.ThrowIfNull(contextAware);
+ ArgumentNullException.ThrowIfNull(query);
+
+ var context = contextAware.GetContext();
+ return context.SendQuery(query);
+ }
+
+ ///
+ /// [Mediator] 异步发送查询并返回结果
+ ///
+ /// 查询响应类型
+ /// 实现 IContextAware 接口的对象
+ /// 要发送的查询对象
+ /// 取消令牌,用于取消操作
+ /// 包含查询结果的ValueTask
+ /// 当 contextAware 或 query 为 null 时抛出
+ public static ValueTask SendQueryAsync(this IContextAware contextAware,
+ IQuery query, CancellationToken cancellationToken = default)
+ {
+ ArgumentNullException.ThrowIfNull(contextAware);
+ ArgumentNullException.ThrowIfNull(query);
+
+ var context = contextAware.GetContext();
+ return context.SendQueryAsync(query, cancellationToken);
+ }
+}
\ No newline at end of file
diff --git a/GFramework.Core/extensions/ContextAwareQueryExtensions.cs b/GFramework.Core/extensions/ContextAwareQueryExtensions.cs
index ed2d47e..3d9719e 100644
--- a/GFramework.Core/extensions/ContextAwareQueryExtensions.cs
+++ b/GFramework.Core/extensions/ContextAwareQueryExtensions.cs
@@ -42,24 +42,6 @@ public static class ContextAwareQueryExtensions
return context.SendQuery(query);
}
- ///
- /// [Mediator] 异步发送查询并返回结果
- ///
- /// 查询响应类型
- /// 实现 IContextAware 接口的对象
- /// 要发送的查询对象
- /// 取消令牌,用于取消操作
- /// 包含查询结果的ValueTask
- /// 当 contextAware 或 query 为 null 时抛出
- public static ValueTask SendQueryAsync(this IContextAware contextAware,
- Mediator.IQuery query, CancellationToken cancellationToken = default)
- {
- ArgumentNullException.ThrowIfNull(contextAware);
- ArgumentNullException.ThrowIfNull(query);
-
- var context = contextAware.GetContext();
- return context.SendQueryAsync(query, cancellationToken);
- }
///
/// 异步发送一个查询请求