mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
- 移除 RegisterBuiltInModules 方法中的 ArchitectureProperties 参数 - 更新 ArchitectureModuleRegistry 使用 ConcurrentDictionary 存储模块工厂 - 实现模块注册的幂等性检查,相同模块名只注册一次 - 为 ArchEcsModule 添加 ArchOptions 配置类支持 - 更新 UseArch 扩展方法传递配置选项给 ArchEcsModule - 移除废弃的 properties 命名空间引用 - 添加显式注册集成测试验证模块配置功能
42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using System.Collections.Concurrent;
|
|
|
|
namespace GFramework.Core.Abstractions.architecture;
|
|
|
|
/// <summary>
|
|
/// 架构模块注册表 - 用于外部模块的自动注册
|
|
/// </summary>
|
|
public static class ArchitectureModuleRegistry
|
|
{
|
|
private static readonly ConcurrentDictionary<string, Func<IServiceModule>> _factories = new();
|
|
|
|
/// <summary>
|
|
/// 注册模块工厂(幂等操作,相同模块名只会注册一次)
|
|
/// </summary>
|
|
/// <param name="factory">模块工厂函数</param>
|
|
public static void Register(Func<IServiceModule> factory)
|
|
{
|
|
// 创建临时实例以获取模块名(用于幂等性检查)
|
|
var tempModule = factory();
|
|
var moduleName = tempModule.ModuleName;
|
|
|
|
// 幂等注册:相同模块名只注册一次
|
|
_factories.TryAdd(moduleName, factory);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建所有已注册的模块实例
|
|
/// </summary>
|
|
/// <returns>模块实例集合</returns>
|
|
public static IEnumerable<IServiceModule> CreateModules()
|
|
{
|
|
return _factories.Values.Select(f => f());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 清空注册表(主要用于测试)
|
|
/// </summary>
|
|
public static void Clear()
|
|
{
|
|
_factories.Clear();
|
|
}
|
|
} |