/// <summary>
        /// Gets the or create builder.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <returns>RocketHostBuilder.</returns>
        internal static RocketHostBuilder GetOrCreateBuilder(IHostBuilder builder)
        {
            if (!Builders.TryGetValue(builder, out var conventionalBuilder))
            {
                var diagnosticSource          = new DiagnosticListener("Rocket.Surgery.Hosting");
                var dependencyContext         = DependencyContext.Default;
                var logger                    = new DiagnosticLogger(diagnosticSource);
                var serviceProviderDictionary = new ServiceProviderDictionary(builder.Properties);
                serviceProviderDictionary.Set <ILogger>(logger);
                var assemblyCandidateFinder = new DependencyContextAssemblyCandidateFinder(dependencyContext, logger);
                var assemblyProvider        = new DependencyContextAssemblyProvider(dependencyContext, logger);
                var scanner = new SimpleConventionScanner(assemblyCandidateFinder, serviceProviderDictionary, logger);
                conventionalBuilder = new RocketHostBuilder(builder, scanner, assemblyCandidateFinder, assemblyProvider, diagnosticSource, serviceProviderDictionary);

                var host = new RocketContext(builder);
                builder
                .ConfigureHostConfiguration(host.CaptureArguments)
                .ConfigureHostConfiguration(host.ConfigureCli)
                .ConfigureAppConfiguration(host.ReplaceArguments)
                .ConfigureAppConfiguration(host.ConfigureAppConfiguration)
                .ConfigureServices(host.ConfigureServices)
                .ConfigureServices(host.DefaultServices);
                Builders.Add(builder, conventionalBuilder);
            }

            return(conventionalBuilder);
        }
 /// <summary>
 /// Swaps the specified builder.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="newRocketBuilder">The new rocket builder.</param>
 /// <returns>RocketHostBuilder.</returns>
 internal static RocketHostBuilder Swap(IRocketHostBuilder builder, RocketHostBuilder newRocketBuilder)
 {
     Builders.Remove(builder.Builder);
     Builders.Add(builder.Builder, newRocketBuilder);
     return(newRocketBuilder);
 }
        /// <summary>
        /// Gets the or create builder.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <returns>RocketHostBuilder.</returns>
        internal static RocketHostBuilder GetOrCreateBuilder(IHostBuilder builder)
        {
            if (!Builders.TryGetValue(builder, out var conventionalBuilder))
            {
                var diagnosticSource          = new DiagnosticListener("Rocket.Surgery.Hosting");
                var dependencyContext         = DependencyContext.Default;
                var logger                    = new DiagnosticLogger(diagnosticSource);
                var serviceProviderDictionary = new ServiceProviderDictionary(builder.Properties);
                serviceProviderDictionary.Set <ILogger>(logger);
                serviceProviderDictionary.Set(HostType.Live);
                var assemblyCandidateFinder = new DependencyContextAssemblyCandidateFinder(dependencyContext, logger);
                var assemblyProvider        = new DependencyContextAssemblyProvider(dependencyContext, logger);
                var scanner = new SimpleConventionScanner(assemblyCandidateFinder, serviceProviderDictionary, logger);
                conventionalBuilder = new RocketHostBuilder(
                    builder,
                    scanner,
                    assemblyCandidateFinder,
                    assemblyProvider,
                    diagnosticSource,
                    serviceProviderDictionary
                    );

                conventionalBuilder.Set(
                    new ConfigurationOptions
                {
                    ApplicationConfiguration =
                    {
                        b => b.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true),
                        b => b.AddYamlFile("appsettings.yml",  optional: true, reloadOnChange: true),
                        b => b.AddYamlFile("appsettings.yaml", optional: true, reloadOnChange: true),
                        b => b.AddIniFile("appsettings.ini",   optional: true, reloadOnChange: true)
                    },
                    EnvironmentConfiguration =
                    {
                        (b, environmentName) => b.AddJsonFile(
                            $"appsettings.{environmentName}.json",
                            optional: true,
                            reloadOnChange: true
                            ),
                        (b, environmentName) => b.AddYamlFile(
                            $"appsettings.{environmentName}.yml",
                            optional: true,
                            reloadOnChange: true
                            ),
                        (b, environmentName) => b.AddYamlFile(
                            $"appsettings.{environmentName}.yaml",
                            optional: true,
                            reloadOnChange: true
                            ),
                        (b, environmentName) => b.AddIniFile(
                            $"appsettings.{environmentName}.ini",
                            optional: true,
                            reloadOnChange: true
                            )
                    }
                }
                    );

                var host = new RocketContext(builder);
                builder
                .ConfigureHostConfiguration(host.ComposeHostingConvention)
                .ConfigureHostConfiguration(host.CaptureArguments)
                .ConfigureHostConfiguration(host.ConfigureCli)
                .ConfigureAppConfiguration(host.ReplaceArguments)
                .ConfigureAppConfiguration(host.ConfigureAppConfiguration)
                .ConfigureServices(host.ConfigureServices)
                .ConfigureServices(host.DefaultServices);
                Builders.Add(builder, conventionalBuilder);
            }

            return(conventionalBuilder);
        }