mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 02:24:30 +08:00
- 将所有小写的命名空间导入更正为首字母大写格式 - 统一 GFramework 框架的命名空间引用规范 - 修复 core、ecs、godot 等模块的命名空间导入错误 - 标准化文档示例代码中的 using 语句格式 - 确保所有文档中的命名空间引用保持一致性 - 更新 global using 语句以匹配正确的命名空间格式
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();
|
|
}
|
|
} |