Commit ad83abb5 authored by Scott DePouw's avatar Scott DePouw

Update Program.cs and Startup.cs to match ASP.NET Core 2.1 templates.

parent 5ae0332d
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore;
using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting;
namespace CleanArchitecture.Web namespace CleanArchitecture.Web
{ {
...@@ -7,12 +7,11 @@ namespace CleanArchitecture.Web ...@@ -7,12 +7,11 @@ namespace CleanArchitecture.Web
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
BuildWebHost(args).Run(); CreateWebHostBuilder(args).Build().Run();
} }
public static IWebHost BuildWebHost(string[] args) => public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args) WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>() .UseStartup<Startup>();
.Build();
} }
} }
using System; using CleanArchitecture.Core.Interfaces;
using CleanArchitecture.Core.Interfaces;
using CleanArchitecture.Core.SharedKernel; using CleanArchitecture.Core.SharedKernel;
using CleanArchitecture.Infrastructure.Data; using CleanArchitecture.Infrastructure.Data;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using StructureMap; using StructureMap;
using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.Swagger;
using System;
namespace CleanArchitecture.Web namespace CleanArchitecture.Web
{ {
...@@ -24,6 +26,12 @@ namespace CleanArchitecture.Web ...@@ -24,6 +26,12 @@ namespace CleanArchitecture.Web
public IServiceProvider ConfigureServices(IServiceCollection services) public IServiceProvider ConfigureServices(IServiceCollection services)
{ {
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
// TODO: Add DbContext and IOC // TODO: Add DbContext and IOC
string dbName = Guid.NewGuid().ToString(); string dbName = Guid.NewGuid().ToString();
services.AddDbContext<AppDbContext>(options => services.AddDbContext<AppDbContext>(options =>
...@@ -31,7 +39,8 @@ namespace CleanArchitecture.Web ...@@ -31,7 +39,8 @@ namespace CleanArchitecture.Web
//options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); //options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddMvc() services.AddMvc()
.AddControllersAsServices(); .AddControllersAsServices()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddSwaggerGen(c => services.AddSwaggerGen(c =>
{ {
...@@ -50,7 +59,7 @@ namespace CleanArchitecture.Web ...@@ -50,7 +59,7 @@ namespace CleanArchitecture.Web
_.WithDefaultConventions(); _.WithDefaultConventions();
_.ConnectImplementationsToTypesClosing(typeof(IHandle<>)); _.ConnectImplementationsToTypesClosing(typeof(IHandle<>));
}); });
// TODO: Add Registry Classes to eliminate reference to Infrastructure // TODO: Add Registry Classes to eliminate reference to Infrastructure
// TODO: Move to Infrastucture Registry // TODO: Move to Infrastucture Registry
...@@ -80,14 +89,17 @@ namespace CleanArchitecture.Web ...@@ -80,14 +89,17 @@ namespace CleanArchitecture.Web
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
app.UseBrowserLink(); // app.UseBrowserLink(); // Must install the Microsoft.VisualStudio.Web.BrowserLink package manually for BrowserLink functionality in 2.1.
} }
else else
{ {
app.UseExceptionHandler("/Home/Error"); app.UseExceptionHandler("/Home/Error");
app.UseHsts();
} }
app.UseHttpsRedirection();
app.UseStaticFiles(); app.UseStaticFiles();
app.UseCookiePolicy();
// Enable middleware to serve generated Swagger as a JSON endpoint. // Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger(); app.UseSwagger();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment