Beispiel #1
0
        public async static Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>
                                        ();
                var logger = loggerFactory.CreateLogger <Program>();

                try
                {
                    var context = services.GetRequiredService <CustomerContext>();
                    await context.Database.MigrateAsync();

                    await SeedCustomers.SeedAsync(context, loggerFactory);

                    logger.LogInformation("Migration is applied");
                }
                catch (System.Exception ex)
                {
                    logger.LogError(ex, "An error occured during migration");
                }
            }

            host.Run();
        }
Beispiel #2
0
        public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            var configBuilder = new ConfigurationBuilder(appEnv.ApplicationBasePath);

            configBuilder.AddJsonFile("config.json");
            configBuilder.AddEnvironmentVariables();
            Configuration = configBuilder.Build();

            if (bool.Parse(Configuration["Data:SeedDataOnStartup"]))
            {
                if (Configuration.GetSection("Persistence").Value.Equals("SQL"))
                {
                    SeedCustomers.SeedToMSSQL(Configuration["Data:SQL:ConnectionString"]);
                }
                else if (Configuration.GetSection("Persistence").Value.Equals("Graph"))
                {
                    SeedCustomers.SeedToNeo4j(Configuration["Data:Graph:ConnectionString"]);
                }
            }
        }