diff --git a/GFramework.Core/ioc/IocContainer.cs b/GFramework.Core/ioc/IocContainer.cs
index 824abcc..d15661e 100644
--- a/GFramework.Core/ioc/IocContainer.cs
+++ b/GFramework.Core/ioc/IocContainer.cs
@@ -1,3 +1,5 @@
+using GFramework.Core.system;
+
namespace GFramework.Core.ioc;
///
@@ -5,32 +7,187 @@ namespace GFramework.Core.ioc;
///
public class IocContainer
{
- private readonly Dictionary _mInstances = new();
+ ///
+ /// 核心存储结构:
+ /// 一个 Type 对应 0~N 个实例
+ ///
+ private readonly Dictionary> _instances = new();
+
+ #region Register
///
- /// 注册一个实例到IOC容器中
+ /// 注册单例(强语义)
+ /// 一个类型只允许一个实例
///
- /// 实例的类型
- /// 要注册的实例对象
- public void Register(T instance)
+ /// 要注册为单例的类型
+ /// 要注册的单例实例
+ /// 当该类型已经注册过单例时抛出异常
+ public void RegisterSingleton(T instance)
{
- var key = typeof(T);
+ var type = typeof(T);
- _mInstances[key] = instance;
+ if (_instances.TryGetValue(type, out var list) && list.Count > 0)
+ {
+ throw new InvalidOperationException(
+ $"Singleton already registered for type: {type.Name}");
+ }
+
+ _instances[type] = new List