mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 19:03:29 +08:00
- 新增 Architecture 基类与 IArchitecture 接口,实现单例模式与组件注册管理 - 集成 IOC 容器支持系统、模型、工具的依赖注入与生命周期管理 - 实现命令模式基础类 AbstractCommand 与接口 ICommand,支持带返回值命令 - 提供事件系统集成,支持事件的发布与订阅机制 - 添加控制器接口 IController,整合命令发送、事件注册与模型获取能力 - 创建详细的 README 文档说明各组件使用方式与设计模式应用 - 支持命令、查询、事件的统一调度与解耦通信机制
29 lines
1.2 KiB
C#
29 lines
1.2 KiB
C#
using GFramework.framework.events;
|
||
|
||
namespace GFramework.framework.extensions;
|
||
|
||
/// <summary>
|
||
/// 事件注册扩展类,提供ICanRegisterEvent接口的扩展方法用于注册和注销事件
|
||
/// </summary>
|
||
public static class CanRegisterEventExtensions
|
||
{
|
||
/// <summary>
|
||
/// 注册指定类型的事件处理函数
|
||
/// </summary>
|
||
/// <typeparam name="T">事件数据类型</typeparam>
|
||
/// <param name="self">实现ICanRegisterEvent接口的对象实例</param>
|
||
/// <param name="onEvent">事件处理回调函数</param>
|
||
/// <returns>返回事件注销器接口,可用于后续注销事件</returns>
|
||
public static IUnRegister RegisterEvent<T>(this ICanRegisterEvent self, Action<T> onEvent) =>
|
||
self.GetArchitecture().RegisterEvent(onEvent);
|
||
|
||
/// <summary>
|
||
/// 注销指定类型的事件处理函数
|
||
/// </summary>
|
||
/// <typeparam name="T">事件数据类型</typeparam>
|
||
/// <param name="self">实现ICanRegisterEvent接口的对象实例</param>
|
||
/// <param name="onEvent">要注销的事件处理回调函数</param>
|
||
public static void UnRegisterEvent<T>(this ICanRegisterEvent self, Action<T> onEvent) =>
|
||
self.GetArchitecture().UnRegisterEvent(onEvent);
|
||
}
|