手写一个ioc容器
public class KuContainer : IKuContainer
{
private Dictionary<string, Type> _kuContainerDictionary = new Dictionary<string, Type>();
public void RegisterType<TFrom, TTo>() where TTo : TFrom
{
this._kuContainerDictionary.Add(typeof(TFrom).FullName, typeof(TTo));
}
public TFrom Resolve<TFrom>()
{
var type = this._kuContainerDictionary[typeof(T).FullName];
var instance = (TFrom)Activator.CreateInstance(type);
return instance;
}
}
22