From 777c3ddd7a69289d2434acf16b90c7db2e8dc36f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 25 Oct 2021 14:50:23 +0300 Subject: [PATCH] Use new hosting model for the MVC app. --- .../Program.cs | 21 +++++++++---------- .../Startup.cs | 18 ---------------- 2 files changed, 10 insertions(+), 29 deletions(-) delete mode 100644 templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/Startup.cs diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/Program.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/Program.cs index e6d0635c7c..3cc35d4291 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/Program.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/Program.cs @@ -1,6 +1,8 @@ using System; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Serilog; using Serilog.Events; @@ -29,7 +31,14 @@ namespace MyCompanyName.MyProjectName.Web try { Log.Information("Starting web host."); - CreateHostBuilder(args).Build().Run(); + var builder = WebApplication.CreateBuilder(args); + builder.Host.AddAppSettingsSecretsJson() + .UseAutofac() + .UseSerilog(); + builder.Services.AddApplication(); + var app = builder.Build(); + app.InitializeApplication(); + app.Run(); return 0; } catch (Exception ex) @@ -42,15 +51,5 @@ namespace MyCompanyName.MyProjectName.Web Log.CloseAndFlush(); } } - - internal static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .AddAppSettingsSecretsJson() - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }) - .UseAutofac() - .UseSerilog(); } } diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/Startup.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/Startup.cs deleted file mode 100644 index 5bacb0f77e..0000000000 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/Startup.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.DependencyInjection; - -namespace MyCompanyName.MyProjectName.Web -{ - public class Startup - { - public void ConfigureServices(IServiceCollection services) - { - services.AddApplication(); - } - - public void Configure(IApplicationBuilder app) - { - app.InitializeApplication(); - } - } -}