Skip to content

Commit

Permalink
Update Startup.cs to .NET Core 2.0 style
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel15 committed Oct 16, 2017
1 parent 599e977 commit af6f90b
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions Daniel15.Web/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using System;
using System;
using System.IO;
using System.Linq;
using Daniel15.Infrastructure;
using Daniel15.SimpleIdentity;
using Daniel15.Web.Extensions;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
Expand All @@ -21,20 +20,14 @@ namespace Daniel15.Web
{
public class Startup
{
public Startup(IHostingEnvironment env)
public Startup(IConfiguration configuration)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("config.json", optional: false, reloadOnChange: true)
.AddJsonFile("config.generated.json", optional: true)
.AddJsonFile($"config.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
Configuration = configuration;
}

public IConfigurationRoot Configuration { get; set; }
public IConfiguration Configuration { get; set; }

public void ConfigureServices(IServiceCollection services)
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddIdentity<SimpleIdentityUser, SimpleIdentityRole>()
.AddSimpleIdentity<SimpleIdentityUser>(Configuration.GetSection("Auth"))
Expand Down Expand Up @@ -88,17 +81,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF

public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.AddCommandLine(args)
.Build();

var host = new WebHostBuilder()
.UseKestrel()
.UseConfiguration(config)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
var host = BuildWebHost(args);

// Delete UNIX pipe if it exists at startup (eg. previous process crashed before cleaning it up)
var addressFeature = host.ServerFeatures.Get<IServerAddressesFeature>();
Expand All @@ -111,5 +94,19 @@ public static void Main(string[] args)

host.Run();
}

public static IWebHost BuildWebHost(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureAppConfiguration((hostContext, config) =>
{
config
.AddJsonFile("config.json", optional: false, reloadOnChange: true)
.AddJsonFile("config.generated.json", optional: true)
.AddJsonFile($"config.{hostContext.HostingEnvironment.EnvironmentName}.json", optional: true);
})
.Build();
}
}
}

0 comments on commit af6f90b

Please sign in to comment.