Пример #1
0
        /// <summary>
        /// 创建一个启动模块类型为<paramref name="startupModuleType"/>的应用,
        /// ,相关的IServiceCollection为<paramref name="services"/>,同时执行<paramref name="optionsAction"/>
        /// </summary>
        /// <param name="startupModuleType">启动模块</param>
        /// <param name="services">该应用所需的服务</param>
        /// <param name="optionsAction"></param>
        internal XqApplicationBase(
            [NotNull] Type startupModuleType,
            [NotNull] IServiceCollection services,
            [CanBeNull] Action <XqApplicationCreationOptions> optionsAction)
        {
            XqCheck.NotNull(startupModuleType, nameof(startupModuleType));
            XqCheck.NotNull(services, nameof(services));

            StartupModuleType = startupModuleType;
            Services          = services;

            services.TryAddObjectAccessor <IServiceProvider>();

            var options = new XqApplicationCreationOptions(services);

            optionsAction?.Invoke(options);

            ///增加<see cref="IXqApplication"/>应用服务
            services.AddSingleton <IXqApplication>(this);

            ///增加<see cref="IModuleContainer"/>服务
            services.AddSingleton <IModuleContainer>(this);

            ///添加应用的核心服务
            services.AddCoreServices();

            services.AddCoreXqServices(this, options);

            Modules = LoadModules(services, options);
        }
Пример #2
0
 /// <summary>
 /// 从<paramref name="services"/>中,通过<paramref name="options"/>配置,加载所有Module
 /// </summary>
 /// <param name="services"></param>
 /// <param name="options"></param>
 /// <returns>返回所有的Modules</returns>
 private IReadOnlyList <IXqModuleDescriptor> LoadModules(IServiceCollection services, XqApplicationCreationOptions options)
 {
     return(services
            .GetSingletonInstance <IModuleLoader>()
            .LoadModules(
                services,
                StartupModuleType,
                options.PlugInSources
                ));
 }