mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
feat(command): 为命令和查询类添加输入参数支持
- 重构 AbstractCommand 类,添加泛型参数 TInput 并要求实现 ICommandInput 接口 - 修改 AbstractCommand.Execute 方法,传入输入参数到 OnExecute 方法 - 重构 AbstractCommand<TInput, TResult> 类,支持输入参数和返回结果 - 更新 AbstractQuery 类,添加泛型参数 TInput 和 TResult 并要求实现 IQueryInput 接口 - 创建 ICommandInput 接口作为命令输入的标记接口 - 创建 IQueryInput 接口定义查询输入规范 - 为所有抽象方法添加参数文档注释
This commit is contained in:
parent
029f3a4652
commit
18267e7c14
7
GFramework.Core.Abstractions/command/ICommandInput.cs
Normal file
7
GFramework.Core.Abstractions/command/ICommandInput.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace GFramework.Core.Abstractions.command;
|
||||
|
||||
/// <summary>
|
||||
/// 命令输入接口,定义命令模式中输入数据的契约
|
||||
/// 该接口作为标记接口使用,不包含任何成员定义
|
||||
/// </summary>
|
||||
public interface ICommandInput;
|
||||
6
GFramework.Core.Abstractions/query/IQueryInput.cs
Normal file
6
GFramework.Core.Abstractions/query/IQueryInput.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace GFramework.Core.Abstractions.query;
|
||||
|
||||
/// <summary>
|
||||
/// 查询输入接口,定义了查询操作的输入规范
|
||||
/// </summary>
|
||||
public interface IQueryInput;
|
||||
@ -6,40 +6,48 @@ namespace GFramework.Core.command;
|
||||
/// <summary>
|
||||
/// 抽象命令类,实现 ICommand 接口,为具体命令提供基础架构支持
|
||||
/// </summary>
|
||||
public abstract class AbstractCommand : ContextAwareBase, ICommand
|
||||
/// <typeparam name="TInput">命令输入参数类型,必须实现 ICommandInput 接口</typeparam>
|
||||
/// <param name="input">命令执行所需的输入参数</param>
|
||||
public abstract class AbstractCommand<TInput>(TInput input) : ContextAwareBase, ICommand
|
||||
where TInput : ICommandInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 执行命令,调用抽象方法 OnExecute 来实现具体逻辑
|
||||
/// 执行命令的入口方法,实现 ICommand 接口的 Execute 方法
|
||||
/// </summary>
|
||||
void ICommand.Execute()
|
||||
{
|
||||
OnExecute();
|
||||
OnExecute(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 抽象方法,由子类实现具体的命令执行逻辑
|
||||
/// 命令执行的抽象方法,由派生类实现具体的命令逻辑
|
||||
/// </summary>
|
||||
protected abstract void OnExecute();
|
||||
/// <param name="input">命令执行所需的输入参数</param>
|
||||
protected abstract void OnExecute(TInput input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 带返回值的抽象命令类,实现 ICommand{TResult} 接口,为需要返回结果的命令提供基础架构支持
|
||||
/// </summary>
|
||||
/// <typeparam name="TInput">命令输入参数类型,必须实现 ICommandInput 接口</typeparam>
|
||||
/// <typeparam name="TResult">命令执行后返回的结果类型</typeparam>
|
||||
public abstract class AbstractCommand<TResult> : ContextAwareBase, ICommand<TResult>
|
||||
/// <param name="input">命令执行所需的输入参数</param>
|
||||
public abstract class AbstractCommand<TInput, TResult>(TInput input) : ContextAwareBase, ICommand<TResult>
|
||||
where TInput : ICommandInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 执行命令,调用抽象方法 OnExecute 来实现具体逻辑并返回结果
|
||||
/// 执行命令的入口方法,实现 ICommand{TResult} 接口的 Execute 方法
|
||||
/// </summary>
|
||||
/// <returns>TResult 类型的执行结果</returns>
|
||||
/// <returns>命令执行后的结果</returns>
|
||||
TResult ICommand<TResult>.Execute()
|
||||
{
|
||||
return OnExecute();
|
||||
return OnExecute(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 抽象方法,由子类实现具体的命令执行逻辑
|
||||
/// 命令执行的抽象方法,由派生类实现具体的命令逻辑
|
||||
/// </summary>
|
||||
/// <returns>TResult 类型的执行结果</returns>
|
||||
protected abstract TResult OnExecute();
|
||||
/// <param name="input">命令执行所需的输入参数</param>
|
||||
/// <returns>命令执行后的结果</returns>
|
||||
protected abstract TResult OnExecute(TInput input);
|
||||
}
|
||||
@ -6,21 +6,24 @@ namespace GFramework.Core.query;
|
||||
/// <summary>
|
||||
/// 抽象查询类,提供查询操作的基础实现
|
||||
/// </summary>
|
||||
/// <typeparam name="T">查询结果的类型</typeparam>
|
||||
public abstract class AbstractQuery<T> : ContextAwareBase, IQuery<T>
|
||||
/// <typeparam name="TInput">查询输入参数的类型,必须实现IQueryInput接口</typeparam>
|
||||
/// <typeparam name="TResult">查询结果的类型</typeparam>
|
||||
public abstract class AbstractQuery<TInput, TResult>(TInput input) : ContextAwareBase, IQuery<TResult>
|
||||
where TInput : IQueryInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 执行查询操作
|
||||
/// </summary>
|
||||
/// <returns>查询结果</returns>
|
||||
public T Do()
|
||||
/// <returns>查询结果,类型为TResult</returns>
|
||||
public TResult Do()
|
||||
{
|
||||
return OnDo();
|
||||
return OnDo(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 抽象方法,由子类实现具体的查询逻辑
|
||||
/// 抽象方法,用于实现具体的查询逻辑
|
||||
/// </summary>
|
||||
/// <returns>查询结果</returns>
|
||||
protected abstract T OnDo();
|
||||
/// <param name="input">查询输入参数</param>
|
||||
/// <returns>查询结果,类型为TResult</returns>
|
||||
protected abstract TResult OnDo(TInput input);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user