public ConfigurationSettings(SettingsConfigurationProvider settingsProvider, IConfiguration configuration)
     : base(configuration)
 {
     _settingsProvider = settingsProvider;
 }
Esempio n. 2
0
        /// <inheritdoc/>
        public async Task <int> RunAsync()
        {
            // Remove the synchronization context
            await default(SynchronizationContextRemover);

            // Populate the class catalog (if we haven't already)
            _classCatalog.Populate();

            // Run bootstrapper configurators first
            Configurators.Configure <IConfigurableBootstrapper>(this);
            Configurators.Configure <IBootstrapper>(this);

            // Run the configuration configurator and get the configuration root
            SettingsConfigurationProvider settingsProvider          = new SettingsConfigurationProvider();
            IConfigurationBuilder         configurationBuilder      = new ConfigurationBuilder();
            ConfigurableConfiguration     configurableConfiguration = new ConfigurableConfiguration(configurationBuilder);

            Configurators.Configure(configurableConfiguration);
            configurationBuilder.Add(settingsProvider);
            IConfigurationRoot    configurationRoot     = configurationBuilder.Build();
            ConfigurationSettings configurationSettings = new ConfigurationSettings(settingsProvider, configurationRoot);

            // Create the service collection
            IServiceCollection serviceCollection = CreateServiceCollection() ?? new ServiceCollection();

            serviceCollection.TryAddSingleton <IConfigurableBootstrapper>(this);
            serviceCollection.TryAddSingleton <IBootstrapper>(this);
            serviceCollection.TryAddSingleton(_classCatalog);  // The class catalog is retrieved later for deferred logging once a service provider is built
            serviceCollection.TryAddSingleton <IConfiguration>(configurationRoot);

            // Run configurators on the service collection
            ConfigurableServices configurableServices = new ConfigurableServices(serviceCollection, configurationRoot);

            Configurators.Configure(configurableServices);

            // Add simple logging to make sure it's available in commands before the engine adds in,
            // but add it after the configurators have a chance to configure logging
            serviceCollection.AddLogging();

            // Create the stand-alone command line service container and register a few types needed for the CLI
            CommandServiceTypeRegistrar registrar = new CommandServiceTypeRegistrar();

            registrar.RegisterInstance(typeof(IConfigurationSettings), configurationSettings);
            registrar.RegisterInstance(typeof(IConfigurationRoot), configurationRoot);
            registrar.RegisterInstance(typeof(IServiceCollection), serviceCollection);
            registrar.RegisterInstance(typeof(IConfiguratorCollection), Configurators);
            registrar.RegisterInstance(typeof(IBootstrapper), this);

            // Create the command line parser and run the command
            ICommandApp app = _getCommandApp(registrar);

            app.Configure(commandConfigurator =>
            {
                commandConfigurator.ValidateExamples();
                ConfigurableCommands configurableCommands = new ConfigurableCommands(commandConfigurator);
                Configurators.Configure(configurableCommands);
            });
            int exitCode = await app.RunAsync(Arguments);

            // Dispose all instances of the console logger to flush the message queue and stop the listening thread
            ConsoleLoggerProvider.DisposeAll();

            return(exitCode);
        }