Skip to content

Refactor/extract ecs to independent module#89

Merged
GeWuYou merged 7 commits into
mainfrom
refactor/extract-ecs-to-independent-module
Mar 8, 2026
Merged

Refactor/extract ecs to independent module#89
GeWuYou merged 7 commits into
mainfrom
refactor/extract-ecs-to-independent-module

Conversation

@GeWuYou
Copy link
Copy Markdown
Owner

@GeWuYou GeWuYou commented Mar 8, 2026

Summary by Sourcery

将基于 Arch 的 ECS 抽取到独立的 GFramework.Ecs.Arch 模块中,并提供显式、按需启用(opt‑in)的注册与集成 API。

New Features:

  • 引入 GFramework.Ecs.ArchGFramework.Ecs.Arch.Abstractions 包,将 Arch ECS 集成从核心中分离出来单独托管。
  • 新增 ArchOptions 配置对象和 UseArch 扩展方法,用于在架构实例上显式启用并配置 Arch ECS。
  • 定义 IArchSystemAdapter<T>IArchEcsModule 抽象,以规范 ECS 集成契约。

Enhancements:

  • 优化 ArchSystemAdapter,使其实现新的 IArchSystemAdapter<T> 接口,并将其移动到新的 GFramework.Ecs.Arch 命名空间下。
  • 新增 ArchitectureModuleRegistry,以支持发现并自动注册外部服务模块。
  • 更新 ServiceModuleManager,改为始终注册核心模块,然后通过 ArchitectureModuleRegistry 注册外部模块,而不再使用 EnableEcs 标志。
  • 将与 ECS 相关的组件、系统和测试迁移到新的 GFramework.Ecs.Arch 项目与命名空间中,从而将核心与 Arch 依赖解耦。
  • 为新的 GFramework.Ecs.Arch 包新增文档,包括用法、配置以及生命周期细节。

Build:

  • 新增 GFramework.Ecs.ArchGFramework.Ecs.Arch.AbstractionsGFramework.Ecs.Arch.Tests 项目,并将其接入解决方案及顶层项目引用中。

Documentation:

  • GFramework.Ecs.Arch 包新增 README,记录特性、配置方式和集成模式。

Tests:

  • 创建 GFramework.Ecs.Arch.Tests 项目,并将 ECS 基础、高级和集成测试迁移至此,与新的命名空间保持一致。
  • 移除已废弃的 EnableEcs 配置开关相关测试,因为在显式模块注册后已不再适用。

Chores:

  • ArchitectureProperties 中移除 EnableEcs 属性,因为 ECS 现已通过显式模块注册启用。
Original summary in English

Summary by Sourcery

Extract Arch-based ECS into a dedicated GFramework.Ecs.Arch module with explicit, opt‑in registration and integration APIs.

New Features:

  • Introduce GFramework.Ecs.Arch and GFramework.Ecs.Arch.Abstractions packages to host Arch ECS integration separately from the core.
  • Add ArchOptions configuration object and UseArch extension method for explicitly enabling and configuring Arch ECS on an architecture instance.
  • Define IArchSystemAdapter and IArchEcsModule abstractions to formalize the ECS integration contract.

Enhancements:

  • Refine ArchSystemAdapter to implement the new IArchSystemAdapter interface and move it into the new GFramework.Ecs.Arch namespace.
  • Add ArchitectureModuleRegistry to support discovery and automatic registration of external service modules.
  • Update ServiceModuleManager to always register core modules and then register external modules via ArchitectureModuleRegistry instead of using an EnableEcs flag.
  • Move ECS-related components, systems, and tests into the new GFramework.Ecs.Arch projects and namespaces, decoupling core from Arch dependencies.
  • Add documentation for the new GFramework.Ecs.Arch package, including usage, configuration, and lifecycle details.

Build:

  • Add new GFramework.Ecs.Arch, GFramework.Ecs.Arch.Abstractions, and GFramework.Ecs.Arch.Tests projects and wire them into the solution and top-level project references.

Documentation:

  • Add README for the GFramework.Ecs.Arch package documenting features, configuration, and integration patterns.

Tests:

  • Create GFramework.Ecs.Arch.Tests project and move ECS basic, advanced, and integration tests there, aligned with the new namespaces.
  • Remove obsolete EnableEcs configuration toggle test that no longer applies with explicit module registration.

Chores:

  • Remove the EnableEcs property from ArchitectureProperties now that ECS is enabled via explicit module registration.

GeWuYou added 2 commits March 8, 2026 19:45
- 删除Position组件结构体定义
- 删除Velocity组件结构体定义
- 删除MovementSystem移动系统实现
- 移除ArchEcsModule ECS模块管理器
- 删除ArchSystemAdapter适配器基类
- 从ServiceModuleManager中移除ECS模块注册逻辑
- 从ArchitectureProperties中移除EnableEcs配置选项
- 删除ECS相关的单元测试文件
- 从项目文件中移除Arch和Arch.System包引用
- 从解决方案文件中移除ECS相关项目引用
- 更新项目配置文件中的目标框架和测试项目属性
- 移除自动初始化器,改用显式注册方式
- 修改 UseArch 扩展方法支持可选配置参数
- 更新文档说明新的集成方式和配置选项
- 删除自动注册相关的测试代码
- 调整 README 中的使用示例和架构说明
@deepsource-io
Copy link
Copy Markdown

deepsource-io Bot commented Mar 8, 2026

DeepSource Code Review

We reviewed changes in 23f186d...f771b7d on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

Important

Some issues found as part of this review are outside of the diff in this pull request and aren't shown in the inline review comments due to GitHub's API limitations. You can see those issues on the DeepSource dashboard.

PR Report Card

Overall Grade  

Focus Area: Hygiene
Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
C# Mar 8, 2026 1:01p.m. Review ↗
Secrets Mar 8, 2026 1:01p.m. Review ↗

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Mar 8, 2026

审阅者指南

将基于 Arch 的 ECS 支持从 GFramework.Core 中抽离出来,放入一个独立的 GFramework.Ecs.Arch 模块中,该模块拥有自己的抽象、配置选项、基于扩展方法的注册方式以及测试,用显式的模块注册机制替代原有的 ArchitectureProperties.EnableEcs 开关。

架构初始化与 ECS Arch 模块使用的时序图

sequenceDiagram
    actor Dev
    participant GA as GameArchitecture
    participant AE as ArchExtensions
    participant AMR as ArchitectureModuleRegistry
    participant SM as ServiceModuleManager
    participant AEM as ArchEcsModule
    participant IOC as IIocContainer

    Dev->>GA: new GameArchitecture(config)
    Dev->>GA: UseArch(configure)
    GA->>AE: UseArch(GA, configure)
    AE->>AE: create ArchOptions
    AE-->>AE: apply configure
    AE->>AMR: Register(() => new ArchEcsModule(enabled: true))
    AMR-->>AE: factory stored
    AE-->>GA: return architecture

    Dev->>GA: Initialize()
    GA->>SM: RegisterBuiltInModules(IOC, properties)
    SM->>SM: Register built-in core modules
    SM->>AMR: CreateModules()
    AMR-->>SM: list of IServiceModule (includes ArchEcsModule)
    loop for each module
        SM->>SM: RegisterModule(module)
    end

    SM->>AEM: Configure(IOC)
    AEM->>IOC: register World and ECS services
    SM->>AEM: Initialize()

    note over Dev,IOC: Runtime usage
    Dev->>IOC: Resolve<IArchEcsModule>()
    IOC-->>Dev: ArchEcsModule
    Dev->>AEM: Update(deltaTime)
    AEM->>AEM: Update all ArchSystemAdapter<float> systems
Loading

新 ECS Arch 抽象和模块的类图

classDiagram
    direction LR

    class ISystem {
    }

    class IServiceModule {
        <<interface>>
        +int Priority
        +bool IsEnabled
        +string ModuleName
        +void Configure(IIocContainer container)
        +void Initialize()
        +void Shutdown()
    }

    class IArchitecture {
        <<interface>>
        +IIocContainer Container
    }

    class IArchSystemAdapter_T_ {
        <<interface>>
        +void Update(in T t)
    }

    class IArchEcsModule {
        <<interface>>
        +void Update(float deltaTime)
    }

    class ArchOptions {
        +int WorldCapacity
        +bool EnableStatistics
        +int Priority
    }

    class ArchSystemAdapter_T_ {
        <<abstract>>
        +World World
        +void Update(in T t)
        #void OnBeforeUpdate(in T t)
        #void OnUpdate(in T t)
        #void OnAfterUpdate(in T t)
        #void OnArchInitialize()
    }

    class ArchEcsModule {
        +bool IsEnabled
        +int Priority
        +string ModuleName
        +void Configure(IIocContainer container)
        +void Initialize()
        +void Shutdown()
        +void Update(float deltaTime)
    }

    class MovementSystem {
        +QueryDescription _query
        +void OnArchInitialize()
        +void OnUpdate(in float deltaTime)
    }

    class World {
    }

    class QueryDescription {
        +QueryDescription WithAll_Position_Velocity_()
    }

    class Position {
        +float X
        +float Y
    }

    class Velocity {
        +float X
        +float Y
    }

    IArchSystemAdapter_T_ --|> ISystem
    ArchSystemAdapter_T_ --|> AbstractSystem
    ArchSystemAdapter_T_ --|> IArchSystemAdapter_T_
    ArchSystemAdapter_T_ ..> World

    IArchEcsModule --|> IServiceModule
    ArchEcsModule --|> IArchEcsModule

    MovementSystem --|> ArchSystemAdapter_float_
    MovementSystem ..> Position
    MovementSystem ..> Velocity
    MovementSystem ..> World
    MovementSystem ..> QueryDescription

    Position ..> Velocity

    ArchOptions ..> ArchEcsModule
    IArchitecture ..> ArchEcsModule

    class AbstractSystem {
    }

    class IIocContainer {
        <<interface>>
        +void Register_T_()
        +T Resolve_T_()
    }

    ArchEcsModule ..> IIocContainer
Loading

文件级改动

Change Details Files
将 Arch ECS 实现从 Core 中抽取到独立的 GFramework.Ecs.Arch 模块,并调整命名空间/usings。
  • 将 ArchSystemAdapter、ArchEcsModule、MovementSystem、Position 和 Velocity 移动到新的 GFramework.Ecs.Arch 项目及其命名空间中。
  • 更新测试和引用,使其使用 GFramework.Ecs.Arch.components 和 GFramework.Ecs.Arch.systems 命名空间,而不是 GFramework.Core.ecs.*。
  • 在新项目中引入 GlobalUsings 以集中管理常用 using。
GFramework.Core/ecs/ArchSystemAdapter.cs
GFramework.Core/ecs/ArchEcsModule.cs
GFramework.Core/ecs/systems/MovementSystem.cs
GFramework.Core/ecs/components/Position.cs
GFramework.Core/ecs/components/Velocity.cs
GFramework.Ecs.Arch/ArchSystemAdapter.cs
GFramework.Ecs.Arch/ArchEcsModule.cs
GFramework.Ecs.Arch/systems/MovementSystem.cs
GFramework.Ecs.Arch/components/Position.cs
GFramework.Ecs.Arch/components/Velocity.cs
GFramework.Ecs.Arch/GlobalUsings.cs
GFramework.Ecs.Arch.Tests/GlobalUsings.cs
GFramework.Core.Tests/ecs/EcsAdvancedTests.cs
GFramework.Core.Tests/ecs/EcsBasicTests.cs
GFramework.Core.Tests/ecs/EcsIntegrationTests.cs
GFramework.Ecs.Arch.Tests/ecs/EcsAdvancedTests.cs
GFramework.Ecs.Arch.Tests/ecs/EcsBasicTests.cs
GFramework.Ecs.Arch.Tests/ecs/EcsIntegrationTests.cs
使用由 ArchitectureModuleRegistry 和扩展方法驱动的显式、可插拔模块注册机制,替换布尔型 EnableEcs 配置开关。
  • 移除 ArchitectureProperties.EnableEcs 以及相应的基于配置驱动 ECS 注册的测试。
  • 引入 ArchitectureModuleRegistry,作为外部 IServiceModule 工厂的集中注册表,提供 Register、CreateModules 和 Clear API。
  • 更新 ServiceModuleManager.RegisterBuiltInModules,使其始终注册核心模块,然后从 ArchitectureModuleRegistry 加载附加模块,并在服务注册前按优先级对所有模块排序。
  • 调整日志消息,使其反映通用的服务模块注册,而不仅仅是内置模块,并记录每一个外部模块的注册。
GFramework.Core.Abstractions/properties/ArchitectureProperties.cs
GFramework.Core.Tests/architecture/ArchitectureServicesTests.cs
GFramework.Core/services/ServiceModuleManager.cs
GFramework.Core.Abstractions/architecture/ArchitectureModuleRegistry.cs
为 Arch 集成引入面向 ECS 的公共抽象和配置选项。
  • 添加 IArchSystemAdapter 接口,继承 ISystem 并声明 Update(in T),以形式化基于 Arch 的系统契约。
  • 使 ArchSystemAdapter 同时实现 IArchSystemAdapter 和 Arch.System.ISystem,并重构 Update 实现为一个非显式方法,将调用转发到 OnUpdate。
  • 添加 IArchEcsModule 接口,继承 IServiceModule,并提供 Update(float deltaTime) 方法,用于更新所有 ECS 系统。
  • 添加 ArchOptions 配置类,用于保存 ECS 配置选项,例如 WorldCapacity、EnableStatistics 和 Priority。
GFramework.Ecs.Arch.Abstractions/IArchSystemAdapter.cs
GFramework.Ecs.Arch.Abstractions/IArchEcsModule.cs
GFramework.Ecs.Arch.Abstractions/ArchOptions.cs
GFramework.Ecs.Arch.Abstractions/GlobalUsings.cs
GFramework.Ecs.Arch/ArchSystemAdapter.cs
GFramework.Ecs.Arch/ArchEcsModule.cs
提供基于扩展方法的流式 API,用于向架构实例添加 Arch ECS 支持,并文档化新的集成模式。
  • 添加 ArchExtensions.UseArch 扩展方法,可选地接受 ArchOptions 配置委托,并向 ArchitectureModuleRegistry 注册一个 ArchEcsModule。
  • 确保 UseArch 返回架构实例,以支持流式调用链。
  • 在 GFramework.Ecs.Arch 的专用 README 中文档化新包、配置选项、生命周期和使用模式,包括系统、实体及更新的示例。
GFramework.Ecs.Arch/extensions/ArchExtensions.cs
GFramework.Ecs.Arch/README.md
为 Arch ECS 抽象、实现和测试引入新项目,并将其接入解决方案/构建配置。
  • 添加 GFramework.Ecs.Arch、GFramework.Ecs.Arch.Abstractions 和 GFramework.Ecs.Arch.Tests 项目文件,并将它们包含到主解决方案及相关 meta-project 中。
  • 调整现有 csproj 引用(例如测试、源码生成器、根项目),使 ECS 相关测试现在针对新的 ECS 项目而非 Core。
  • 为新的抽象项目添加 Directory.Build.props,以在需要时共享构建设置。
GFramework.Ecs.Arch/GFramework.Ecs.Arch.csproj
GFramework.Ecs.Arch.Abstractions/GFramework.Ecs.Arch.Abstractions.csproj
GFramework.Ecs.Arch.Abstractions/Directory.Build.props
GFramework.Ecs.Arch.Tests/GFramework.Ecs.Arch.Tests.csproj
GFramework.Core.Tests/GFramework.Core.Tests.csproj
GFramework.Core/GFramework.Core.csproj
GFramework.SourceGenerators.Tests/GFramework.SourceGenerators.Tests.csproj
GFramework.csproj
GFramework.sln

技巧和命令

与 Sourcery 交互

  • 触发一次新的审查: 在 pull request 上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub issue: 在审查评论中回复,要求 Sourcery 从该评论创建一个 issue。你也可以直接回复审查评论 @sourcery-ai issue 从该评论创建 issue。
  • 生成 pull request 标题: 在 pull request 标题的任意位置写入 @sourcery-ai 即可随时生成标题。也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 总结: 在 pull request 正文任意位置写入 @sourcery-ai summary,即可在该位置生成 PR 总结。也可以在 pull request 中评论 @sourcery-ai summary 来(重新)生成总结。
  • 生成审阅者指南: 在 pull request 中评论 @sourcery-ai guide,即可随时(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve 以解决所有 Sourcery 评论。如果你已经处理完所有评论且不希望再看到它们,这会非常有用。
  • 忽略所有 Sourcery 审查: 在 pull request 中评论 @sourcery-ai dismiss 以忽略所有现有的 Sourcery 审查。若你想从一次全新的审查开始,这尤其有用——别忘了再评论 @sourcery-ai review 触发新的审查!

自定义你的体验

访问你的控制面板 以:

  • 启用或停用审查功能,例如 Sourcery 生成的 pull request 总结、审阅者指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查指令。
  • 调整其他审查设置。

获取帮助

Original review guide in English

Reviewer's Guide

Refactors Arch-based ECS support out of GFramework.Core into a dedicated GFramework.Ecs.Arch module with its own abstractions, options, extension-based registration, and tests, replacing the old ArchitectureProperties.EnableEcs toggle with an explicit module registration mechanism.

Sequence diagram for architecture initialization and ECS Arch module usage

sequenceDiagram
    actor Dev
    participant GA as GameArchitecture
    participant AE as ArchExtensions
    participant AMR as ArchitectureModuleRegistry
    participant SM as ServiceModuleManager
    participant AEM as ArchEcsModule
    participant IOC as IIocContainer

    Dev->>GA: new GameArchitecture(config)
    Dev->>GA: UseArch(configure)
    GA->>AE: UseArch(GA, configure)
    AE->>AE: create ArchOptions
    AE-->>AE: apply configure
    AE->>AMR: Register(() => new ArchEcsModule(enabled: true))
    AMR-->>AE: factory stored
    AE-->>GA: return architecture

    Dev->>GA: Initialize()
    GA->>SM: RegisterBuiltInModules(IOC, properties)
    SM->>SM: Register built-in core modules
    SM->>AMR: CreateModules()
    AMR-->>SM: list of IServiceModule (includes ArchEcsModule)
    loop for each module
        SM->>SM: RegisterModule(module)
    end

    SM->>AEM: Configure(IOC)
    AEM->>IOC: register World and ECS services
    SM->>AEM: Initialize()

    note over Dev,IOC: Runtime usage
    Dev->>IOC: Resolve<IArchEcsModule>()
    IOC-->>Dev: ArchEcsModule
    Dev->>AEM: Update(deltaTime)
    AEM->>AEM: Update all ArchSystemAdapter<float> systems
Loading

Class diagram for new ECS Arch abstractions and module

classDiagram
    direction LR

    class ISystem {
    }

    class IServiceModule {
        <<interface>>
        +int Priority
        +bool IsEnabled
        +string ModuleName
        +void Configure(IIocContainer container)
        +void Initialize()
        +void Shutdown()
    }

    class IArchitecture {
        <<interface>>
        +IIocContainer Container
    }

    class IArchSystemAdapter_T_ {
        <<interface>>
        +void Update(in T t)
    }

    class IArchEcsModule {
        <<interface>>
        +void Update(float deltaTime)
    }

    class ArchOptions {
        +int WorldCapacity
        +bool EnableStatistics
        +int Priority
    }

    class ArchSystemAdapter_T_ {
        <<abstract>>
        +World World
        +void Update(in T t)
        #void OnBeforeUpdate(in T t)
        #void OnUpdate(in T t)
        #void OnAfterUpdate(in T t)
        #void OnArchInitialize()
    }

    class ArchEcsModule {
        +bool IsEnabled
        +int Priority
        +string ModuleName
        +void Configure(IIocContainer container)
        +void Initialize()
        +void Shutdown()
        +void Update(float deltaTime)
    }

    class MovementSystem {
        +QueryDescription _query
        +void OnArchInitialize()
        +void OnUpdate(in float deltaTime)
    }

    class World {
    }

    class QueryDescription {
        +QueryDescription WithAll_Position_Velocity_()
    }

    class Position {
        +float X
        +float Y
    }

    class Velocity {
        +float X
        +float Y
    }

    IArchSystemAdapter_T_ --|> ISystem
    ArchSystemAdapter_T_ --|> AbstractSystem
    ArchSystemAdapter_T_ --|> IArchSystemAdapter_T_
    ArchSystemAdapter_T_ ..> World

    IArchEcsModule --|> IServiceModule
    ArchEcsModule --|> IArchEcsModule

    MovementSystem --|> ArchSystemAdapter_float_
    MovementSystem ..> Position
    MovementSystem ..> Velocity
    MovementSystem ..> World
    MovementSystem ..> QueryDescription

    Position ..> Velocity

    ArchOptions ..> ArchEcsModule
    IArchitecture ..> ArchEcsModule

    class AbstractSystem {
    }

    class IIocContainer {
        <<interface>>
        +void Register_T_()
        +T Resolve_T_()
    }

    ArchEcsModule ..> IIocContainer
Loading

File-Level Changes

Change Details Files
Extract Arch ECS implementation from Core into a dedicated GFramework.Ecs.Arch module and adjust namespaces/usings.
  • Move ArchSystemAdapter, ArchEcsModule, MovementSystem, Position, and Velocity into the new GFramework.Ecs.Arch project and namespaces.
  • Update tests and references to use GFramework.Ecs.Arch.components and GFramework.Ecs.Arch.systems namespaces instead of GFramework.Core.ecs.*.
  • Introduce GlobalUsings in the new projects to centralize common usings.
GFramework.Core/ecs/ArchSystemAdapter.cs
GFramework.Core/ecs/ArchEcsModule.cs
GFramework.Core/ecs/systems/MovementSystem.cs
GFramework.Core/ecs/components/Position.cs
GFramework.Core/ecs/components/Velocity.cs
GFramework.Ecs.Arch/ArchSystemAdapter.cs
GFramework.Ecs.Arch/ArchEcsModule.cs
GFramework.Ecs.Arch/systems/MovementSystem.cs
GFramework.Ecs.Arch/components/Position.cs
GFramework.Ecs.Arch/components/Velocity.cs
GFramework.Ecs.Arch/GlobalUsings.cs
GFramework.Ecs.Arch.Tests/GlobalUsings.cs
GFramework.Core.Tests/ecs/EcsAdvancedTests.cs
GFramework.Core.Tests/ecs/EcsBasicTests.cs
GFramework.Core.Tests/ecs/EcsIntegrationTests.cs
GFramework.Ecs.Arch.Tests/ecs/EcsAdvancedTests.cs
GFramework.Ecs.Arch.Tests/ecs/EcsBasicTests.cs
GFramework.Ecs.Arch.Tests/ecs/EcsIntegrationTests.cs
Replace the boolean EnableEcs configuration flag with an explicit, pluggable module registration mechanism driven by ArchitectureModuleRegistry and extension methods.
  • Remove ArchitectureProperties.EnableEcs and the corresponding configuration-driven ECS registration test.
  • Introduce ArchitectureModuleRegistry as a central registry of external IServiceModule factories, with Register, CreateModules, and Clear APIs.
  • Update ServiceModuleManager.RegisterBuiltInModules to always register core modules and then load additional modules from ArchitectureModuleRegistry, sorting all modules by priority before service registration.
  • Adjust logging messages to reflect generic service module registration instead of built-in-only and log each external module registration.
GFramework.Core.Abstractions/properties/ArchitectureProperties.cs
GFramework.Core.Tests/architecture/ArchitectureServicesTests.cs
GFramework.Core/services/ServiceModuleManager.cs
GFramework.Core.Abstractions/architecture/ArchitectureModuleRegistry.cs
Introduce public ECS-specific abstractions and configuration options for the Arch integration.
  • Add IArchSystemAdapter interface extending ISystem and declaring Update(in T) to formalize the contract for Arch-based systems.
  • Have ArchSystemAdapter implement IArchSystemAdapter in addition to Arch.System.ISystem, and reorganize the Update implementation to be a non-explicit method that forwards to OnUpdate.
  • Add IArchEcsModule interface extending IServiceModule with an Update(float deltaTime) method for updating all ECS systems.
  • Add ArchOptions configuration class to hold ECS options such as WorldCapacity, EnableStatistics, and Priority.
GFramework.Ecs.Arch.Abstractions/IArchSystemAdapter.cs
GFramework.Ecs.Arch.Abstractions/IArchEcsModule.cs
GFramework.Ecs.Arch.Abstractions/ArchOptions.cs
GFramework.Ecs.Arch.Abstractions/GlobalUsings.cs
GFramework.Ecs.Arch/ArchSystemAdapter.cs
GFramework.Ecs.Arch/ArchEcsModule.cs
Provide a fluent extension-based API to add Arch ECS support to an architecture instance and document the new integration pattern.
  • Add ArchExtensions.UseArch extension method that optionally accepts an ArchOptions configuration delegate and registers an ArchEcsModule into ArchitectureModuleRegistry.
  • Ensure UseArch returns the architecture instance to enable fluent chaining.
  • Document the new package, configuration options, lifecycle, and usage patterns in a dedicated README for GFramework.Ecs.Arch, including examples for systems, entities, and updates.
GFramework.Ecs.Arch/extensions/ArchExtensions.cs
GFramework.Ecs.Arch/README.md
Introduce new projects for Arch ECS abstractions, implementation, and tests, and wire them into the solution/build configuration.
  • Add GFramework.Ecs.Arch, GFramework.Ecs.Arch.Abstractions, and GFramework.Ecs.Arch.Tests project files and include them in the main solution and any affected meta-projects.
  • Adjust existing csproj references (e.g., tests, source generators, root project) so that ECS-related tests now target the new ECS projects instead of Core.
  • Add Directory.Build.props for the new abstractions project to share build settings, if applicable.
GFramework.Ecs.Arch/GFramework.Ecs.Arch.csproj
GFramework.Ecs.Arch.Abstractions/GFramework.Ecs.Arch.Abstractions.csproj
GFramework.Ecs.Arch.Abstractions/Directory.Build.props
GFramework.Ecs.Arch.Tests/GFramework.Ecs.Arch.Tests.csproj
GFramework.Core.Tests/GFramework.Core.Tests.csproj
GFramework.Core/GFramework.Core.csproj
GFramework.SourceGenerators.Tests/GFramework.SourceGenerators.Tests.csproj
GFramework.csproj
GFramework.sln

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我发现了两个问题,并给出了一些总体反馈:

  • 新的 ArchitectureModuleRegistry 使用了一个静态可变的 List,没有任何同步或重复处理;如果模块可能在不同上下文中被注册,建议让每种模块类型的注册是幂等的,并/或增加基础的线程安全措施。
  • ArchExtensions.UseArch 创建了一个 ArchOptions 实例,但从未将这些选项传递给 ArchEcsModule 或其他任何地方,因此配置实际上被忽略了;建议要么在构造模块(以及模块行为)时接入 ArchOptions,要么移除这些未使用的选项以避免混淆。
  • ServiceModuleManager.RegisterBuiltInModules 仍然接受 ArchitectureProperties,但在移除 EnableEcs 之后已经不再使用它;建议移除该参数或重新赋予它用途,以避免误导性的 API 设计。
给 AI Agent 的提示
请根据下面的代码审查意见进行修改:

## 总体意见
- 新的 ArchitectureModuleRegistry 使用了一个静态可变的 List,没有任何同步或重复处理;如果模块可能在不同上下文中被注册,建议让每种模块类型的注册是幂等的,并/或增加基础的线程安全措施。
- ArchExtensions.UseArch 创建了一个 ArchOptions 实例,但从未将这些选项传递给 ArchEcsModule 或其他任何地方,因此配置实际上被忽略了;建议要么在构造模块(以及模块行为)时接入 ArchOptions,要么移除这些未使用的选项以避免混淆。
- ServiceModuleManager.RegisterBuiltInModules 仍然接受 ArchitectureProperties,但在移除 EnableEcs 之后已经不再使用它;建议移除该参数或重新赋予它用途,以避免误导性的 API 设计。

## 单独评论

### 评论 1
<location path="GFramework.Core/services/ServiceModuleManager.cs" line_range="50-51" />
<code_context>
     /// </summary>
     /// <param name="container">IoC容器实例,用于模块服务注册。</param>
-    /// <param name="properties">架构属性配置,用于判断是否启用ECS模块。</param>
+    /// <param name="properties">架构属性配置。</param>
     public void RegisterBuiltInModules(IIocContainer container, ArchitectureProperties properties)
     {
         if (_builtInModulesRegistered)
</code_context>
<issue_to_address>
**suggestion:** ArchitectureProperties 现在在 RegisterBuiltInModules 中未被使用,可以移除或重新利用。

由于此处已不再使用 `ArchitectureProperties`,建议移除该参数,以保持 API 精简并避免混淆。如果你预计很快会用它做额外配置,可以加一个简短的 TODO 或占位分支来向调用方说明它的用途。

建议实现:

```csharp
    /// <summary>
    ///     注册内置服务模块,并根据优先级排序后完成服务注册。
    ///     内置模块包括事件总线、命令执行器、查询执行器等核心模块。
    ///     同时注册通过 ModuleInitializer 自动注册的外部模块。
    /// </summary>
    /// <param name="container">IoC容器实例,用于模块服务注册。</param>
    public void RegisterBuiltInModules(IIocContainer container)
    {
        if (_builtInModulesRegistered)
            return;

        // 注册内置模块
        RegisterModule(new EventBusModule());
        RegisterModule(new CommandExecutorModule());
        RegisterModule(new QueryExecutorModule());
        RegisterModule(new AsyncQueryExecutorModule());

```

1. 更新所有对 `RegisterBuiltInModules` 的调用点,移除 `ArchitectureProperties` 参数,仅传入 `IIocContainer` 实例。
2. 如果 `ArchitectureProperties` 之前只在这个方法中使用,考虑移除本文件中与之相关、现在已未使用的 `using` 指令或引用。
</issue_to_address>

### 评论 2
<location path="GFramework.Ecs.Arch/extensions/ArchExtensions.cs" line_range="17-26" />
<code_context>
+    /// <param name="architecture">架构实例</param>
+    /// <param name="configure">可选的配置委托</param>
+    /// <returns>架构实例,支持链式调用</returns>
+    public static TArchitecture UseArch<TArchitecture>(
+        this TArchitecture architecture,
+        Action<ArchOptions>? configure = null)
+        where TArchitecture : IArchitecture
+    {
+        // 配置选项
+        var options = new ArchOptions();
+        configure?.Invoke(options);
+
+        // 注册模块
+        ArchitectureModuleRegistry.Register(() => new ArchEcsModule(enabled: true));
+
+        return architecture;
</code_context>
<issue_to_address>
**issue:** ArchOptions 被配置了,但其值未被使用,这可能会误导使用者。

`UseArch` 构建了一个 `ArchOptions` 实例(WorldCapacityEnableStatisticsPriority),但从未将其传递给 `ArchEcsModule` 或其他消费者,因此当前配置委托实际上不起任何作用。建议要么将这些选项接入 `ArchEcsModule`(例如通过构造函数或配置接口),要么暂时移除这些配置选项,以避免暴露一个“没有效果”的配置 API</issue_to_address>

Sourcery 对开源项目是免费的 —— 如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据这些反馈改进以后的评审。
Original comment in English

Hey - I've found 2 issues, and left some high level feedback:

  • The new ArchitectureModuleRegistry uses a static mutable List without any synchronization or duplicate-handling; consider making registration idempotent per module type and/or adding basic thread-safety if modules can be registered from different contexts.
  • ArchExtensions.UseArch creates an ArchOptions instance but never passes those options to ArchEcsModule or anywhere else, so the configuration is effectively ignored; either wire ArchOptions into module construction (and module behavior) or remove the unused options to avoid confusion.
  • ServiceModuleManager.RegisterBuiltInModules still takes ArchitectureProperties but no longer uses it after removing EnableEcs; consider removing this parameter or repurposing it to avoid a misleading API surface.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new ArchitectureModuleRegistry uses a static mutable List without any synchronization or duplicate-handling; consider making registration idempotent per module type and/or adding basic thread-safety if modules can be registered from different contexts.
- ArchExtensions.UseArch creates an ArchOptions instance but never passes those options to ArchEcsModule or anywhere else, so the configuration is effectively ignored; either wire ArchOptions into module construction (and module behavior) or remove the unused options to avoid confusion.
- ServiceModuleManager.RegisterBuiltInModules still takes ArchitectureProperties but no longer uses it after removing EnableEcs; consider removing this parameter or repurposing it to avoid a misleading API surface.

## Individual Comments

### Comment 1
<location path="GFramework.Core/services/ServiceModuleManager.cs" line_range="50-51" />
<code_context>
     /// </summary>
     /// <param name="container">IoC容器实例,用于模块服务注册。</param>
-    /// <param name="properties">架构属性配置,用于判断是否启用ECS模块。</param>
+    /// <param name="properties">架构属性配置。</param>
     public void RegisterBuiltInModules(IIocContainer container, ArchitectureProperties properties)
     {
         if (_builtInModulesRegistered)
</code_context>
<issue_to_address>
**suggestion:** ArchitectureProperties is now unused in RegisterBuiltInModules and could be removed or repurposed.

Since `ArchitectureProperties` is no longer used here, consider removing the parameter to keep the API minimal and avoid confusion. If you expect to use it soon for additional configuration, adding a brief TODO or placeholder branch would help clarify its purpose to callers.

Suggested implementation:

```csharp
    /// <summary>
    ///     注册内置服务模块,并根据优先级排序后完成服务注册。
    ///     内置模块包括事件总线、命令执行器、查询执行器等核心模块。
    ///     同时注册通过 ModuleInitializer 自动注册的外部模块。
    /// </summary>
    /// <param name="container">IoC容器实例,用于模块服务注册。</param>
    public void RegisterBuiltInModules(IIocContainer container)
    {
        if (_builtInModulesRegistered)
            return;

        // 注册内置模块
        RegisterModule(new EventBusModule());
        RegisterModule(new CommandExecutorModule());
        RegisterModule(new QueryExecutorModule());
        RegisterModule(new AsyncQueryExecutorModule());

```

1. Update all call sites of `RegisterBuiltInModules` to remove the `ArchitectureProperties` argument and pass only the `IIocContainer` instance.
2. If `ArchitectureProperties` was only used for this method, consider removing related `using` directives or references that are now unused in this file.
</issue_to_address>

### Comment 2
<location path="GFramework.Ecs.Arch/extensions/ArchExtensions.cs" line_range="17-26" />
<code_context>
+    /// <param name="architecture">架构实例</param>
+    /// <param name="configure">可选的配置委托</param>
+    /// <returns>架构实例,支持链式调用</returns>
+    public static TArchitecture UseArch<TArchitecture>(
+        this TArchitecture architecture,
+        Action<ArchOptions>? configure = null)
+        where TArchitecture : IArchitecture
+    {
+        // 配置选项
+        var options = new ArchOptions();
+        configure?.Invoke(options);
+
+        // 注册模块
+        ArchitectureModuleRegistry.Register(() => new ArchEcsModule(enabled: true));
+
+        return architecture;
</code_context>
<issue_to_address>
**issue:** ArchOptions is configured but its values are not used, which can be misleading for consumers.

`UseArch` builds an `ArchOptions` instance (WorldCapacity, EnableStatistics, Priority) but never passes it to `ArchEcsModule` or any other consumer, so the configuration delegate currently does nothing. Either wire these options into `ArchEcsModule` (e.g., via constructor/config interface) or remove the options for now to avoid exposing a configuration API that has no effect.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread GFramework.Core/services/ServiceModuleManager.cs Outdated
Comment thread GFramework.Ecs.Arch/extensions/ArchExtensions.cs Outdated
GeWuYou added 5 commits March 8, 2026 20:33
- 在 ArchEcsModule 初始化时注册模块自身到容器
- 移除不必要的空行以保持代码整洁
- 将 _systems 字段类型从 List 改为 IReadOnlyList
- 使用 GetAllByPriority 方法按优先级获取适配器
- 移除手动 AddRange 操作,直接赋值适配器列表
- 销毁时将 _systems 设置为空数组而非 Clear() 操作
- 移除 RegisterBuiltInModules 方法中的 ArchitectureProperties 参数
- 更新 ArchitectureModuleRegistry 使用 ConcurrentDictionary 存储模块工厂
- 实现模块注册的幂等性检查,相同模块名只注册一次
- 为 ArchEcsModule 添加 ArchOptions 配置类支持
- 更新 UseArch 扩展方法传递配置选项给 ArchEcsModule
- 移除废弃的 properties 命名空间引用
- 添加显式注册集成测试验证模块配置功能
- 将 ECS 相关菜单项从 Core 部分独立出来
- 新增 ECS 概述页面和 Arch ECS 集成文档
- 删除旧的 Core/ECS 集成文档文件
- 更新侧边栏配置以支持新的 ECS 导航结构
- 为 CI 工作流添加新的测试步骤
- 配置 GFramework.Ecs.Arch.Tests 的测试运行命令
- 设置测试结果输出目录为 TestResults
- 使用 trx 格式记录测试日志文件
- 保持与现有测试配置一致的结构和格式
@GeWuYou GeWuYou merged commit 05d7557 into main Mar 8, 2026
8 checks passed
@GeWuYou GeWuYou deleted the refactor/extract-ecs-to-independent-module branch March 8, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant