using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Stary.Evo
{
public class IOCContainer
{
///
/// 实例
///
public Dictionary mInstances = new Dictionary();
///
/// 注册
///
///
///
public void Register(T instance)
{
var key = typeof(T);
if (mInstances.ContainsKey(key))
{
mInstances[key] = instance;
}
else
{
mInstances.Add(key, instance);
}
}
///
/// 注销
///
public void UnRegister() where T : class
{
var key = typeof(T);
if (mInstances.TryGetValue(key, out var retObj))
{
retObj = null;
mInstances.Remove(key);
}
else
{
Debug.LogErrorFormat("IOC容器里不存在Key:--【{0}】--请用对应创建的key进行调用",key);
}
}
public T Get() where T : class
{
var key = typeof(T);
if (mInstances.TryGetValue(key, out var retObj))
{
return retObj as T;
}
else
{
Debug.LogErrorFormat("IOC容器里不存在Key:--【{0}】--请用对应创建的key进行调用",key);
}
return null;
}
}
}