Skip to content

Instantly share code, notes, and snippets.

@solrevdev
Created July 16, 2018 09:15
Show Gist options
  • Save solrevdev/32a1b820a450bc8f93d8f4b49c007736 to your computer and use it in GitHub Desktop.
Save solrevdev/32a1b820a450bc8f93d8f4b49c007736 to your computer and use it in GitHub Desktop.
Program.cs that adds json file per machine name
using System;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using System.Reflection;
namespace web
{
public class Program
{
public static void Main(string[] args)
{
var host = CreateWebHostBuilder(args).Build();
using (var scope = host.Services.CreateScope())
{
var service = scope.ServiceProvider;
try
{
SeedData.CreateDatabaseTablesIfNotExist(service);
SeedData.SeedDatabaseTablesIfNeeded(service);
}
catch (Exception ex)
{
var logger = service.GetRequiredService<ILogger<Program>>();
logger.LogError(ex, "An error occurred seeding the DB.");
}
}
host.Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostContext, config) =>
{
//config.Sources.Clear();//
config.AddJsonFile($"appsettings.{Environment.MachineName}.json", optional: true); // allows machine/dev specific overrides
})
.UseStartup<Startup>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment