Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
73 lines (60 sloc) 2.37 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FancyRestaurant.Models;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace FancyRestaurant
{
public class Startup
{
private readonly IHostingEnvironment _env;
private readonly IConfigurationRoot _config;
private ILogger<Startup> _logger;
public Startup(IHostingEnvironment env, ILogger<Startup> logger)
{
_logger = logger;
_env = env;
var builder = new ConfigurationBuilder().SetBasePath(_env.ContentRootPath).AddJsonFile("config.json");
_config = builder.Build();
}
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton(_config);
services.AddDbContext<FancyRestaurantContext>();
services.AddScoped<IReservationRepository, ReservationRepository>();
services.AddTransient<FancyRestaurantSeedData>();
services.AddMvc(config =>
{
if (_env.IsProduction())
{
config.Filters.Add(new RequireHttpsAttribute());
}
});
}
// 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, FancyRestaurantSeedData seeder)
{
loggerFactory.AddConsole();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseMvc(config =>
{
config.MapRoute(name: "Default", template: "{controller}/{action}/{id?}",
defaults: new {controller = "App", action = "Index"});
});
seeder.EnsureSeedData();
}
}
}