From acefa6446597d732ba547088ac2d4953cd2ca89f Mon Sep 17 00:00:00 2001 From: Unai Zorrilla Castro Date: Tue, 29 Aug 2017 11:40:23 +0200 Subject: [PATCH] Updated Program and Startup to new .NETCoreApp2.0 templates. Minor refactorings --- src/Web/WebMVC/Program.cs | 26 ++++++++++++++++---------- src/Web/WebMVC/Startup.cs | 14 +++++--------- src/Web/WebMVC/WebMVC.csproj | 27 ++++----------------------- 3 files changed, 25 insertions(+), 42 deletions(-) diff --git a/src/Web/WebMVC/Program.cs b/src/Web/WebMVC/Program.cs index 654ae7677..ec711b2ae 100644 --- a/src/Web/WebMVC/Program.cs +++ b/src/Web/WebMVC/Program.cs @@ -1,4 +1,6 @@ -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Logging; using System.IO; namespace Microsoft.eShopOnContainers.WebMVC @@ -7,15 +9,19 @@ namespace Microsoft.eShopOnContainers.WebMVC { public static void Main(string[] args) { - var host = new WebHostBuilder() - .UseKestrel() - .UseHealthChecks("/hc") - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseIISIntegration() - .UseStartup() - .Build(); - - host.Run(); + BuildWebHost(args).Run(); } + + public static IWebHost BuildWebHost(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseHealthChecks("/hc") + .UseStartup() + .ConfigureLogging((hostingContext, builder) => + { + builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); + builder.AddConsole(); + builder.AddDebug(); + }).Build(); } } diff --git a/src/Web/WebMVC/Startup.cs b/src/Web/WebMVC/Startup.cs index ebf303f1b..1791e8da1 100644 --- a/src/Web/WebMVC/Startup.cs +++ b/src/Web/WebMVC/Startup.cs @@ -20,17 +20,12 @@ namespace Microsoft.eShopOnContainers.WebMVC { public class Startup { - public Startup(IHostingEnvironment env) + public Startup(IConfiguration configuration) { - var builder = new ConfigurationBuilder() - .SetBasePath(env.ContentRootPath) - .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) // Settings for the application - .AddEnvironmentVariables(); // override settings with environment variables set in compose. - - Configuration = builder.Build(); + Configuration = configuration; } - public IConfigurationRoot Configuration { get; } + public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) @@ -135,7 +130,8 @@ namespace Microsoft.eShopOnContainers.WebMVC app.UseAuthentication(); var log = loggerFactory.CreateLogger("identity"); - WebContextSeed.Seed(app, env, loggerFactory); + + WebContextSeed.Seed(app, env, loggerFactory); app.UseMvc(routes => { diff --git a/src/Web/WebMVC/WebMVC.csproj b/src/Web/WebMVC/WebMVC.csproj index e6e11cb99..7f45a64f9 100644 --- a/src/Web/WebMVC/WebMVC.csproj +++ b/src/Web/WebMVC/WebMVC.csproj @@ -36,27 +36,8 @@ --> - - - - - - - - - - - - - - - - - - - - - + + @@ -66,8 +47,8 @@ - - + +