using GFramework.Core.Abstractions.command;
namespace GFramework.Core.command;
///
/// 命令总线实现类,用于发送和执行命令
///
public sealed class CommandBus : ICommandBus
{
///
/// 发送并执行无返回值的命令
///
/// 要执行的命令对象,不能为空
/// 当command参数为null时抛出
public void Send(ICommand command)
{
ArgumentNullException.ThrowIfNull(command);
command.Execute();
}
///
/// 发送并执行有返回值的命令
///
/// 命令执行结果的类型
/// 要执行的命令对象,不能为空
/// 命令执行的结果
/// 当command参数为null时抛出
public TResult Send(ICommand command)
{
ArgumentNullException.ThrowIfNull(command);
return command.Execute();
}
}