mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 19:03:29 +08:00
- 移除了 IArchitectureRuntime 接口和 ArchitectureRuntime 类 - 在 ArchitectureContext 中添加了对 ICommandBus 和 IQueryBus 的依赖注入 - 修改 Architecture 类以使用 CommandBus 和 QueryBus 替代 Runtime - 更新 ArchitectureServices 以提供 CommandBus 和 QueryBus 服务 - 将组件初始化逻辑从 if-else 改为 switch 语句 - 更新 ContextAwareBase 以使用新的 GetFirstArchitectureContext 方法 - 添加了 CommandBus 和 QueryBus 的实现类 - 修复了 Godot 模块中系统获取的重复代码问题
35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using GFramework.Core.Abstractions.command;
|
|
|
|
namespace GFramework.Core.command;
|
|
|
|
/// <summary>
|
|
/// 命令总线实现类,用于发送和执行命令
|
|
/// </summary>
|
|
public sealed class CommandBus : ICommandBus
|
|
{
|
|
/// <summary>
|
|
/// 发送并执行无返回值的命令
|
|
/// </summary>
|
|
/// <param name="command">要执行的命令对象,不能为空</param>
|
|
/// <exception cref="ArgumentNullException">当command参数为null时抛出</exception>
|
|
public void Send(ICommand command)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(command);
|
|
|
|
command.Execute();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发送并执行有返回值的命令
|
|
/// </summary>
|
|
/// <typeparam name="TResult">命令执行结果的类型</typeparam>
|
|
/// <param name="command">要执行的命令对象,不能为空</param>
|
|
/// <returns>命令执行的结果</returns>
|
|
/// <exception cref="ArgumentNullException">当command参数为null时抛出</exception>
|
|
public TResult Send<TResult>(ICommand<TResult> command)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(command);
|
|
|
|
return command.Execute();
|
|
}
|
|
} |