Exemplo n.º 1
0
        public static async Task Main(string[] args)
        {
            var host          = CreateHostBuilder(args).Build();
            var loggerFactory = host.Services.GetRequiredService <ILoggerFactory>();

            using (var scope = host.Services.CreateScope())
            {
                try
                {
                    var context = scope.ServiceProvider.GetRequiredService <StoreContext>();
                    await context.Database.MigrateAsync();

                    await StoreSeedData.SeedAsync(context, loggerFactory);
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogInformation(ex.ToString(), "Error in migrations");
                }
            }

            host.Run();
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, StorEntities context)
        {
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Stores}/{action=Index}/{id?}");
            });

            //Initialize the Store db
            StoreSeedData.SeedStor(context);
        }