diff --git a/GFramework.Core.Abstractions/command/IAsyncCommand.cs b/GFramework.Core.Abstractions/command/IAsyncCommand.cs index 72366bb..a6ae752 100644 --- a/GFramework.Core.Abstractions/command/IAsyncCommand.cs +++ b/GFramework.Core.Abstractions/command/IAsyncCommand.cs @@ -3,12 +3,27 @@ using GFramework.Core.Abstractions.rule; namespace GFramework.Core.Abstractions.command; +/// +/// 表示一个异步命令接口,该命令不返回结果 +/// public interface IAsyncCommand : IContextAware { + /// + /// 异步执行命令 + /// + /// 表示异步操作的任务 Task ExecuteAsync(); } +/// +/// 表示一个异步命令接口,该命令返回指定类型的结果 +/// +/// 命令执行结果的类型 public interface IAsyncCommand : IContextAware { + /// + /// 异步执行命令并返回结果 + /// + /// 表示异步操作的任务,任务结果为命令执行的返回值 Task ExecuteAsync(); } \ No newline at end of file diff --git a/GFramework.Core/extensions/ContextAwareExtensions.cs b/GFramework.Core/extensions/ContextAwareExtensions.cs index 485835d..d21a11a 100644 --- a/GFramework.Core/extensions/ContextAwareExtensions.cs +++ b/GFramework.Core/extensions/ContextAwareExtensions.cs @@ -73,38 +73,6 @@ public static class ContextAwareExtensions return context.SendQuery(query); } - /// - /// 发送一个无返回结果的命令 - /// - /// 实现 IContextAware 接口的对象 - /// 要发送的命令 - /// 当 contextAware 或 command 为 null 时抛出 - public static void SendCommand(this IContextAware contextAware, ICommand command) - { - ArgumentNullException.ThrowIfNull(contextAware); - ArgumentNullException.ThrowIfNull(command); - - var context = contextAware.GetContext(); - context.SendCommand(command); - } - - /// - /// 发送一个带返回值的命令 - /// - /// 命令执行结果类型 - /// 实现 IContextAware 接口的对象 - /// 要发送的命令 - /// 命令执行结果 - /// 当 contextAware 或 command 为 null 时抛出 - public static TResult SendCommand(this IContextAware contextAware, ICommand command) - { - ArgumentNullException.ThrowIfNull(contextAware); - ArgumentNullException.ThrowIfNull(command); - - var Context = contextAware.GetContext(); - return Context.SendCommand(command); - } - /// /// 发送并异步执行一个无返回值的命令 /// @@ -116,8 +84,8 @@ public static class ContextAwareExtensions ArgumentNullException.ThrowIfNull(contextAware); ArgumentNullException.ThrowIfNull(command); - var Context = contextAware.GetContext(); - await Context.SendCommandAsync(command); + var context = contextAware.GetContext(); + await context.SendCommandAsync(command); } /// @@ -134,27 +102,11 @@ public static class ContextAwareExtensions ArgumentNullException.ThrowIfNull(contextAware); ArgumentNullException.ThrowIfNull(command); - var Context = contextAware.GetContext(); - return await Context.SendCommandAsync(command); - } - - /// - /// 发送一个事件 - /// - /// 命令执行结果类型 - /// 实现 IContextAware 接口的对象 - /// 要发送的命令 - /// 命令执行结果 - /// 当 contextAware 或 command 为 null 时抛出 - public static TResult SendCommand(this IContextAware contextAware, ICommand command) - { - ArgumentNullException.ThrowIfNull(contextAware); - ArgumentNullException.ThrowIfNull(command); - var context = contextAware.GetContext(); - return context.SendCommand(command); + return await context.SendCommandAsync(command); } + /// /// 发送一个事件 /// @@ -184,6 +136,39 @@ public static class ContextAwareExtensions context.SendEvent(e); } + /// + /// 发送一个事件 + /// + /// 命令执行结果类型 + /// 实现 IContextAware 接口的对象 + /// 要发送的命令 + /// 命令执行结果 + /// 当 contextAware 或 command 为 null 时抛出 + public static TResult SendCommand(this IContextAware contextAware, ICommand command) + { + ArgumentNullException.ThrowIfNull(contextAware); + ArgumentNullException.ThrowIfNull(command); + + var context = contextAware.GetContext(); + return context.SendCommand(command); + } + + /// + /// 发送一个无返回结果的命令 + /// + /// 实现 IContextAware 接口的对象 + /// 要发送的命令 + /// 当 contextAware 或 command 为 null 时抛出 + public static void SendCommand(this IContextAware contextAware, ICommand command) + { + ArgumentNullException.ThrowIfNull(contextAware); + ArgumentNullException.ThrowIfNull(command); + + var context = contextAware.GetContext(); + context.SendCommand(command); + } + + /// /// 注册事件处理器 ///