// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); Dbinitializer.Initialize(context); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory, IServiceProvider serviceProvider) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseSession(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseCors(builder => { builder.WithOrigins("http://*.axmouth.dev", "https://*.axmouth.dev", "http://localhost") .SetIsOriginAllowedToAllowWildcardSubdomains() .AllowCredentials() .SetIsOriginAllowed((host) => true) .AllowAnyHeader() .AllowAnyMethod(); }); app.UseEndpoints(endpoints => { endpoints.MapControllers().RequireCors(MyAllowSpecificOrigins); }); Dbinitializer.Seed(serviceProvider); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory, IServiceProvider serviceProvider) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseStatusCodePages(); app.UseStaticFiles(); app.UseSession(); // app.UseMvc(routes => // { // routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}"); // }); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute("categoryFilter", "Drink/{action}/{categoryName?}", new { Controller = "Drink", action = "List" }); endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); }); // app.UseMvcWithDefaultRoute(); Dbinitializer.Seed(serviceProvider); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { Dbinitializer.SeedData(scope.ServiceProvider).Wait(); } host.Run(); }
private static void CreateDbIfNotExists(IHost host) { using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <RentaPeli>(); Dbinitializer.Initialize(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error ocurred creating the DB. "); } } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); using (var scope = app .ApplicationServices.CreateScope()) { var ptx = scope.ServiceProvider.GetService <PetAppContext>(); Dbinitializer.SeedDB(ptx); } } else { app.UseHsts(); } app.UseHttpsRedirection(); app.UseMvc(); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <SchoolContext>(); Dbinitializer.Initialize(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "Error during seeding the database"); } } host.Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, SistemaContext context) { if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); Dbinitializer.Initialize(context); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { Dbinitializer.Initialize(services); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } FlyWithWings fly = new FlyWithWings(); FlyNoWay noFly = new FlyNoWay(); MallardDuck md = new MallardDuck(fly); RedheadDuck red = new RedheadDuck(fly); RubberDuck rubberDuck = new RubberDuck(noFly); md.Display(); md.Fly(); red.Display(); red.Fly(); rubberDuck.Display(); rubberDuck.Fly(); host.Run(); }