Ejemplo n.º 1
0
 /// <summary>
 /// 从程序集中刷新功能数据,主要检索MVC的Controller-Action信息
 /// </summary>
 public void Initialize()
 {
     Type[]      types     = TypeFinder.FindAll();
     TFunction[] functions = GetFunctions(types);
     UpdateToRepository(functions);
     RefreshCache();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the command class.
        /// </summary>
        /// <param name="command">Command enum.<see cref="ECommand"/>.</param>
        /// <returns>return the type.</returns>
        public static Type GetCommandClass(ECommand command)
        {
            ITypeFinder typeFinder = new TypeFinder();

            var types = typeFinder.FindAll().Where(zw => zw.Name == command.ToString() + "Command");

            return(types.FirstOrDefault());
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 从程序集中刷新功能数据,主要检索MVC的Controller-Action信息
 /// </summary>
 public void Initialize()
 {
     Type[]      types     = TypeFinder.FindAll();
     TFunction[] functions = GetFunctions(types);
     if (functions.Length == 0)
     {
         return;
     }
     UpdateToRepository(functions);
     RefreshCache();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Ioc容器初始化
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public IServiceProvider Initialize(IServiceCollection services)
        {
            var builder = new ContainerBuilder();

            var AssemblyFinder = CurrentDomainAssemblyFinder.Instance;
            var typeFinder     = new TypeFinder();

            builder.RegisterInstance(AssemblyFinder).As <IAssemblyFinder>().SingleInstance();
            builder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance();
            builder.RegisterInstance(Instance).As <IIocManager>().SingleInstance();

            var listAllType = typeFinder.FindAll();

            //找到所有外部IDependencyRegistrar实现,调用注册
            var registrarType          = typeof(IDependencyRegistrar);
            var arrRegistrarType       = listAllType.Where(t => registrarType.IsAssignableFrom(t) && t != registrarType).ToArray();
            var listRegistrarInstances = new List <IDependencyRegistrar>();

            foreach (var drType in arrRegistrarType)
            {
                listRegistrarInstances.Add((IDependencyRegistrar)Activator.CreateInstance(drType));
            }
            //排序
            listRegistrarInstances = listRegistrarInstances.OrderBy(t => t.Order).ToList();
            foreach (var dependencyRegistrar in listRegistrarInstances)
            {
                dependencyRegistrar.Register(builder, typeFinder);
            }

            //注册ITransientDependency实现类
            var dependencyType    = typeof(ITransientDependency);
            var arrDependencyType = listAllType.Where(t => dependencyType.IsAssignableFrom(t) && t != dependencyType).ToArray();

            builder.RegisterTypes(arrDependencyType)
            .AsSelf()
            .AsImplementedInterfaces()
            .InstancePerLifetimeScope()
            .PropertiesAutowired();

            foreach (Type type in arrDependencyType)
            {
                if (type.IsClass && !type.IsAbstract && !type.BaseType.IsInterface && type.BaseType != typeof(object))
                {
                    builder.RegisterType(type).As(type.BaseType)
                    .InstancePerLifetimeScope()
                    .PropertiesAutowired();
                }
            }


            //注册ISingletonDependency实现类
            var singletonDependencyType    = typeof(ISingletonDependency);
            var arrSingletonDependencyType = listAllType.Where(t => singletonDependencyType.IsAssignableFrom(t) && t != singletonDependencyType).ToArray();

            builder.RegisterTypes(arrSingletonDependencyType)
            .AsSelf()
            .AsImplementedInterfaces()
            .SingleInstance()
            .PropertiesAutowired();

            foreach (Type type in arrSingletonDependencyType)
            {
                if (type.IsClass && !type.IsAbstract && !type.BaseType.IsInterface && type.BaseType != typeof(object))
                {
                    builder.RegisterType(type).As(type.BaseType)
                    .SingleInstance()
                    .PropertiesAutowired();
                }
            }

            builder.Populate(services);
            _container = builder.Build();
            return(new AutofacServiceProvider(_container));
        }