Beispiel #1
0
        private T CreateInstance <T>()
        {
            T ret = default(T);
            IResolvePolicy policy  = ResolvePolicyFactory.GetPolicy();
            bool           isFound = false;

            Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
            foreach (var item in assemblies)
            {
                Type[] types = item.GetTypes();
                foreach (var type in types)
                {
                    if (policy.IsInstanceOf <T>(type))
                    {
                        ret     = (T)Activator.CreateInstance(type);
                        isFound = true;
                        break;
                    }
                }

                if (isFound)
                {
                    break;
                }
            }

            return(ret);
        }
 /// <summary>
 /// 注册依赖注入实例类查找策略
 /// </summary>
 /// <param name="policy">待注册的策略</param>
 public static void RegisterPolicy(IResolvePolicy policy)
 {
     _policy = policy;
 }
 /// <summary>
 /// 注册依赖注入实例类查找策略
 /// </summary>
 /// <param name="policy">待注册的策略</param>
 public static void RegisterPolicy(IResolvePolicy policy)
 {
     _policy = policy;
 }