/// <summary> /// Initializes a new instance of the <see cref="ApplicationBase"/> class. /// </summary> /// <param name="startupModuleType">Type of the startup module.</param> /// <param name="services">The services.</param> /// <param name="optionsAction">The options action.</param> 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; //ObjectAccessor采用头插法,放入其中的查找较快。 AddObjectAccessor一注册注册一对儿:ObjectAccessor;IObjectAccessor services.TryAddObjectAccessor <IServiceProvider>(); var options = new ApplicationCreationOptions(services); optionsAction?.Invoke(options); // 当前的 Application 就是一个模块容器。 services.AddSingleton <IApplication>(this); services.AddSingleton <IModuleContainer>(this); //核心基本服务 Options Logging Localization services.AddCoreServices(); // 注入模块加载类,以及模块的四个应用程序生命周期。 services.AddAppCoreServices(this, options); //遍历所有模块,并按照预加载、初始化、初始化完成的顺序执行其生命周期方法。 Modules = LoadModules(services, options); }
/// <summary> /// Uses the autofac. /// </summary> /// <param name="options">The options.</param> public static void UseAutofac(this ApplicationCreationOptions options) { var builder = new ContainerBuilder(); options.Services.AddObjectAccessor(builder); options.Services.AddSingleton((IServiceProviderFactory <ContainerBuilder>) new AutofacServiceProviderFactory(builder)); }
/// <summary> /// Loads the modules. /// </summary> /// <param name="services">The services.</param> /// <param name="options">The options.</param> /// <returns>IReadOnlyList<IModuleDescriptor>.</returns> private IReadOnlyList <IModuleDescriptor> LoadModules(IServiceCollection services, ApplicationCreationOptions options) { return(services .GetSingletonInstance <IModuleLoader>() .LoadModules( services, StartupModuleType, options.PlugInSources )); }