Example #1
0
        private static void AddStartupEnvironmentsWithServices(string solutionDirectory, ApiTemplate template)
        {
            // add a development environment by default for local work if none exists
            if (template.Environments.Where(e => e.EnvironmentName == "Development").Count() == 0)
            {
                template.Environments.Add(new ApiEnvironment {
                    EnvironmentName = "Development", ProfileName = $"{template.SolutionName} (Development)"
                });
            }

            foreach (var env in template.Environments)
            {
                // default startup is already built in cleanup phase
                if (env.EnvironmentName != "Startup")
                {
                    StartupBuilder.CreateStartup(solutionDirectory, env.EnvironmentName, template);
                }

                AppSettingsBuilder.CreateAppSettings(solutionDirectory, env, template.DbContext.DatabaseName, template);
                LaunchSettingsModifier.AddProfile(solutionDirectory, env);

                //services
                if (!template.SwaggerConfig.IsSameOrEqualTo(new SwaggerConfig()))
                {
                    SwaggerBuilder.RegisterSwaggerInStartup(solutionDirectory, env);
                }
            }
        }
Example #2
0
 static async Task Main(string[] args)
 {
     await new HostBuilder()
     .ConfigureHostConfiguration((configHost) =>
     {
         configHost.AddEnvironmentVariables("DOTNET_");
     })
     .ConfigureAppConfiguration((hostBuilder, config) =>
     {
         config.SetBasePath(Directory.GetCurrentDirectory());
         config.AddJsonFile("appsettings.json", optional: true);
         config.AddJsonFile($"appsettings.{hostBuilder.HostingEnvironment.EnvironmentName}.json", optional: true);
         config.AddEnvironmentVariables("fiksArkivMock_");
     })
     .ConfigureServices((hostContext, services) =>
     {
         services.AddSingleton(AppSettingsBuilder.CreateAppSettings(hostContext.Configuration));
         services.AddHostedService <ArkivService>();
     })
     .RunConsoleAsync();
 }