mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 19:03:29 +08:00
- 在 Architecture 中添加对 IAsyncDestroyable 接口的支持 - 将销毁集合类型从 IDestroyable 改为 object 以支持多种销毁接口 - 实现 DestroyAsync 方法提供异步销毁能力 - 保留旧的同步 Destroy 方法用于向后兼容 - 在 StateMachineSystem 中添加异步销毁状态的支持 - 添加 IAsyncDestroyable、IAsyncInitializable 和 IAsyncLifecycle 接口定义 - 更新测试代码以使用新的异步销毁方法 - 在架构销毁时清理依赖注入容器
118 lines
4.4 KiB
C#
118 lines
4.4 KiB
C#
using GFramework.Core.Abstractions.lifecycle;
|
||
using GFramework.Core.Abstractions.model;
|
||
using GFramework.Core.Abstractions.system;
|
||
using GFramework.Core.Abstractions.utility;
|
||
using Microsoft.Extensions.DependencyInjection;
|
||
|
||
namespace GFramework.Core.Abstractions.architecture;
|
||
|
||
/// <summary>
|
||
/// 架构接口,专注于生命周期管理,包括系统、模型、工具的注册和获取
|
||
/// 业务操作通过 ArchitectureRuntime 提供
|
||
/// </summary>
|
||
public interface IArchitecture : IAsyncInitializable
|
||
{
|
||
/// <summary>
|
||
/// 获取架构上下文
|
||
/// </summary>
|
||
IArchitectureContext Context { get; }
|
||
|
||
/// <summary>
|
||
/// 获取或设置用于配置服务集合的委托
|
||
/// </summary>
|
||
/// <value>
|
||
/// 一个可为空的委托,用于配置IServiceCollection实例
|
||
/// </value>
|
||
Action<IServiceCollection>? Configurator { get; }
|
||
|
||
/// <summary>
|
||
/// 初始化方法,用于执行对象的初始化操作
|
||
/// </summary>
|
||
/// <remarks>
|
||
/// 该方法通常用于设置初始状态、初始化成员变量或执行必要的预处理操作
|
||
/// </remarks>
|
||
void Initialize();
|
||
|
||
/// <summary>
|
||
/// 销毁方法,用于执行对象的清理和销毁操作
|
||
/// </summary>
|
||
/// <remarks>
|
||
/// 该方法通常用于释放资源、清理内存或执行必要的清理操作
|
||
/// </remarks>
|
||
void Destroy();
|
||
|
||
/// <summary>
|
||
/// 注册系统实例到架构中
|
||
/// </summary>
|
||
/// <typeparam name="T">系统类型,必须实现ISystem接口</typeparam>
|
||
/// <param name="system">要注册的系统实例</param>
|
||
/// <returns>注册的系统实例</returns>
|
||
T RegisterSystem<T>(T system) where T : ISystem;
|
||
|
||
/// <summary>
|
||
/// 注册系统实例到架构中
|
||
/// </summary>
|
||
/// <typeparam name="T">系统类型,必须实现ISystem接口</typeparam>
|
||
/// <param name="onCreated">系统实例创建后的回调函数,可为null</param>
|
||
void RegisterSystem<T>(Action<T>? onCreated = null) where T : class, ISystem;
|
||
|
||
/// <summary>
|
||
/// 注册模型实例到架构中
|
||
/// </summary>
|
||
/// <typeparam name="T">模型类型,必须实现IModel接口</typeparam>
|
||
/// <param name="model">要注册的模型实例</param>
|
||
/// <returns>注册的模型实例</returns>
|
||
T RegisterModel<T>(T model) where T : IModel;
|
||
|
||
/// <summary>
|
||
/// 注册模型实例到架构中
|
||
/// </summary>
|
||
/// <typeparam name="T">模型类型,必须实现IModel接口</typeparam>
|
||
/// <param name="onCreated">模型实例创建后的回调函数,可为null</param>
|
||
void RegisterModel<T>(Action<T>? onCreated = null) where T : class, IModel;
|
||
|
||
/// <summary>
|
||
/// 注册工具实例到架构中
|
||
/// </summary>
|
||
/// <typeparam name="T">工具类型,必须实现IUtility接口</typeparam>
|
||
/// <param name="utility">要注册的工具实例</param>
|
||
/// <returns>注册的工具实例</returns>
|
||
T RegisterUtility<T>(T utility) where T : IUtility;
|
||
|
||
|
||
/// <summary>
|
||
/// 注册工具类型并可选地指定创建回调
|
||
/// 当工具实例被创建时会调用指定的回调函数
|
||
/// </summary>
|
||
/// <typeparam name="T">工具类型,必须是引用类型且实现IUtility接口</typeparam>
|
||
/// <param name="onCreated">工具实例创建后的回调函数,可为null</param>
|
||
void RegisterUtility<T>(Action<T>? onCreated = null) where T : class, IUtility;
|
||
|
||
/// <summary>
|
||
/// 注册中介行为管道
|
||
/// 用于配置Mediator框架的行为拦截和处理逻辑
|
||
/// </summary>
|
||
/// <typeparam name="TBehavior">行为类型,必须是引用类型</typeparam>
|
||
void RegisterMediatorBehavior<TBehavior>()
|
||
where TBehavior : class;
|
||
|
||
/// <summary>
|
||
/// 安装架构模块
|
||
/// </summary>
|
||
/// <param name="module">要安装的模块</param>
|
||
/// <returns>安装的模块实例</returns>
|
||
IArchitectureModule InstallModule(IArchitectureModule module);
|
||
|
||
/// <summary>
|
||
/// 注册生命周期钩子
|
||
/// </summary>
|
||
/// <param name="hook">生命周期钩子实例</param>
|
||
/// <returns>注册的钩子实例</returns>
|
||
IArchitectureLifecycle RegisterLifecycleHook(IArchitectureLifecycle hook);
|
||
|
||
/// <summary>
|
||
/// 等待直到架构准备就绪的异步操作
|
||
/// </summary>
|
||
/// <returns>表示异步等待操作的任务</returns>
|
||
Task WaitUntilReadyAsync();
|
||
} |