Pārlūkot izejas kodu

Cleanup and small improvements

Lukas Angerer 1 gadu atpakaļ
vecāks
revīzija
b930ae3ce1

+ 3 - 2
WebTemplate/AppServer.cs

@@ -18,14 +18,15 @@ public class AppServer
     /// </summary>
     private readonly IList<IAppConfigurationModule> _modules = new List<IAppConfigurationModule>
     {
-        new JsonModule(),
         new AuthModule(),
         new CorsModule(),
+        new JsonModule(),
         new SwaggerModule(),
-        new SpaRoutingModule(),
         new ValidationModule(),
         new StatusEndpointModule(),
         new ControllersModule(),
+        // Keep the SpaRoutingModule at the very end
+        new SpaRoutingModule(),
     };
 
     public void Start(string[] args)

+ 2 - 4
WebTemplate/Program.cs

@@ -1,9 +1,7 @@
-
 using WebTemplate;
 
-var server = new AppServer();
-server.Start(args);
-
 // After launching the application, you can access
 // * https://localhost:7169/swagger/
 // * https://localhost:7169/v1/status
+var server = new AppServer();
+server.Start(args);

+ 2 - 12
WebTemplate/Properties/launchSettings.json

@@ -1,22 +1,12 @@
 {
   "$schema": "http://json.schemastore.org/launchsettings.json",
   "profiles": {
-    "http": {
-      "commandName": "Project",
-      "dotnetRunMessages": true,
-      "launchBrowser": true,
-      "launchUrl": "http://localhost:5292/v1/status",
-      "applicationUrl": "http://localhost:5292",
-      "environmentVariables": {
-        "ASPNETCORE_ENVIRONMENT": "Development"
-      }
-    },
     "https": {
       "commandName": "Project",
       "dotnetRunMessages": true,
       "launchBrowser": true,
-      "launchUrl": "https://localhost:7169/v1/status",
-      "applicationUrl": "https://localhost:7169;http://localhost:5292",
+      "launchUrl": "https://localhost:7169/swagger",
+      "applicationUrl": "https://localhost:7169",
       "environmentVariables": {
         "ASPNETCORE_ENVIRONMENT": "Development"
       }

+ 2 - 2
WebTemplate/ServerAspects/Controllers/ControllersModule.cs

@@ -1,4 +1,4 @@
-namespace WebTemplate.ServerAspects.Controllers;
+namespace WebTemplate.ServerAspects.Controllers;
 
 public class ControllersModule : IAppConfigurationModule
 {
@@ -12,4 +12,4 @@ public class ControllersModule : IAppConfigurationModule
     {
         app.MapControllers();
     }
-}
+}

+ 2 - 2
WebTemplate/ServerAspects/Json/JsonModule.cs

@@ -1,4 +1,4 @@
-using System.Text.Json.Serialization;
+using System.Text.Json.Serialization;
 
 namespace WebTemplate.ServerAspects.Json;
 
@@ -17,4 +17,4 @@ public class JsonModule : IAppConfigurationModule
     public void ConfigureApplication(WebApplication app)
     {
     }
-}
+}

+ 6 - 0
WebTemplate/ServerAspects/Spa/SpaRoutingModule.cs

@@ -1,5 +1,11 @@
 namespace WebTemplate.ServerAspects.Spa;
 
+/// <summary>
+/// IMPORTANT: The <see cref="SpaDefaultPageMiddleware"/> _by design_ MUST map ALL previously unmapped routes
+/// to the default page which makes this module very susceptible to ordering issues. Any middleware that is registered
+/// AFTER the SPA default page middleware is not actually going to get a chance to add anything to the routing process
+/// if at the point of the SPA default page middleware the "GetEndpoint" method returns null.
+/// </summary>
 public class SpaRoutingModule : IAppConfigurationModule
 {
 	public void ConfigureServices(IServiceCollection services, IConfigurationRoot config)

+ 2 - 2
WebTemplate/ServerAspects/Swagger/StringEnumSchemaFilter.cs

@@ -1,4 +1,4 @@
-using System.ComponentModel;
+using System.ComponentModel;
 using System.Reflection;
 using Microsoft.OpenApi.Any;
 using Microsoft.OpenApi.Models;
@@ -37,4 +37,4 @@ public class StringEnumSchemaFilter : ISchemaFilter
             schema.Description = description.ToString();
         }
     }
-}
+}

+ 2 - 2
WebTemplate/ServerAspects/Validation/ValidationFilter.cs

@@ -1,4 +1,4 @@
-using FluentValidation;
+using FluentValidation;
 
 namespace WebTemplate.ServerAspects.Validation;
 
@@ -36,4 +36,4 @@ public class ValidationFilter<T> : IEndpointFilter
         
         return Results.Problem("Could not find type to validate");
     }
-}
+}

+ 2 - 2
WebTemplate/ServerAspects/Validation/ValidationModule.cs

@@ -1,4 +1,4 @@
-using FluentValidation;
+using FluentValidation;
 
 namespace WebTemplate.ServerAspects.Validation;
 
@@ -21,4 +21,4 @@ public class ValidationModule : IAppConfigurationModule
     public void ConfigureApplication(WebApplication app)
     {
     }
-}
+}

+ 1 - 1
WebTemplate/Status/ServiceStatus.cs

@@ -1,4 +1,4 @@
-namespace WebTemplate.Status;
+namespace WebTemplate.Status;
 
 /// <summary>
 /// Overall service status result.

+ 1 - 1
WebTemplate/Status/StatusEndpointModule.cs

@@ -1,4 +1,4 @@
-namespace WebTemplate.Status;
+namespace WebTemplate.Status;
 
 public class StatusEndpointModule : IAppConfigurationModule
 {

+ 1 - 2
WebTemplate/WebTemplate.csproj

@@ -9,12 +9,11 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="FluentValidation" Version="11.9.0" />
-    <PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.9.0" />
     <PackageReference Include="GitInfo" Version="3.3.4">
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>
+    <PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
     <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.1" />
     <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.1" />
     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />