mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
refactor(architecture): 重构架构生命周期相关接口命名
- 将 IArchitectureLifecycle 重命名为 IArchitectureLifecycleHook - 将 IArchitecturePhaseAware 重命名为 IArchitecturePhaseListener - 更新内部生命周期钩子集合类型为 IArchitectureLifecycleHook - 更新 NotifyPhaseAwareObjects 方法中的类型引用 - 移除 IArchitectureModule 对生命周期接口的继承 - 更新 IModel 和 ISystem 接口中的相位感知类型引用 - 删除废弃的 AbstractModule 抽象类
This commit is contained in:
parent
9ccfd7f49e
commit
a65d4fa294
@ -92,7 +92,7 @@ public interface IArchitecture : IAsyncInitializable, IAsyncDestroyable, IInitia
|
||||
/// </summary>
|
||||
/// <param name="hook">生命周期钩子实例</param>
|
||||
/// <returns>注册的钩子实例</returns>
|
||||
IArchitectureLifecycle RegisterLifecycleHook(IArchitectureLifecycle hook);
|
||||
IArchitectureLifecycleHook RegisterLifecycleHook(IArchitectureLifecycleHook hook);
|
||||
|
||||
/// <summary>
|
||||
/// 等待直到架构准备就绪的异步操作
|
||||
|
||||
@ -3,12 +3,13 @@
|
||||
namespace GFramework.Core.Abstractions.architecture;
|
||||
|
||||
/// <summary>
|
||||
/// 架构生命周期接口,定义了架构在不同阶段的回调方法
|
||||
/// 架构生命周期钩子接口,用于在架构的不同生命周期阶段执行自定义逻辑。
|
||||
/// 实现此接口的类可以监听架构阶段变化并访问相关的架构实例。
|
||||
/// </summary>
|
||||
public interface IArchitectureLifecycle
|
||||
public interface IArchitectureLifecycleHook
|
||||
{
|
||||
/// <summary>
|
||||
/// 当架构进入指定阶段时触发的回调方法
|
||||
/// 当架构进入指定阶段时触发的回调方法。
|
||||
/// </summary>
|
||||
/// <param name="phase">当前的架构阶段</param>
|
||||
/// <param name="architecture">相关的架构实例</param>
|
||||
@ -4,7 +4,7 @@
|
||||
/// 架构模块接口,继承自架构生命周期接口。
|
||||
/// 定义了模块安装到架构中的标准方法。
|
||||
/// </summary>
|
||||
public interface IArchitectureModule : IArchitectureLifecycle, IArchitecturePhaseAware
|
||||
public interface IArchitectureModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 将当前模块安装到指定的架构中。
|
||||
|
||||
@ -3,12 +3,13 @@
|
||||
namespace GFramework.Core.Abstractions.architecture;
|
||||
|
||||
/// <summary>
|
||||
/// 定义架构阶段感知接口,用于在架构的不同阶段执行相应的逻辑
|
||||
/// 架构阶段监听器接口,用于监听和响应架构生命周期中的不同阶段变化。
|
||||
/// 实现此接口的类可以在架构进入特定阶段时执行相应的逻辑处理。
|
||||
/// </summary>
|
||||
public interface IArchitecturePhaseAware
|
||||
public interface IArchitecturePhaseListener
|
||||
{
|
||||
/// <summary>
|
||||
/// 当架构进入指定阶段时触发的回调方法
|
||||
/// 当架构进入指定阶段时触发的回调方法。
|
||||
/// </summary>
|
||||
/// <param name="phase">架构阶段枚举值,表示当前所处的架构阶段</param>
|
||||
void OnArchitecturePhase(ArchitecturePhase phase);
|
||||
@ -7,4 +7,4 @@ namespace GFramework.Core.Abstractions.model;
|
||||
/// <summary>
|
||||
/// 模型接口,定义了模型的基本行为和功能
|
||||
/// </summary>
|
||||
public interface IModel : IContextAware, IArchitecturePhaseAware, IInitializable;
|
||||
public interface IModel : IContextAware, IArchitecturePhaseListener, IInitializable;
|
||||
@ -8,4 +8,4 @@ namespace GFramework.Core.Abstractions.system;
|
||||
/// 系统接口,定义了系统的基本行为和功能
|
||||
/// 该接口继承了多个框架相关的接口,提供了系统初始化和销毁能力
|
||||
/// </summary>
|
||||
public interface ISystem : IContextAware, IArchitecturePhaseAware, ILifecycle;
|
||||
public interface ISystem : IContextAware, IArchitecturePhaseListener, ILifecycle;
|
||||
@ -49,8 +49,6 @@ public abstract class Architecture(
|
||||
var name = module.GetType().Name;
|
||||
var logger = LoggerFactoryResolver.Provider.CreateLogger(name);
|
||||
logger.Debug($"Installing module: {name}");
|
||||
RegisterLifecycleHook(module);
|
||||
Container.RegisterPlurality(module);
|
||||
module.Install(this);
|
||||
logger.Info($"Module installed: {name}");
|
||||
return module;
|
||||
@ -126,7 +124,7 @@ public abstract class Architecture(
|
||||
/// <summary>
|
||||
/// 生命周期感知对象列表
|
||||
/// </summary>
|
||||
private readonly List<IArchitectureLifecycle> _lifecycleHooks = [];
|
||||
private readonly List<IArchitectureLifecycleHook> _lifecycleHooks = [];
|
||||
|
||||
/// <summary>
|
||||
/// 标记架构是否已初始化完成
|
||||
@ -201,7 +199,7 @@ public abstract class Architecture(
|
||||
/// <param name="phase">新阶段</param>
|
||||
private void NotifyPhaseAwareObjects(ArchitecturePhase phase)
|
||||
{
|
||||
foreach (var obj in Container.GetAll<IArchitecturePhaseAware>())
|
||||
foreach (var obj in Container.GetAll<IArchitecturePhaseListener>())
|
||||
{
|
||||
_logger.Trace($"Notifying phase-aware object {obj.GetType().Name} of phase change to {phase}");
|
||||
obj.OnArchitecturePhase(phase);
|
||||
@ -226,7 +224,7 @@ public abstract class Architecture(
|
||||
/// </summary>
|
||||
/// <param name="hook">生命周期钩子实例</param>
|
||||
/// <returns>注册的钩子实例</returns>
|
||||
public IArchitectureLifecycle RegisterLifecycleHook(IArchitectureLifecycle hook)
|
||||
public IArchitectureLifecycleHook RegisterLifecycleHook(IArchitectureLifecycleHook hook)
|
||||
{
|
||||
if (CurrentPhase >= ArchitecturePhase.Ready && !Configuration.ArchitectureProperties.AllowLateRegistration)
|
||||
throw new InvalidOperationException(
|
||||
|
||||
@ -1,33 +0,0 @@
|
||||
using GFramework.Core.Abstractions.architecture;
|
||||
using GFramework.Core.Abstractions.enums;
|
||||
|
||||
namespace GFramework.Game.architecture;
|
||||
|
||||
/// <summary>
|
||||
/// 抽象模块类,实现IArchitectureModule接口,为架构模块提供基础功能
|
||||
/// </summary>
|
||||
public abstract class AbstractModule : IArchitectureModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 在指定架构阶段执行的操作
|
||||
/// </summary>
|
||||
/// <param name="phase">架构阶段枚举值</param>
|
||||
/// <param name="architecture">架构实例</param>
|
||||
public virtual void OnPhase(ArchitecturePhase phase, IArchitecture architecture)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在架构阶段执行的操作
|
||||
/// </summary>
|
||||
/// <param name="phase">架构阶段枚举值</param>
|
||||
public virtual void OnArchitecturePhase(ArchitecturePhase phase)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 安装模块到架构中
|
||||
/// </summary>
|
||||
/// <param name="architecture">要安装到的架构实例</param>
|
||||
public abstract void Install(IArchitecture architecture);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user