用 forDictionary<Type,object>
代替不是无效Dictionary<Type,T>
吗?
每次我添加一个 ICustomerService 它都会被装箱。
如果我有 Type,T 应该没有拳击,你怎么看?
public class MyService
{
private static Dictionary<Type, object> _services = new Dictionary<Type, object>();
public static void AddService<T>(object service)
{
if (! (_services.ContainsKey(typeof(T))))
_services.Add(typeof(T), service);
}
public static T1 GetService<T1>()
{
return (T1) _services[typeof(T1)];
}
}