Exemplo n.º 1
0
        /// <summary>
        /// Configures the services.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="services">The services.</param>
        public void ConfigureServices(HostBuilderContext context, IServiceCollection services)
        {
            var rocketHostBuilder = RocketHostExtensions.GetConventionalHostBuilder(_hostBuilder);

            services.AddSingleton(rocketHostBuilder.AssemblyCandidateFinder);
            services.AddSingleton(rocketHostBuilder.AssemblyProvider);
            services.AddSingleton(rocketHostBuilder.Scanner);
#if !(NETSTANDARD2_0 || NETCOREAPP2_1)
            services.AddHealthChecks();
#endif
        }
Exemplo n.º 2
0
        /// <summary>
        /// Configures the application configuration.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="configurationBuilder">The configuration builder.</param>
        public void ConfigureAppConfiguration(HostBuilderContext context, IConfigurationBuilder configurationBuilder)
        {
            var rocketHostBuilder = RocketHostExtensions.GetConventionalHostBuilder(_hostBuilder);

            InsertConfigurationSourceAfter(
                configurationBuilder.Sources,
                sources => sources.OfType <JsonConfigurationSource>().FirstOrDefault(x => x.Path == "appsettings.json"),
                (source) => new YamlConfigurationSource()
            {
                Path           = "appsettings.yml",
                FileProvider   = source.FileProvider,
                Optional       = true,
                ReloadOnChange = true,
            });

            InsertConfigurationSourceAfter(
                configurationBuilder.Sources,
                sources => sources.OfType <JsonConfigurationSource>().FirstOrDefault(x =>
                                                                                     string.Equals(x.Path, $"appsettings.{context.HostingEnvironment.EnvironmentName}.json",
                                                                                                   StringComparison.OrdinalIgnoreCase)),
                (source) => new YamlConfigurationSource()
            {
                Path           = $"appsettings.{context.HostingEnvironment.EnvironmentName}.yml",
                FileProvider   = source.FileProvider,
                Optional       = true,
                ReloadOnChange = true,
            });

            var cb = new ConfigurationBuilder(
                rocketHostBuilder.Scanner,
                context.HostingEnvironment.Convert(),
                context.Configuration,
                configurationBuilder,
                rocketHostBuilder.Logger,
                rocketHostBuilder.Properties);

            cb.Build();

            MoveConfigurationSourceToEnd(configurationBuilder.Sources,
                                         sources => sources.OfType <JsonConfigurationSource>().Where(x =>
                                                                                                     string.Equals(x.Path, "secrets.json", StringComparison.OrdinalIgnoreCase)));

            MoveConfigurationSourceToEnd(configurationBuilder.Sources,
                                         sources => sources.OfType <EnvironmentVariablesConfigurationSource>());

            MoveConfigurationSourceToEnd(configurationBuilder.Sources,
                                         sources => sources.OfType <CommandLineConfigurationSource>());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Configures the cli.
        /// </summary>
        /// <param name="configurationBuilder">The configuration builder.</param>
        public void ConfigureCli(IConfigurationBuilder configurationBuilder)
        {
            var rocketHostBuilder = RocketHostExtensions.GetConventionalHostBuilder(_hostBuilder);
            var clb = new CommandLineBuilder(
                rocketHostBuilder.Scanner,
                rocketHostBuilder.AssemblyProvider,
                rocketHostBuilder.AssemblyCandidateFinder,
                rocketHostBuilder.Logger,
                rocketHostBuilder.Properties
                );

            _exec = clb.Build().Parse(_args ?? Array.Empty <string>());
            _args = _exec.ApplicationState.RemainingArguments ?? Array.Empty <string>();
            configurationBuilder.AddApplicationState(_exec.ApplicationState);
            rocketHostBuilder.Properties.Add(typeof(ICommandLineExecutor), _exec);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Defaults the services.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="services">The services.</param>
        public void DefaultServices(HostBuilderContext context, IServiceCollection services)
        {
            var conventionalBuilder = RocketHostExtensions.GetConventionalHostBuilder(_hostBuilder);

            _hostBuilder.UseServiceProviderFactory(
                new ServicesBuilderServiceProviderFactory(collection =>
                                                          new ServicesBuilder(
                                                              conventionalBuilder.Scanner,
                                                              conventionalBuilder.AssemblyProvider,
                                                              conventionalBuilder.AssemblyCandidateFinder,
                                                              collection,
                                                              context.Configuration,
                                                              context.HostingEnvironment.Convert(),
                                                              conventionalBuilder.Logger,
                                                              conventionalBuilder.Properties
                                                              )
                                                          )
                );
        }
Exemplo n.º 5
0
        /// <summary>
        /// Fors the application domain.
        /// </summary>
        /// <param name="appDomain">The application domain.</param>
        /// <param name="diagnosticSource">The diagnostic source.</param>
        /// <returns>Func&lt;IHostBuilder, IRocketHostBuilder&gt;.</returns>
        public static Func <IHostBuilder, IRocketHostBuilder> ForAppDomain(
            AppDomain appDomain,
            DiagnosticSource diagnosticSource = null)
        {
            return(builder =>
            {
                var b = RocketHostExtensions.GetOrCreateBuilder(builder);
                if (diagnosticSource != null)
                {
                    b = b.With(diagnosticSource);
                }

                var logger = new DiagnosticLogger(b.DiagnosticSource);
                var assemblyCandidateFinder = new AppDomainAssemblyCandidateFinder(appDomain, logger);
                var assemblyProvider = new AppDomainAssemblyProvider(appDomain, logger);
                var scanner = new SimpleConventionScanner(assemblyCandidateFinder, b.ServiceProperties, logger);
                return RocketHostExtensions.Swap(b, b
                                                 .With(assemblyCandidateFinder)
                                                 .With(assemblyProvider)
                                                 .With(scanner)
                                                 );
            });
        }
Exemplo n.º 6
0
        /// <summary>
        /// Fors the dependency context.
        /// </summary>
        /// <param name="dependencyContext">The dependency context.</param>
        /// <param name="diagnosticSource">The diagnostic source.</param>
        /// <returns>Func&lt;IHostBuilder, IRocketHostBuilder&gt;.</returns>
        public static Func <IHostBuilder, IRocketHostBuilder> ForDependencyContext(
            DependencyContext dependencyContext,
            DiagnosticSource?diagnosticSource = null
            ) => builder =>
        {
            var b = RocketHostExtensions.GetOrCreateBuilder(builder);
            if (diagnosticSource != null)
            {
                b = b.With(diagnosticSource);
            }

            var logger = new DiagnosticLogger(b.DiagnosticSource);
            var assemblyCandidateFinder = new DependencyContextAssemblyCandidateFinder(dependencyContext, logger);
            var assemblyProvider        = new DependencyContextAssemblyProvider(dependencyContext, logger);
            var scanner = new SimpleConventionScanner(assemblyCandidateFinder, b.ServiceProperties, logger);
            return(RocketHostExtensions.Swap(
                       b,
                       b
                       .With(assemblyCandidateFinder)
                       .With(assemblyProvider)
                       .With(scanner)
                       ));
        };
Exemplo n.º 7
0
        /// <summary>
        /// Fors the assemblies.
        /// </summary>
        /// <param name="assemblies">The assemblies.</param>
        /// <param name="diagnosticSource">The diagnostic source.</param>
        /// <returns>Func&lt;IHostBuilder, IRocketHostBuilder&gt;.</returns>
        public static Func <IHostBuilder, IRocketHostBuilder> ForAssemblies(
            IEnumerable <Assembly> assemblies,
            DiagnosticSource diagnosticSource = null)
        {
            return(builder =>
            {
                var b = RocketHostExtensions.GetOrCreateBuilder(builder);
                if (diagnosticSource != null)
                {
                    b = b.With(diagnosticSource);
                }

                var logger = new DiagnosticLogger(b.DiagnosticSource);
                var enumerable = assemblies as Assembly[] ?? assemblies.ToArray();
                var assemblyCandidateFinder = new DefaultAssemblyCandidateFinder(enumerable, logger);
                var assemblyProvider = new DefaultAssemblyProvider(enumerable, logger);
                var scanner = new SimpleConventionScanner(assemblyCandidateFinder, b.ServiceProperties, logger);
                return RocketHostExtensions.Swap(b, b
                                                 .With(assemblyCandidateFinder)
                                                 .With(assemblyProvider)
                                                 .With(scanner)
                                                 );
            });
        }