mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 19:03:29 +08:00
- 移除专用的RegisterMediator方法,替换为ExecuteServicesHook通用服务配置方法 - 从架构配置中移除Mediator特定配置选项,改为通用服务配置委托 - 在架构基类中添加Configurator属性支持,允许子类提供自定义服务配置 - 更新测试代码适配新的服务配置方式,通过ExecuteServicesHook注册Mediator - 移除过时的测试组件和相关验证逻辑 - 删除Mediator.SourceGenerator包引用,保留运行时依赖 - 添加WaitUntilReadyAsync方法的详细文档注释
117 lines
4.4 KiB
C#
117 lines
4.4 KiB
C#
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();
|
||
} |