using GFramework.Core.system;
namespace GFramework.Core.ioc;
///
/// IOC容器类,用于管理对象的注册和获取
///
public class IocContainer
{
///
/// 核心存储结构:
/// 一个 Type 对应 0~N 个实例
///
private readonly Dictionary> _instances = new();
#region Register
///
/// 注册单例(强语义)
/// 一个类型只允许一个实例
///
/// 要注册为单例的类型
/// 要注册的单例实例
/// 当该类型已经注册过单例时抛出异常
public void RegisterSingleton(T instance)
{
var type = typeof(T);
if (_instances.TryGetValue(type, out var list) && list.Count > 0)
{
throw new InvalidOperationException(
$"Singleton already registered for type: {type.Name}");
}
_instances[type] = new List