Пример #1
0
    internal ApplicationBase(
        [NotNull] Type startupModuleType,
        [NotNull] IServiceCollection services,
        [CanBeNull] Action <ApplicationCreationOptions> optionsAction)
    {
        Check.NotNull(startupModuleType, nameof(startupModuleType));
        Check.NotNull(services, nameof(services));

        // 设置启动模块。
        StartupModuleType = startupModuleType;
        Services          = services;

        // 添加一个空的对象访问器,该访问器的值会在初始化的时候被赋值。
        services.TryAddObjectAccessor <IServiceProvider>();

        // 调用用户传入的配置委托。
        var options = new ApplicationCreationOptions(services);

        optionsAction?.Invoke(options);

        // 注册自己。
        services.AddSingleton <IApplication>(this);
        services.AddSingleton <IModuleContainer>(this);

        // 添加日志等基础设施组件。
        // 添加核心服务,主要是模块系统相关组件。
        services.AddCoreServices();
        services.AddLinFxCoreServices(this, options);

        Modules = LoadModules(services, options);
        ConfigureServices();
    }
        /// <summary>
        /// Adds the core abp services.
        /// </summary>
        /// <param name="services">The services.</param>
        /// <param name="aplication">The  application.</param>
        /// <param name="applicationCreationOptions">The application creation options.</param>
        internal static void AddAppCoreServices(this IServiceCollection services,
                                                IApplication aplication,
                                                ApplicationCreationOptions applicationCreationOptions)
        {
            var moduleLoader = new ModuleLoader();

            //StartupModules=>Modules=>Assemblies
            var assemblyFinder = new AssemblyFinder(aplication);

            //封装了所有程序集中所有的Types
            var typeFinder = new TypeFinder(assemblyFinder);

            if (!services.IsAdded <IConfiguration>())
            {
                //生成Configuration对象并注册(默认规则appsetting.json环境变量,命令行参数等)
                services.ReplaceConfiguration(
                    ConfigurationHelper.BuildConfiguration(
                        applicationCreationOptions.Configuration
                        )
                    );
            }

            services.TryAddSingleton <IModuleLoader>(moduleLoader);
            services.TryAddSingleton <IAssemblyFinder>(assemblyFinder);
            services.TryAddSingleton <ITypeFinder>(typeFinder);

            //添加Noob.Core程序集(基于约定方式的,注册程序集中services)IMPORTANT
            services.AddAssemblyOf <IApplication>();

            //配置模块声明周期的HOOKS
            services.Configure <ModuleLifecycleOptions>(options =>
            {
                options.Contributors.Add <OnPreApplicationInitializationModuleLifecycleContributor>();
                options.Contributors.Add <OnApplicationInitializationModuleLifecycleContributor>();
                options.Contributors.Add <OnPostApplicationInitializationModuleLifecycleContributor>();
                options.Contributors.Add <OnApplicationShutdownModuleLifecycleContributor>();
            });
        }
Пример #3
0
 public static void UseAutofac(this ApplicationCreationOptions options)
 {
     options.Services.AddAutofacServiceProviderFactory();
 }
Пример #4
0
 /// <summary>
 /// Sets the application creation options.
 /// </summary>
 /// <param name="options">The options.</param>
 protected override void SetApplicationCreationOptions(ApplicationCreationOptions options)
 {
     options.UseAutofac();
 }
        internal static void AddCoreFraServices(this IServiceCollection services, IApplication fraApplication, ApplicationCreationOptions fraApplicationCreationOptions)
        {
            var moduleLoader = new ModuleLoader();

            services.TryAddSingleton(moduleLoader);
            services.AddAssemblyOf <IApplication>();
        }
Пример #6
0
 /// <summary>
 /// 加载模块
 /// </summary>
 protected virtual IReadOnlyList <IModuleDescriptor> LoadModules(IServiceCollection services, ApplicationCreationOptions options)
 {
     return(services
            .GetSingletonInstance <IModuleLoader>()
            .LoadModules(services, StartupModuleType, options.PlugInSources));
 }
    internal static void AddLinFxCoreServices(this IServiceCollection services, IApplication application, ApplicationCreationOptions applicationCreationOptions)
    {
        var moduleLoader   = new ModuleLoader();
        var assemblyFinder = new AssemblyFinder(application);
        var typeFinder     = new TypeFinder(assemblyFinder);

        if (!services.IsAdded <IConfiguration>())
        {
            //services.ReplaceConfiguration(ConfigurationHelper.BuildConfiguration(applicationCreationOptions.Configuration));
        }

        services.TryAddSingleton <IModuleLoader>(moduleLoader);
        services.TryAddSingleton <IAssemblyFinder>(assemblyFinder);
        services.TryAddSingleton <ITypeFinder>(typeFinder);

        services.AddAssemblyOf <IApplication>();

        //services.AddTransient(typeof(ISimpleStateCheckerManager<>), typeof(SimpleStateCheckerManager<>));

        services.Configure <ModuleLifecycleOptions>(options =>
        {
            options.Contributors.Add <OnPreApplicationInitializationModuleLifecycleContributor>();
            options.Contributors.Add <OnApplicationInitializationModuleLifecycleContributor>();
            options.Contributors.Add <OnPostApplicationInitializationModuleLifecycleContributor>();
            options.Contributors.Add <OnApplicationShutdownModuleLifecycleContributor>();
        });
    }
Пример #8
0
 /// <summary>
 /// Sets the application creation options.
 /// </summary>
 /// <param name="options">The options.</param>
 protected virtual void SetApplicationCreationOptions(ApplicationCreationOptions options)
 {
 }