Example #1
0
        /// <summary>
        /// 添加模块
        /// </summary>
        /// <param name="services"></param>
        /// <param name="environmentName">环境名称</param>
        /// <param name="moduleCommonOptions"></param>
        /// <returns></returns>
        public static IModuleCollection AddModules(this IServiceCollection services, string environmentName, out ModuleCommonOptions moduleCommonOptions)
        {
            moduleCommonOptions = null;
            var modules = new ModuleCollection();

            services.AddSingleton <IModuleCollection>(modules);

            //通用配置
            var cfg = new ConfigurationHelper().Load("module", environmentName, true);

            if (cfg == null)
            {
                return(modules);
            }

            var options = cfg.Get <ModuleCommonOptions>() ?? new ModuleCommonOptions();

            if (options.UploadPath.IsNull())
            {
                options.UploadPath = Path.Combine(AppContext.BaseDirectory, "Upload");
            }
            if (options.TempPath.IsNull())
            {
                options.TempPath = Path.Combine(AppContext.BaseDirectory, "Temp");
            }

            services.AddSingleton(options);

            services.Configure <ModuleCommonOptions>(m =>
            {
                m.UploadPath = options.UploadPath;
                m.TempPath   = options.TempPath;
            });

            moduleCommonOptions = options;

            foreach (var module in modules)
            {
                if (module == null)
                {
                    continue;
                }

                services.AddApplicationServices(module);

                //加载模块配置项
                var optionsConfigureType = module.AssemblyDescriptor.Infrastructure.GetTypes().FirstOrDefault(m => typeof(IModuleOptionsConfigure).IsAssignableFrom(m));
                if (optionsConfigureType != null)
                {
                    ((IModuleOptionsConfigure)Activator.CreateInstance(optionsConfigureType)).ConfigOptions(services, cfg.GetSection(module.Id));
                }

                services.AddSingleton(module);
            }

            return(modules);
        }
Example #2
0
        /// <summary>
        /// 添加模块
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static IModuleCollection AddModules(this IServiceCollection services)
        {
            var modules = new ModuleCollection();

            modules.Load();

            services.AddSingleton <IModuleCollection>(modules);

            foreach (var module in modules)
            {
                if (module == null)
                {
                    continue;
                }

                services.AddApplicationServices(module);

                services.AddSingleton(module);
            }

            return(modules);
        }
Example #3
0
        /// <summary>
        /// 添加模块
        /// </summary>
        /// <param name="services"></param>
        /// <param name="environmentName">环境名称</param>
        /// <returns></returns>
        public static IModuleCollection AddModules(this IServiceCollection services, string environmentName)
        {
            var modules = new ModuleCollection();

            services.AddSingleton <IModuleCollection>(modules);

            var cfgHelper = new ConfigurationHelper();
            var cfg       = cfgHelper.Load("module", environmentName, true);

            if (cfg == null)
            {
                return(modules);
            }

            //通用配置
            services.Configure <ModuleCommonOptions>(cfg);

            foreach (var module in modules)
            {
                if (module == null)
                {
                    continue;
                }

                services.AddApplicationServices(module);

                //加载模块配置项
                var optionsConfigureType = module.AssemblyDescriptor.Infrastructure.GetTypes().FirstOrDefault(m => typeof(IModuleOptionsConfigure).IsAssignableFrom(m));
                if (optionsConfigureType != null)
                {
                    ((IModuleOptionsConfigure)Activator.CreateInstance(optionsConfigureType)).ConfigOptions(services, cfg.GetSection(module.Id));
                }

                services.AddSingleton(module);
            }

            return(modules);
        }