From b656d657b9d3b9720fd14864483b871e9324b6d7 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 8 Dec 2021 17:55:31 +0000 Subject: [PATCH] Migrate to .NET 6.0 --- Aaru.Server.Task/Aaru.Server.Task.csproj | 4 +- Aaru.Server/Aaru.Server.csproj | 16 ++--- Aaru.Server/Program.cs | 82 ++++++++++++++++++--- Aaru.Server/Startup.cs | 91 ------------------------ 4 files changed, 83 insertions(+), 110 deletions(-) delete mode 100644 Aaru.Server/Startup.cs diff --git a/Aaru.Server.Task/Aaru.Server.Task.csproj b/Aaru.Server.Task/Aaru.Server.Task.csproj index b49221eb..8fed1cab 100644 --- a/Aaru.Server.Task/Aaru.Server.Task.csproj +++ b/Aaru.Server.Task/Aaru.Server.Task.csproj @@ -2,7 +2,7 @@ Exe - net5.0 + net6.0 9 @@ -26,7 +26,7 @@ - + diff --git a/Aaru.Server/Aaru.Server.csproj b/Aaru.Server/Aaru.Server.csproj index 227b5c36..785e5d3a 100644 --- a/Aaru.Server/Aaru.Server.csproj +++ b/Aaru.Server/Aaru.Server.csproj @@ -1,7 +1,7 @@  - net5.0 + net6.0 9 @@ -32,14 +32,14 @@ - - - - - - + + + + + + - + diff --git a/Aaru.Server/Program.cs b/Aaru.Server/Program.cs index 009d8130..31156d94 100644 --- a/Aaru.Server/Program.cs +++ b/Aaru.Server/Program.cs @@ -1,10 +1,15 @@ using System; using Aaru.CommonTypes.Interop; using Aaru.Server.Models; -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.HttpOverrides; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Prometheus; using Version = Aaru.CommonTypes.Interop.Version; namespace Aaru.Server @@ -70,9 +75,72 @@ namespace Aaru.Server DetectOS.IsMono ? "Mono" : ".NET Core", DetectOS.IsMono ? Version.GetMonoVersion() : Version.GetNetCoreVersion()); - IHost host = CreateHostBuilder(args).Build(); + System.Console.WriteLine("\u001b[31;1mBuilding web application...\u001b[0m"); - using(IServiceScope scope = host.Services.CreateScope()) + WebApplicationBuilder builder = WebApplication.CreateBuilder(args); + + builder.Services.AddDbContext(options => options. + UseMySql(builder.Configuration.GetConnectionString("DefaultConnection"), + new MariaDbServerVersion(new System. + Version(10, 4, 0))). + UseLazyLoadingProxies()); + + builder.Services.AddDefaultIdentity(options => + { + options.SignIn.RequireConfirmedAccount = true; + options.User.RequireUniqueEmail = true; + }).AddEntityFrameworkStores(); + + builder.Services.AddApplicationInsightsTelemetry(); + + builder.Services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0); + + WebApplication app = builder.Build(); + + app.UseForwardedHeaders(new ForwardedHeadersOptions + { + ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto + }); + + app.UseHttpMetrics(); + + if(builder.Environment.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.UseDefaultFiles(); + app.UseStaticFiles(); + + // Add other security headers + app.UseMiddleware(); + + app.UseRouting(); + + app.UseAuthentication(); + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllerRoute("areas", "{area}/{controller=Home}/{action=Index}/{id?}"); + endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); + endpoints.MapRazorPages(); + }); + + app.Map("/metrics", metricsApp => + { + metricsApp.UseMiddleware("Aaru"); + + // We already specified URL prefix in .Map() above, no need to specify it again here. + metricsApp.UseMetricServer(""); + }); + + using(IServiceScope scope = app.Services.CreateScope()) { IServiceProvider services = scope.ServiceProvider; @@ -107,12 +175,8 @@ namespace Aaru.Server } System.Console.WriteLine("\u001b[31;1mStarting web server...\u001b[0m"); - host.Run(); - } - public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args). - ConfigureWebHostDefaults(webBuilder => - webBuilder. - UseStartup()); + app.Run(); + } } } \ No newline at end of file diff --git a/Aaru.Server/Startup.cs b/Aaru.Server/Startup.cs deleted file mode 100644 index 6e543ac0..00000000 --- a/Aaru.Server/Startup.cs +++ /dev/null @@ -1,91 +0,0 @@ -using Aaru.Server.Models; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpOverrides; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Prometheus; -using Version = System.Version; - -namespace Aaru.Server -{ - public sealed 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.AddDbContext(options => options. - UseMySql(Configuration.GetConnectionString("DefaultConnection"), - new MariaDbServerVersion(new Version(10, 4, - 0))). - UseLazyLoadingProxies()); - - services.AddDefaultIdentity(options => - { - options.SignIn.RequireConfirmedAccount = true; - options.User.RequireUniqueEmail = true; - }).AddEntityFrameworkStores(); - - services.AddApplicationInsightsTelemetry(); - - services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0); - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - app.UseForwardedHeaders(new() - { - ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto - }); - - app.UseHttpMetrics(); - - 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.UseDefaultFiles(); - app.UseStaticFiles(); - - // Add other security headers - app.UseMiddleware(); - - app.UseRouting(); - - app.UseAuthentication(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllerRoute("areas", "{area}/{controller=Home}/{action=Index}/{id?}"); - endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); - endpoints.MapRazorPages(); - }); - - app.Map("/metrics", metricsApp => - { - metricsApp.UseMiddleware("Aaru"); - - // We already specified URL prefix in .Map() above, no need to specify it again here. - metricsApp.UseMetricServer(""); - }); - } - } -} \ No newline at end of file