From 2c678866415b544ba71a050565c5b4e1ae81a4fb Mon Sep 17 00:00:00 2001 From: seetoe Date: Thu, 2 Nov 2023 20:49:20 -0400 Subject: [PATCH] upgrade from dot net 3.1 to 7 and use minimal hosting model --- .vscode/launch.json | 2 +- Program.cs | 38 +++++++++++++++----------- Startup.cs | 55 -------------------------------------- sm-coding-challenge.csproj | 6 ++--- 4 files changed, 27 insertions(+), 74 deletions(-) delete mode 100644 Startup.cs diff --git a/.vscode/launch.json b/.vscode/launch.json index 94f6038..dd42859 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "request": "launch", "preLaunchTask": "build", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/sm-coding-challenge.dll", + "program": "${workspaceFolder}/bin/Debug/net7.0/sm-coding-challenge.dll", "args": [], "cwd": "${workspaceFolder}", "stopAtEntry": false, diff --git a/Program.cs b/Program.cs index 3e9409b..45f14b2 100644 --- a/Program.cs +++ b/Program.cs @@ -1,20 +1,28 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using sm_coding_challenge.Services.DataProvider; -namespace sm_coding_challenge -{ - public class Program - { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } +var builder = WebApplication.CreateBuilder(args); +builder.Services.AddControllersWithViews(); +builder.Services.AddTransient(); - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } +var app = builder.Build(); +IWebHostEnvironment env = app.Environment; +if (env.IsDevelopment()) +{ + app.UseDeveloperExceptionPage(); +} +else +{ + app.UseExceptionHandler("/Home/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } +app.UseStaticFiles(); +app.UseAuthorization(); +app.MapControllerRoute( + name: "default", + pattern: "{controller=Home}/{action=Index}/{id?}"); +app.Run(); diff --git a/Startup.cs b/Startup.cs deleted file mode 100644 index 6c11a3e..0000000 --- a/Startup.cs +++ /dev/null @@ -1,55 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using sm_coding_challenge.Services.DataProvider; - -namespace sm_coding_challenge -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - 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) - { - services.AddControllersWithViews(); - - services.AddTransient(); - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - else - { - app.UseExceptionHandler("/Home/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseStaticFiles(); - - app.UseRouting(); - - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllerRoute( - name: "default", - pattern: "{controller=Home}/{action=Index}/{id?}"); - }); - } - } -} diff --git a/sm-coding-challenge.csproj b/sm-coding-challenge.csproj index 6c2f700..217bced 100644 --- a/sm-coding-challenge.csproj +++ b/sm-coding-challenge.csproj @@ -1,11 +1,11 @@ - netcoreapp3.1 + net7.0 - - + +