// Copyright (c) 2025-2026 GeWuYou
// SPDX-License-Identifier: Apache-2.0
using GFramework.Core.Abstractions.Command;
using GFramework.Core.Rule;
using GFramework.Cqrs.Abstractions.Cqrs.Command;
using ICommand = GFramework.Core.Abstractions.Command.ICommand;
namespace GFramework.Core.Command;
///
/// 抽象命令类,实现 ICommand 接口,为具体命令提供基础架构支持
///
public abstract class AbstractCommand : ContextAwareBase, ICommand
{
///
/// 执行命令的入口方法,实现 ICommand 接口的 Execute 方法
///
void ICommand.Execute()
{
OnExecute();
}
///
/// 命令执行的抽象方法,由派生类实现具体的命令逻辑
///
protected abstract void OnExecute();
}
///
/// 抽象命令类,实现 接口,为需要命令输入的具体命令提供基础架构支持。
///
/// 命令输入参数类型,必须实现 接口。
/// 命令执行所需的输入参数。
public abstract class AbstractCommand(TInput input) : ContextAwareBase, ICommand
where TInput : ICommandInput
{
///
/// 执行命令的入口方法,实现 接口的 Execute 方法。
///
void ICommand.Execute()
{
OnExecute(input);
}
///
/// 命令执行的抽象方法,由派生类实现具体的命令逻辑。
///
/// 命令执行所需的输入参数。
protected abstract void OnExecute(TInput input);
}
///
/// 带返回值的抽象命令类,为需要输入和返回值的命令提供统一执行骨架。
///
/// 命令输入参数类型,必须实现 接口。
/// 命令执行后返回的结果类型。
/// 命令执行所需的输入参数。
public abstract class AbstractCommand(TInput input)
: ContextAwareBase, GFramework.Core.Abstractions.Command.ICommand
where TInput : ICommandInput
{
///
/// 执行命令的入口方法,实现 接口的
/// Execute 方法。
///
/// 命令执行后的结果。
TResult GFramework.Core.Abstractions.Command.ICommand.Execute()
{
return OnExecute(input);
}
///
/// 命令执行的抽象方法,由派生类实现具体的命令逻辑。
///
/// 命令执行所需的输入参数。
/// 命令执行后的结果。
protected abstract TResult OnExecute(TInput input);
}