refactor(architecture): 重构架构类为模块化设计提升代码安全性#112
Conversation
- 将单一 Architecture 类拆分为 ArchitectureLifecycle、ArchitectureComponentRegistry 和 ArchitectureModules - 消除 3 处 null! 强制断言,在构造函数中初始化管理器提高代码安全性 - 添加 PhaseChanged 事件支持架构阶段监听 - 所有公共 API 保持不变确保向后兼容 - 实现单一职责原则使代码更易维护和测试 - 组件注册、生命周期管理和模块管理职责分离到专门的管理器中
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| C# | Mar 17, 2026 4:50a.m. | Review ↗ | |
| Secrets | Mar 17, 2026 4:50a.m. | Review ↗ |
审阅者指南在保持公共 API 稳定的前提下,将核心 Architecture 类重构为“协调器 + 管理器”(生命周期、组件注册表、模块)的模块化设计;改进生命周期安全性,新增 PhaseChanged 事件,并更新文档/测试以符合新的架构以及构造期初始化语义。 Architecture 初始化生命周期时序图(v1.1.0)sequenceDiagram
actor App
participant Arch as Architecture
participant Lifecycle as ArchitectureLifecycle
participant Services as IArchitectureServices
participant Container as IIocContainer
participant Env as IEnvironment
participant Modules as IArchitectureModuleManager
participant UserArch as DerivedArchitecture
participant Util as IContextUtility
participant Model as IModel
participant Sys as ISystem
App->>Arch: new DerivedArchitecture(configuration, environment, services, context)
activate Arch
Arch->>Arch: constructor
Arch->>Arch: LoggerFactoryResolver.Provider = configuration.LoggerProperties.LoggerFactoryProvider
Arch->>Arch: _logger = CreateLogger()
Arch->>Lifecycle: new ArchitectureLifecycle(Arch, configuration, services, _logger)
Arch->>Arch: _lifecycle = Lifecycle
Arch->>Arch: _componentRegistry = new ArchitectureComponentRegistry(...)
Arch->>Arch: _modules = new ArchitectureModules(...)
deactivate Arch
App->>Arch: InitializeAsync()
activate Arch
Arch->>Arch: InitializeInternalAsync(asyncMode:true)
Arch->>Env: Initialize()
activate Env
Env-->>Arch: done
deactivate Env
Arch->>Modules: RegisterBuiltInModules(Services.Container)
activate Modules
Modules-->>Arch: done
deactivate Modules
Arch->>Container: Contains<IEnvironment>()
alt not registered
Arch->>Container: RegisterPlurality(Environment)
end
Arch->>Arch: _context = new ArchitectureContext(Services.Container)
Arch->>Arch: GameContext.Bind(GetType(), _context)
Arch->>Services: set Context on internal services
Arch->>Container: ExecuteServicesHook(Configurator)
Arch->>Modules: InitializeAllAsync(asyncMode:true)
Modules-->>Arch: done
Arch->>UserArch: OnInitialize()
activate UserArch
UserArch->>Arch: RegisterUtility(Util)
Arch->>Arch: _componentRegistry.RegisterUtility(Util)
Arch->>Util: IfType<IContextUtility>.SetContext(Context)
Arch->>Lifecycle: RegisterLifecycleComponent(Util)
UserArch->>Arch: RegisterModel(Model)
Arch->>Arch: _componentRegistry.RegisterModel(Model)
Arch->>Model: SetContext(Context)
Arch->>Lifecycle: RegisterLifecycleComponent(Model)
UserArch->>Arch: RegisterSystem(Sys)
Arch->>Arch: _componentRegistry.RegisterSystem(Sys)
Arch->>Sys: SetContext(Context)
Arch->>Lifecycle: RegisterLifecycleComponent(Sys)
deactivate UserArch
Arch->>Lifecycle: InitializeAllComponentsAsync(asyncMode:true)
activate Lifecycle
Lifecycle->>Lifecycle: EnterPhase(BeforeUtilityInit)
Lifecycle->>Util: InitializeAsync()
Util-->>Lifecycle: done
Lifecycle->>Lifecycle: EnterPhase(AfterUtilityInit)
Lifecycle->>Lifecycle: EnterPhase(BeforeModelInit)
Lifecycle->>Model: InitializeAsync() or Initialize()
Model-->>Lifecycle: done
Lifecycle->>Lifecycle: EnterPhase(AfterModelInit)
Lifecycle->>Lifecycle: EnterPhase(BeforeSystemInit)
Lifecycle->>Sys: InitializeAsync() or Initialize()
Sys-->>Lifecycle: done
Lifecycle->>Lifecycle: EnterPhase(AfterSystemInit)
Lifecycle-->>Arch: all components initialized
deactivate Lifecycle
Arch->>Container: Freeze()
Arch->>Lifecycle: MarkAsReady()
activate Lifecycle
Lifecycle->>Lifecycle: EnterPhase(Ready)
Lifecycle->>Lifecycle: _readyTcs.TrySetResult()
deactivate Lifecycle
Arch-->>App: InitializeAsync completed
deactivate Arch
App->>Arch: WaitUntilReadyAsync()
Arch->>Lifecycle: WaitUntilReadyAsync()
Lifecycle-->>Arch: completed Task (already Ready)
Arch-->>App: return
模块化 Architecture 协调器与管理器的类图classDiagram
direction LR
class IArchitecture {
<<interface>>
+ArchitecturePhase CurrentPhase
+IArchitectureContext Context
+bool IsReady
+void Initialize()
+Task InitializeAsync()
+ValueTask DestroyAsync()
+void Destroy()
+TSystem RegisterSystem~TSystem~(TSystem system)
+void RegisterSystem~T~(Action~T~ onCreated)
+TModel RegisterModel~TModel~(TModel model)
+void RegisterModel~T~(Action~T~ onCreated)
+TUtility RegisterUtility~TUtility~(TUtility utility)
+void RegisterUtility~T~(Action~T~ onCreated)
+IArchitectureModule InstallModule(IArchitectureModule module)
+IArchitectureLifecycleHook RegisterLifecycleHook(IArchitectureLifecycleHook hook)
+Task WaitUntilReadyAsync()
+event PhaseChanged(ArchitecturePhase phase)
}
class Architecture {
-IArchitectureConfiguration Configuration
-IEnvironment Environment
-IArchitectureServices Services
-ILogger _logger
-IArchitectureContext _context
-ArchitectureLifecycle _lifecycle
-ArchitectureComponentRegistry _componentRegistry
-ArchitectureModules _modules
+ArchitecturePhase CurrentPhase
+IArchitectureContext Context
+bool IsReady
+Action~IServiceCollection~ Configurator
+event PhaseChanged(ArchitecturePhase phase)
+Architecture(IArchitectureConfiguration configuration, IEnvironment environment, IArchitectureServices services, IArchitectureContext context)
+IArchitectureLifecycleHook RegisterLifecycleHook(IArchitectureLifecycleHook hook)
+void RegisterMediatorBehavior~TBehavior~()
+IArchitectureModule InstallModule(IArchitectureModule module)
+TSystem RegisterSystem~TSystem~(TSystem system)
+void RegisterSystem~T~(Action~T~ onCreated)
+TModel RegisterModel~TModel~(TModel model)
+void RegisterModel~T~(Action~T~ onCreated)
+TUtility RegisterUtility~TUtility~(TUtility utility)
+void RegisterUtility~T~(Action~T~ onCreated)
+void Initialize()
+Task InitializeAsync()
+Task WaitUntilReadyAsync()
+ValueTask DestroyAsync()
+void Destroy()
#void OnInitialize()
}
class ArchitectureLifecycle {
-IArchitecture _architecture
-IArchitectureConfiguration _configuration
-IArchitectureServices _services
-ILogger _logger
-TaskCompletionSource _readyTcs
-HashSet~IInitializable~ _pendingInitializableSet
-List~IInitializable~ _pendingInitializableList
-HashSet~object~ _disposableSet
-List~object~ _disposables
-List~IArchitectureLifecycleHook~ _lifecycleHooks
-bool _initialized
+ArchitecturePhase CurrentPhase
+bool IsReady
+bool IsInitialized
+event PhaseChanged(ArchitecturePhase phase)
+ArchitectureLifecycle(IArchitecture architecture, IArchitectureConfiguration configuration, IArchitectureServices services, ILogger logger)
+IArchitectureLifecycleHook RegisterLifecycleHook(IArchitectureLifecycleHook hook)
+void RegisterLifecycleComponent~T~(T component)
+void EnterPhase(ArchitecturePhase next)
+Task InitializeAllComponentsAsync(bool asyncMode)
+ValueTask DestroyAsync()
+void Destroy()
+void MarkAsReady()
+void MarkAsFailed(Exception exception)
+Task WaitUntilReadyAsync()
}
class ArchitectureComponentRegistry {
-IArchitecture architecture
-IArchitectureConfiguration configuration
-IArchitectureServices services
-ArchitectureLifecycle lifecycle
-ILogger logger
+ArchitectureComponentRegistry(IArchitecture architecture, IArchitectureConfiguration configuration, IArchitectureServices services, ArchitectureLifecycle lifecycle, ILogger logger)
+TSystem RegisterSystem~TSystem~(TSystem system)
+void RegisterSystem~T~(Action~T~ onCreated)
+TModel RegisterModel~TModel~(TModel model)
+void RegisterModel~T~(Action~T~ onCreated)
+TUtility RegisterUtility~TUtility~(TUtility utility)
+void RegisterUtility~T~(Action~T~ onCreated)
}
class ArchitectureModules {
-IArchitecture architecture
-IArchitectureServices services
-ILogger logger
+ArchitectureModules(IArchitecture architecture, IArchitectureServices services, ILogger logger)
+void RegisterMediatorBehavior~TBehavior~()
+IArchitectureModule InstallModule(IArchitectureModule module)
}
class IArchitectureLifecycleHook {
<<interface>>
+void OnPhase(ArchitecturePhase phase, IArchitecture architecture)
}
class IArchitecturePhaseListener {
<<interface>>
+void OnArchitecturePhase(ArchitecturePhase phase)
}
class IArchitectureModule {
<<interface>>
+void Install(IArchitecture architecture)
}
class IArchitectureServices {
<<interface>>
+IIocContainer Container
+IArchitectureModuleManager ModuleManager
}
class IIocContainer {
<<interface>>
+void RegisterPlurality~T~(T instance)
+void RegisterFactory~T~(Func~IServiceProvider,T~ factory)
+IEnumerable~T~ GetAll~T~()
+bool Contains~T~()
+void RegisterMediatorBehavior~TBehavior~()
+void ExecuteServicesHook(Action~IServiceCollection~ configurator)
+void Freeze()
+void Clear()
}
class IArchitectureModuleManager {
<<interface>>
+void RegisterBuiltInModules(IIocContainer container)
+Task InitializeAllAsync(bool asyncMode)
+ValueTask DestroyAllAsync()
}
class IModel {
<<interface>>
+void SetContext(IArchitectureContext context)
}
class ISystem {
<<interface>>
+void SetContext(IArchitectureContext context)
}
class IUtility {
<<interface>>
}
class IContextUtility {
<<interface>>
+void SetContext(IArchitectureContext context)
}
class IInitializable {
<<interface>>
+void Initialize()
}
class IAsyncInitializable {
<<interface>>
+Task InitializeAsync()
}
class IDestroyable {
<<interface>>
+void Destroy()
}
class IAsyncDestroyable {
<<interface>>
+ValueTask DestroyAsync()
}
IArchitecture <|.. Architecture
Architecture --> ArchitectureLifecycle : composes
Architecture --> ArchitectureComponentRegistry : composes
Architecture --> ArchitectureModules : composes
Architecture --> IArchitectureServices : uses
Architecture --> IEnvironment : uses
ArchitectureLifecycle --> IArchitecture : coordinates
ArchitectureLifecycle --> IArchitectureServices : uses
ArchitectureLifecycle --> IArchitectureLifecycleHook : manages
ArchitectureLifecycle --> IArchitecturePhaseListener : notifies
ArchitectureLifecycle --> IInitializable : manages
ArchitectureLifecycle --> IAsyncInitializable : manages
ArchitectureLifecycle --> IDestroyable : manages
ArchitectureLifecycle --> IAsyncDestroyable : manages
ArchitectureComponentRegistry --> IArchitecture : uses
ArchitectureComponentRegistry --> IArchitectureServices : uses
ArchitectureComponentRegistry --> ArchitectureLifecycle : uses
ArchitectureComponentRegistry --> IModel : registers
ArchitectureComponentRegistry --> ISystem : registers
ArchitectureComponentRegistry --> IUtility : registers
ArchitectureComponentRegistry --> IContextUtility : registers
ArchitectureModules --> IArchitecture : uses
ArchitectureModules --> IArchitectureServices : uses
ArchitectureModules --> IArchitectureModule : installs
IArchitectureServices --> IIocContainer : has
IArchitectureServices --> IArchitectureModuleManager : has
IContextUtility --|> IUtility
IAsyncInitializable --|> IInitializable
IAsyncDestroyable --|> IDestroyable
文件级变更
提示与命令与 Sourcery 交互
自定义你的体验访问你的 控制台 可以:
获取帮助Original review guide in EnglishReviewer's GuideRefactors the core Architecture class into a modular coordinator-plus-managers design (lifecycle, component registry, modules) while keeping the public APIs stable, improving lifecycle safety, adding a PhaseChanged event, and updating docs/tests to match the new architecture and construction-time initialization semantics. Sequence diagram for Architecture initialization lifecycle (v1.1.0)sequenceDiagram
actor App
participant Arch as Architecture
participant Lifecycle as ArchitectureLifecycle
participant Services as IArchitectureServices
participant Container as IIocContainer
participant Env as IEnvironment
participant Modules as IArchitectureModuleManager
participant UserArch as DerivedArchitecture
participant Util as IContextUtility
participant Model as IModel
participant Sys as ISystem
App->>Arch: new DerivedArchitecture(configuration, environment, services, context)
activate Arch
Arch->>Arch: constructor
Arch->>Arch: LoggerFactoryResolver.Provider = configuration.LoggerProperties.LoggerFactoryProvider
Arch->>Arch: _logger = CreateLogger()
Arch->>Lifecycle: new ArchitectureLifecycle(Arch, configuration, services, _logger)
Arch->>Arch: _lifecycle = Lifecycle
Arch->>Arch: _componentRegistry = new ArchitectureComponentRegistry(...)
Arch->>Arch: _modules = new ArchitectureModules(...)
deactivate Arch
App->>Arch: InitializeAsync()
activate Arch
Arch->>Arch: InitializeInternalAsync(asyncMode:true)
Arch->>Env: Initialize()
activate Env
Env-->>Arch: done
deactivate Env
Arch->>Modules: RegisterBuiltInModules(Services.Container)
activate Modules
Modules-->>Arch: done
deactivate Modules
Arch->>Container: Contains<IEnvironment>()
alt not registered
Arch->>Container: RegisterPlurality(Environment)
end
Arch->>Arch: _context = new ArchitectureContext(Services.Container)
Arch->>Arch: GameContext.Bind(GetType(), _context)
Arch->>Services: set Context on internal services
Arch->>Container: ExecuteServicesHook(Configurator)
Arch->>Modules: InitializeAllAsync(asyncMode:true)
Modules-->>Arch: done
Arch->>UserArch: OnInitialize()
activate UserArch
UserArch->>Arch: RegisterUtility(Util)
Arch->>Arch: _componentRegistry.RegisterUtility(Util)
Arch->>Util: IfType<IContextUtility>.SetContext(Context)
Arch->>Lifecycle: RegisterLifecycleComponent(Util)
UserArch->>Arch: RegisterModel(Model)
Arch->>Arch: _componentRegistry.RegisterModel(Model)
Arch->>Model: SetContext(Context)
Arch->>Lifecycle: RegisterLifecycleComponent(Model)
UserArch->>Arch: RegisterSystem(Sys)
Arch->>Arch: _componentRegistry.RegisterSystem(Sys)
Arch->>Sys: SetContext(Context)
Arch->>Lifecycle: RegisterLifecycleComponent(Sys)
deactivate UserArch
Arch->>Lifecycle: InitializeAllComponentsAsync(asyncMode:true)
activate Lifecycle
Lifecycle->>Lifecycle: EnterPhase(BeforeUtilityInit)
Lifecycle->>Util: InitializeAsync()
Util-->>Lifecycle: done
Lifecycle->>Lifecycle: EnterPhase(AfterUtilityInit)
Lifecycle->>Lifecycle: EnterPhase(BeforeModelInit)
Lifecycle->>Model: InitializeAsync() or Initialize()
Model-->>Lifecycle: done
Lifecycle->>Lifecycle: EnterPhase(AfterModelInit)
Lifecycle->>Lifecycle: EnterPhase(BeforeSystemInit)
Lifecycle->>Sys: InitializeAsync() or Initialize()
Sys-->>Lifecycle: done
Lifecycle->>Lifecycle: EnterPhase(AfterSystemInit)
Lifecycle-->>Arch: all components initialized
deactivate Lifecycle
Arch->>Container: Freeze()
Arch->>Lifecycle: MarkAsReady()
activate Lifecycle
Lifecycle->>Lifecycle: EnterPhase(Ready)
Lifecycle->>Lifecycle: _readyTcs.TrySetResult()
deactivate Lifecycle
Arch-->>App: InitializeAsync completed
deactivate Arch
App->>Arch: WaitUntilReadyAsync()
Arch->>Lifecycle: WaitUntilReadyAsync()
Lifecycle-->>Arch: completed Task (already Ready)
Arch-->>App: return
Class diagram for modular Architecture coordinator and managersclassDiagram
direction LR
class IArchitecture {
<<interface>>
+ArchitecturePhase CurrentPhase
+IArchitectureContext Context
+bool IsReady
+void Initialize()
+Task InitializeAsync()
+ValueTask DestroyAsync()
+void Destroy()
+TSystem RegisterSystem~TSystem~(TSystem system)
+void RegisterSystem~T~(Action~T~ onCreated)
+TModel RegisterModel~TModel~(TModel model)
+void RegisterModel~T~(Action~T~ onCreated)
+TUtility RegisterUtility~TUtility~(TUtility utility)
+void RegisterUtility~T~(Action~T~ onCreated)
+IArchitectureModule InstallModule(IArchitectureModule module)
+IArchitectureLifecycleHook RegisterLifecycleHook(IArchitectureLifecycleHook hook)
+Task WaitUntilReadyAsync()
+event PhaseChanged(ArchitecturePhase phase)
}
class Architecture {
-IArchitectureConfiguration Configuration
-IEnvironment Environment
-IArchitectureServices Services
-ILogger _logger
-IArchitectureContext _context
-ArchitectureLifecycle _lifecycle
-ArchitectureComponentRegistry _componentRegistry
-ArchitectureModules _modules
+ArchitecturePhase CurrentPhase
+IArchitectureContext Context
+bool IsReady
+Action~IServiceCollection~ Configurator
+event PhaseChanged(ArchitecturePhase phase)
+Architecture(IArchitectureConfiguration configuration, IEnvironment environment, IArchitectureServices services, IArchitectureContext context)
+IArchitectureLifecycleHook RegisterLifecycleHook(IArchitectureLifecycleHook hook)
+void RegisterMediatorBehavior~TBehavior~()
+IArchitectureModule InstallModule(IArchitectureModule module)
+TSystem RegisterSystem~TSystem~(TSystem system)
+void RegisterSystem~T~(Action~T~ onCreated)
+TModel RegisterModel~TModel~(TModel model)
+void RegisterModel~T~(Action~T~ onCreated)
+TUtility RegisterUtility~TUtility~(TUtility utility)
+void RegisterUtility~T~(Action~T~ onCreated)
+void Initialize()
+Task InitializeAsync()
+Task WaitUntilReadyAsync()
+ValueTask DestroyAsync()
+void Destroy()
#void OnInitialize()
}
class ArchitectureLifecycle {
-IArchitecture _architecture
-IArchitectureConfiguration _configuration
-IArchitectureServices _services
-ILogger _logger
-TaskCompletionSource _readyTcs
-HashSet~IInitializable~ _pendingInitializableSet
-List~IInitializable~ _pendingInitializableList
-HashSet~object~ _disposableSet
-List~object~ _disposables
-List~IArchitectureLifecycleHook~ _lifecycleHooks
-bool _initialized
+ArchitecturePhase CurrentPhase
+bool IsReady
+bool IsInitialized
+event PhaseChanged(ArchitecturePhase phase)
+ArchitectureLifecycle(IArchitecture architecture, IArchitectureConfiguration configuration, IArchitectureServices services, ILogger logger)
+IArchitectureLifecycleHook RegisterLifecycleHook(IArchitectureLifecycleHook hook)
+void RegisterLifecycleComponent~T~(T component)
+void EnterPhase(ArchitecturePhase next)
+Task InitializeAllComponentsAsync(bool asyncMode)
+ValueTask DestroyAsync()
+void Destroy()
+void MarkAsReady()
+void MarkAsFailed(Exception exception)
+Task WaitUntilReadyAsync()
}
class ArchitectureComponentRegistry {
-IArchitecture architecture
-IArchitectureConfiguration configuration
-IArchitectureServices services
-ArchitectureLifecycle lifecycle
-ILogger logger
+ArchitectureComponentRegistry(IArchitecture architecture, IArchitectureConfiguration configuration, IArchitectureServices services, ArchitectureLifecycle lifecycle, ILogger logger)
+TSystem RegisterSystem~TSystem~(TSystem system)
+void RegisterSystem~T~(Action~T~ onCreated)
+TModel RegisterModel~TModel~(TModel model)
+void RegisterModel~T~(Action~T~ onCreated)
+TUtility RegisterUtility~TUtility~(TUtility utility)
+void RegisterUtility~T~(Action~T~ onCreated)
}
class ArchitectureModules {
-IArchitecture architecture
-IArchitectureServices services
-ILogger logger
+ArchitectureModules(IArchitecture architecture, IArchitectureServices services, ILogger logger)
+void RegisterMediatorBehavior~TBehavior~()
+IArchitectureModule InstallModule(IArchitectureModule module)
}
class IArchitectureLifecycleHook {
<<interface>>
+void OnPhase(ArchitecturePhase phase, IArchitecture architecture)
}
class IArchitecturePhaseListener {
<<interface>>
+void OnArchitecturePhase(ArchitecturePhase phase)
}
class IArchitectureModule {
<<interface>>
+void Install(IArchitecture architecture)
}
class IArchitectureServices {
<<interface>>
+IIocContainer Container
+IArchitectureModuleManager ModuleManager
}
class IIocContainer {
<<interface>>
+void RegisterPlurality~T~(T instance)
+void RegisterFactory~T~(Func~IServiceProvider,T~ factory)
+IEnumerable~T~ GetAll~T~()
+bool Contains~T~()
+void RegisterMediatorBehavior~TBehavior~()
+void ExecuteServicesHook(Action~IServiceCollection~ configurator)
+void Freeze()
+void Clear()
}
class IArchitectureModuleManager {
<<interface>>
+void RegisterBuiltInModules(IIocContainer container)
+Task InitializeAllAsync(bool asyncMode)
+ValueTask DestroyAllAsync()
}
class IModel {
<<interface>>
+void SetContext(IArchitectureContext context)
}
class ISystem {
<<interface>>
+void SetContext(IArchitectureContext context)
}
class IUtility {
<<interface>>
}
class IContextUtility {
<<interface>>
+void SetContext(IArchitectureContext context)
}
class IInitializable {
<<interface>>
+void Initialize()
}
class IAsyncInitializable {
<<interface>>
+Task InitializeAsync()
}
class IDestroyable {
<<interface>>
+void Destroy()
}
class IAsyncDestroyable {
<<interface>>
+ValueTask DestroyAsync()
}
IArchitecture <|.. Architecture
Architecture --> ArchitectureLifecycle : composes
Architecture --> ArchitectureComponentRegistry : composes
Architecture --> ArchitectureModules : composes
Architecture --> IArchitectureServices : uses
Architecture --> IEnvironment : uses
ArchitectureLifecycle --> IArchitecture : coordinates
ArchitectureLifecycle --> IArchitectureServices : uses
ArchitectureLifecycle --> IArchitectureLifecycleHook : manages
ArchitectureLifecycle --> IArchitecturePhaseListener : notifies
ArchitectureLifecycle --> IInitializable : manages
ArchitectureLifecycle --> IAsyncInitializable : manages
ArchitectureLifecycle --> IDestroyable : manages
ArchitectureLifecycle --> IAsyncDestroyable : manages
ArchitectureComponentRegistry --> IArchitecture : uses
ArchitectureComponentRegistry --> IArchitectureServices : uses
ArchitectureComponentRegistry --> ArchitectureLifecycle : uses
ArchitectureComponentRegistry --> IModel : registers
ArchitectureComponentRegistry --> ISystem : registers
ArchitectureComponentRegistry --> IUtility : registers
ArchitectureComponentRegistry --> IContextUtility : registers
ArchitectureModules --> IArchitecture : uses
ArchitectureModules --> IArchitectureServices : uses
ArchitectureModules --> IArchitectureModule : installs
IArchitectureServices --> IIocContainer : has
IArchitectureServices --> IArchitectureModuleManager : has
IContextUtility --|> IUtility
IAsyncInitializable --|> IInitializable
IAsyncDestroyable --|> IDestroyable
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
你好——我发现了两个问题,并留下了一些整体层面的反馈:
- 在
ArchitectureLifecycle.DestroyAsync中,你现在在CurrentPhase == ArchitecturePhase.None时会提前返回;这可能会跳过对那些在初始化之前就已注册并添加到_disposables中的组件的释放,而这些组件之前是会被清理掉的——建议在这种状态下仍然执行释放路径(或者禁止注册),以避免产生泄漏。 - 新增的
ArchitectureLifecycle中的RegisterLifecycleComponent<T>并没有用到它的泛型类型参数,而且只对若干接口类型进行操作;你可以将方法签名简化为接收object(或特定的生命周期接口),以减少不必要的泛型噪音。
给 AI Agent 的提示
Please address the comments from this code review:
## Overall Comments
- In `ArchitectureLifecycle.DestroyAsync` you now return early when `CurrentPhase == ArchitecturePhase.None`; this can skip disposing components that were registered before initialization and added to `_disposables`, which previously would have been cleaned up—consider still running the disposal path (or preventing registration) in this state to avoid leaks.
- The new `RegisterLifecycleComponent<T>` in `ArchitectureLifecycle` doesn’t use its generic type parameter and only operates on interface types; you could simplify the signature to accept `object` (or specific lifecycle interfaces) to reduce unnecessary generic noise.
## Individual Comments
### Comment 1
<location path="GFramework.Core/Architectures/ArchitectureLifecycle.cs" line_range="62-71" />
<code_context>
+ public void RegisterLifecycleComponent<T>(T component)
</code_context>
<issue_to_address>
**suggestion:** Consider removing the generic type parameter from RegisterLifecycleComponent since it is unused.
Since `T` isn’t used and the method relies on the runtime type of `component`, you can change the signature to something like `public void RegisterLifecycleComponent(object component)` (or a relevant interface). This avoids unnecessary generic instantiation, reduces caller noise, and keeps the API surface smaller.
Suggested implementation:
```csharp
/// <summary>
/// 统一的组件生命周期注册逻辑
/// </summary>
/// <param name="component">要注册的组件</param>
public void RegisterLifecycleComponent(object component)
```
1. Update all call sites of `RegisterLifecycleComponent` to remove the generic type argument, e.g. change `RegisterLifecycleComponent<MyType>(myInstance)` to `RegisterLifecycleComponent(myInstance)`.
2. If there are any references using method group syntax or reflection that assume a generic signature (e.g. `MethodInfo` lookups), adjust them to use the non-generic `RegisterLifecycleComponent(object component)` signature.
</issue_to_address>
### Comment 2
<location path="docs/zh-CN/core/architecture.md" line_range="219-221" />
<code_context>
+ │ ├─> 优先调用 IAsyncDestroyable.DestroyAsync()
+ │ └─> 否则调用 IDestroyable.Destroy()
+ ├─> 销毁服务模块
+ ├─> 清空 IOC 容器
+ └─> 进入 Destroyed 阶段
+```
</code_context>
<issue_to_address>
**suggestion (typo):** “IOC 容器”的大小写与文中其他“IoC 容器”的写法不一致。
建议将此处改为 “IoC 容器”,与前文保持一致,避免被理解为不同概念。
```suggestion
├─> 销毁服务模块
├─> 清空 IoC 容器
└─> 进入 Destroyed 阶段
```
</issue_to_address>帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续评审。
Original comment in English
Hey - I've found 2 issues, and left some high level feedback:
- In
ArchitectureLifecycle.DestroyAsyncyou now return early whenCurrentPhase == ArchitecturePhase.None; this can skip disposing components that were registered before initialization and added to_disposables, which previously would have been cleaned up—consider still running the disposal path (or preventing registration) in this state to avoid leaks. - The new
RegisterLifecycleComponent<T>inArchitectureLifecycledoesn’t use its generic type parameter and only operates on interface types; you could simplify the signature to acceptobject(or specific lifecycle interfaces) to reduce unnecessary generic noise.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `ArchitectureLifecycle.DestroyAsync` you now return early when `CurrentPhase == ArchitecturePhase.None`; this can skip disposing components that were registered before initialization and added to `_disposables`, which previously would have been cleaned up—consider still running the disposal path (or preventing registration) in this state to avoid leaks.
- The new `RegisterLifecycleComponent<T>` in `ArchitectureLifecycle` doesn’t use its generic type parameter and only operates on interface types; you could simplify the signature to accept `object` (or specific lifecycle interfaces) to reduce unnecessary generic noise.
## Individual Comments
### Comment 1
<location path="GFramework.Core/Architectures/ArchitectureLifecycle.cs" line_range="62-71" />
<code_context>
+ public void RegisterLifecycleComponent<T>(T component)
</code_context>
<issue_to_address>
**suggestion:** Consider removing the generic type parameter from RegisterLifecycleComponent since it is unused.
Since `T` isn’t used and the method relies on the runtime type of `component`, you can change the signature to something like `public void RegisterLifecycleComponent(object component)` (or a relevant interface). This avoids unnecessary generic instantiation, reduces caller noise, and keeps the API surface smaller.
Suggested implementation:
```csharp
/// <summary>
/// 统一的组件生命周期注册逻辑
/// </summary>
/// <param name="component">要注册的组件</param>
public void RegisterLifecycleComponent(object component)
```
1. Update all call sites of `RegisterLifecycleComponent` to remove the generic type argument, e.g. change `RegisterLifecycleComponent<MyType>(myInstance)` to `RegisterLifecycleComponent(myInstance)`.
2. If there are any references using method group syntax or reflection that assume a generic signature (e.g. `MethodInfo` lookups), adjust them to use the non-generic `RegisterLifecycleComponent(object component)` signature.
</issue_to_address>
### Comment 2
<location path="docs/zh-CN/core/architecture.md" line_range="219-221" />
<code_context>
+ │ ├─> 优先调用 IAsyncDestroyable.DestroyAsync()
+ │ └─> 否则调用 IDestroyable.Destroy()
+ ├─> 销毁服务模块
+ ├─> 清空 IOC 容器
+ └─> 进入 Destroyed 阶段
+```
</code_context>
<issue_to_address>
**suggestion (typo):** “IOC 容器”的大小写与文中其他“IoC 容器”的写法不一致。
建议将此处改为 “IoC 容器”,与前文保持一致,避免被理解为不同概念。
```suggestion
├─> 销毁服务模块
├─> 清空 IoC 容器
└─> 进入 Destroyed 阶段
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
- 将文档中的"IOC"统一更正为"IoC"格式 - 重构ArchitectureLifecycle类构造函数使用主构造函数语法 - 移除私有字段前缀下划线,直接使用参数名称 - 修复配置访问权限问题,移除字段访问前缀下划线 - 调整组件注册方法泛型约束,提升类型安全 - 优化日志记录器访问方式,移除字段访问前缀下划线 - 重构销毁逻辑,分离组件清理和服务模块销毁流程 - 提取清理组件逻辑到独立方法,提升代码可读性 - 更新阶段转换和钩子通知中的对象引用方式
Summary by Sourcery
将核心的 Architecture 类重构为一个模块化的协调器,通过专门的管理类来委托生命周期管理、组件注册和模块管理,同时保持现有的公共 API 不变。
Enhancements:
Documentation:
Tests:
Chores:
Original summary in English
Summary by Sourcery
Refactor the core Architecture class into a modular coordinator that delegates lifecycle, component registration, and module management to dedicated manager classes while preserving the public API.
Enhancements:
Documentation:
Tests:
Chores: