Esempio n. 1
0
        public static void Main(string[] args)
        {
            Console.Title = "Sales API";
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                try
                {
                    var salesContext = services.GetRequiredService <SalesContext>();
                    SalesContextSeed.SeedAsync(salesContext, loggerFactory).Wait();
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }

            host.Run();
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                try
                {
                    var storageService = services.GetRequiredService <IStorageService>();
                    ProductImagesSeed.SeedAsync(storageService, "images", "products", loggerFactory).Wait();

                    var catalogContext = services.GetRequiredService <CatalogContext>();
                    catalogContext.Database.EnsureCreated();
                    CatalogContextSeed.SeedAsync(catalogContext, loggerFactory).Wait();

                    var salesContext = services.GetRequiredService <SalesContext>();
                    salesContext.Database.EnsureCreated();
                    SalesContextSeed.SeedAsync(catalogContext, salesContext, loggerFactory).Wait();

                    var identityContext = services.GetRequiredService <AppIdentityDbContext>();
                    identityContext.Database.EnsureCreated();

                    var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
                    AppIdentityDbContextSeed.SeedAsync(userManager).Wait();
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }

            host.Run();
        }