Esempio n. 1
0
 /// <summary>
 /// 接口注册
 /// </summary>
 /// <param name="types">类型数组</param>
 public void Register(params Type[] types)
 {
     foreach (var type in types)
     {
         var interfaces = type.GetInterfaces();
         foreach (var inter in interfaces)
         {
             if (DicToRegister.ContainsValue(inter.FullName))
             {
                 continue;
             }
             DicToRegister.Add(type, inter.FullName);
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 获取实体
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public T Resolve <T>(Type type)
 {
     if (type.IsInterface)
     {
         if (DicToRegister.ContainsValue(type.FullName))
         {
             return(Resolve <T>(DicToRegister.FirstOrDefault(q => q.Value == type.FullName).Key));
         }
         else
         {
             return(default(T));
         }
     }
     else
     {
         return(CreateInstance <T>(type));
     }
 }