From a65d4fa2949de12d5a3817338a9ef4fb20834ad5 Mon Sep 17 00:00:00 2001 From: GeWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Mon, 23 Feb 2026 11:19:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor(architecture):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E6=9E=B6=E6=9E=84=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=8E=A5=E5=8F=A3=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 IArchitectureLifecycle 重命名为 IArchitectureLifecycleHook - 将 IArchitecturePhaseAware 重命名为 IArchitecturePhaseListener - 更新内部生命周期钩子集合类型为 IArchitectureLifecycleHook - 更新 NotifyPhaseAwareObjects 方法中的类型引用 - 移除 IArchitectureModule 对生命周期接口的继承 - 更新 IModel 和 ISystem 接口中的相位感知类型引用 - 删除废弃的 AbstractModule 抽象类 --- .../architecture/IArchitecture.cs | 2 +- ...cycle.cs => IArchitectureLifecycleHook.cs} | 7 ++-- .../architecture/IArchitectureModule.cs | 2 +- ...Aware.cs => IArchitecturePhaseListener.cs} | 7 ++-- GFramework.Core.Abstractions/model/IModel.cs | 2 +- .../system/ISystem.cs | 2 +- GFramework.Core/architecture/Architecture.cs | 8 ++--- .../architecture/AbstractModule.cs | 33 ------------------- 8 files changed, 15 insertions(+), 48 deletions(-) rename GFramework.Core.Abstractions/architecture/{IArchitectureLifecycle.cs => IArchitectureLifecycleHook.cs} (54%) rename GFramework.Core.Abstractions/architecture/{IArchitecturePhaseAware.cs => IArchitecturePhaseListener.cs} (51%) delete mode 100644 GFramework.Game/architecture/AbstractModule.cs diff --git a/GFramework.Core.Abstractions/architecture/IArchitecture.cs b/GFramework.Core.Abstractions/architecture/IArchitecture.cs index eaf0a22..7425123 100644 --- a/GFramework.Core.Abstractions/architecture/IArchitecture.cs +++ b/GFramework.Core.Abstractions/architecture/IArchitecture.cs @@ -92,7 +92,7 @@ public interface IArchitecture : IAsyncInitializable, IAsyncDestroyable, IInitia /// /// 生命周期钩子实例 /// 注册的钩子实例 - IArchitectureLifecycle RegisterLifecycleHook(IArchitectureLifecycle hook); + IArchitectureLifecycleHook RegisterLifecycleHook(IArchitectureLifecycleHook hook); /// /// 等待直到架构准备就绪的异步操作 diff --git a/GFramework.Core.Abstractions/architecture/IArchitectureLifecycle.cs b/GFramework.Core.Abstractions/architecture/IArchitectureLifecycleHook.cs similarity index 54% rename from GFramework.Core.Abstractions/architecture/IArchitectureLifecycle.cs rename to GFramework.Core.Abstractions/architecture/IArchitectureLifecycleHook.cs index 28b3948..54dc6f8 100644 --- a/GFramework.Core.Abstractions/architecture/IArchitectureLifecycle.cs +++ b/GFramework.Core.Abstractions/architecture/IArchitectureLifecycleHook.cs @@ -3,12 +3,13 @@ namespace GFramework.Core.Abstractions.architecture; /// -/// 架构生命周期接口,定义了架构在不同阶段的回调方法 +/// 架构生命周期钩子接口,用于在架构的不同生命周期阶段执行自定义逻辑。 +/// 实现此接口的类可以监听架构阶段变化并访问相关的架构实例。 /// -public interface IArchitectureLifecycle +public interface IArchitectureLifecycleHook { /// - /// 当架构进入指定阶段时触发的回调方法 + /// 当架构进入指定阶段时触发的回调方法。 /// /// 当前的架构阶段 /// 相关的架构实例 diff --git a/GFramework.Core.Abstractions/architecture/IArchitectureModule.cs b/GFramework.Core.Abstractions/architecture/IArchitectureModule.cs index 2dc62cd..5442830 100644 --- a/GFramework.Core.Abstractions/architecture/IArchitectureModule.cs +++ b/GFramework.Core.Abstractions/architecture/IArchitectureModule.cs @@ -4,7 +4,7 @@ /// 架构模块接口,继承自架构生命周期接口。 /// 定义了模块安装到架构中的标准方法。 /// -public interface IArchitectureModule : IArchitectureLifecycle, IArchitecturePhaseAware +public interface IArchitectureModule { /// /// 将当前模块安装到指定的架构中。 diff --git a/GFramework.Core.Abstractions/architecture/IArchitecturePhaseAware.cs b/GFramework.Core.Abstractions/architecture/IArchitecturePhaseListener.cs similarity index 51% rename from GFramework.Core.Abstractions/architecture/IArchitecturePhaseAware.cs rename to GFramework.Core.Abstractions/architecture/IArchitecturePhaseListener.cs index c7bcfeb..3a8dce2 100644 --- a/GFramework.Core.Abstractions/architecture/IArchitecturePhaseAware.cs +++ b/GFramework.Core.Abstractions/architecture/IArchitecturePhaseListener.cs @@ -3,12 +3,13 @@ namespace GFramework.Core.Abstractions.architecture; /// -/// 定义架构阶段感知接口,用于在架构的不同阶段执行相应的逻辑 +/// 架构阶段监听器接口,用于监听和响应架构生命周期中的不同阶段变化。 +/// 实现此接口的类可以在架构进入特定阶段时执行相应的逻辑处理。 /// -public interface IArchitecturePhaseAware +public interface IArchitecturePhaseListener { /// - /// 当架构进入指定阶段时触发的回调方法 + /// 当架构进入指定阶段时触发的回调方法。 /// /// 架构阶段枚举值,表示当前所处的架构阶段 void OnArchitecturePhase(ArchitecturePhase phase); diff --git a/GFramework.Core.Abstractions/model/IModel.cs b/GFramework.Core.Abstractions/model/IModel.cs index 4ec22d0..38f2f52 100644 --- a/GFramework.Core.Abstractions/model/IModel.cs +++ b/GFramework.Core.Abstractions/model/IModel.cs @@ -7,4 +7,4 @@ namespace GFramework.Core.Abstractions.model; /// /// 模型接口,定义了模型的基本行为和功能 /// -public interface IModel : IContextAware, IArchitecturePhaseAware, IInitializable; \ No newline at end of file +public interface IModel : IContextAware, IArchitecturePhaseListener, IInitializable; \ No newline at end of file diff --git a/GFramework.Core.Abstractions/system/ISystem.cs b/GFramework.Core.Abstractions/system/ISystem.cs index 7a8b415..0c91dcd 100644 --- a/GFramework.Core.Abstractions/system/ISystem.cs +++ b/GFramework.Core.Abstractions/system/ISystem.cs @@ -8,4 +8,4 @@ namespace GFramework.Core.Abstractions.system; /// 系统接口,定义了系统的基本行为和功能 /// 该接口继承了多个框架相关的接口,提供了系统初始化和销毁能力 /// -public interface ISystem : IContextAware, IArchitecturePhaseAware, ILifecycle; \ No newline at end of file +public interface ISystem : IContextAware, IArchitecturePhaseListener, ILifecycle; \ No newline at end of file diff --git a/GFramework.Core/architecture/Architecture.cs b/GFramework.Core/architecture/Architecture.cs index 33c4740..7e4ba9c 100644 --- a/GFramework.Core/architecture/Architecture.cs +++ b/GFramework.Core/architecture/Architecture.cs @@ -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( /// /// 生命周期感知对象列表 /// - private readonly List _lifecycleHooks = []; + private readonly List _lifecycleHooks = []; /// /// 标记架构是否已初始化完成 @@ -201,7 +199,7 @@ public abstract class Architecture( /// 新阶段 private void NotifyPhaseAwareObjects(ArchitecturePhase phase) { - foreach (var obj in Container.GetAll()) + foreach (var obj in Container.GetAll()) { _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( /// /// 生命周期钩子实例 /// 注册的钩子实例 - public IArchitectureLifecycle RegisterLifecycleHook(IArchitectureLifecycle hook) + public IArchitectureLifecycleHook RegisterLifecycleHook(IArchitectureLifecycleHook hook) { if (CurrentPhase >= ArchitecturePhase.Ready && !Configuration.ArchitectureProperties.AllowLateRegistration) throw new InvalidOperationException( diff --git a/GFramework.Game/architecture/AbstractModule.cs b/GFramework.Game/architecture/AbstractModule.cs deleted file mode 100644 index d4d2551..0000000 --- a/GFramework.Game/architecture/AbstractModule.cs +++ /dev/null @@ -1,33 +0,0 @@ -using GFramework.Core.Abstractions.architecture; -using GFramework.Core.Abstractions.enums; - -namespace GFramework.Game.architecture; - -/// -/// 抽象模块类,实现IArchitectureModule接口,为架构模块提供基础功能 -/// -public abstract class AbstractModule : IArchitectureModule -{ - /// - /// 在指定架构阶段执行的操作 - /// - /// 架构阶段枚举值 - /// 架构实例 - public virtual void OnPhase(ArchitecturePhase phase, IArchitecture architecture) - { - } - - /// - /// 在架构阶段执行的操作 - /// - /// 架构阶段枚举值 - public virtual void OnArchitecturePhase(ArchitecturePhase phase) - { - } - - /// - /// 安装模块到架构中 - /// - /// 要安装到的架构实例 - public abstract void Install(IArchitecture architecture); -} \ No newline at end of file