Example #1
0
        private static void SeedDatabase(IHost host)
        {
            using var scope = host.Services.CreateScope();
            var services      = scope.ServiceProvider;
            var loggerFactory = services.GetRequiredService <ILoggerFactory>();

            try
            {
                var aspnetRunContext = services.GetRequiredService <DemoContext>();
                DemoContextSeed.SeedAsync(aspnetRunContext, loggerFactory).Wait();
            }
            catch (Exception exception)
            {
                var logger = loggerFactory.CreateLogger <Program>();
                logger.LogError(exception, "An error occurred seeding the DB.");
            }
        }
Example #2
0
        private static void SeedDatabase(IHost host)
        {
            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();

                try
                {
                    var demoContext = services.GetRequiredService <DemoContext>();
                    DemoContextSeed.SeedAsync(demoContext, loggerFactory).Wait();
                }
                catch (Exception exception)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(exception, "Un Error ha ocurrido en la base de datos");
                }
            }
        }
Example #3
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;

                try
                {
                    var demoContext = services.GetService <DemoContext>();
                    DemoContextSeed.Seed(demoContext);
                }
                catch (Exception ex)
                {
                    Console.Out.WriteLine(ex);
                }
            }

            host.Run();
        }