// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, CityInfoContex cityInfoContex) { loggerFactory.AddNLog(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler(); } cityInfoContex.EnsureSeedDataForContext(); app.UseStatusCodePages(); app.UseMvc(); //app.Run((context) => throw new Exception("Example exception")); //app.Run(async (context) => //{ // await context.Response.WriteAsync("Hello World!"); //}); }
public DummyController(CityInfoContex ctx) { _ctx = ctx ?? throw new ArgumentNullException(nameof(ctx)); }
public CityInfoRepository(CityInfoContex context) { _context = context ?? throw new ArgumentNullException(nameof(context)); }
public DummyController(CityInfoContex ctx) { _ctx = ctx; }
public static void EnsureSeedDataForContext(this CityInfoContex contex) { if (contex.Cities.Any()) { return; } var cities = new List <City>() { new City() { Name = "New York City", Description = "The one with that big park.", PointsOfInterest = new List <PointOfInterest>() { new PointOfInterest() { Name = "Central Park", Description = "The most visited urban park in the United States." }, new PointOfInterest() { Name = "Empire State Building", Description = "A 102-story skyscraper located in Midtown Manhattan." }, } }, new City() { Name = "Antwerp", Description = "The one with the cathedral that was never really finished.", PointsOfInterest = new List <PointOfInterest>() { new PointOfInterest() { Name = "Cathedral of Our Lady", Description = "A Gothic style cathedral, conceived by architects Jan and Pieter Appelmans." }, new PointOfInterest() { Name = "Antwerp Central Station", Description = "The the finest example of railway architecture in Belgium." }, } }, new City() { Name = "Paris", Description = "The one with that big tower.", PointsOfInterest = new List <PointOfInterest>() { new PointOfInterest() { Name = "Eiffel Tower", Description = "A wrought iron lattice tower on the Champ de Mars, named after engineer Gustave Eiffel." }, new PointOfInterest() { Name = "The Louvre", Description = "The world's largest museum." }, } } }; contex.AddRange(cities); contex.SaveChanges(); }