From ce406a28c860630c7342d525181cb6917cafc036 Mon Sep 17 00:00:00 2001 From: Ken Swan <49496839+kenswan@users.noreply.github.com> Date: Thu, 19 Jun 2025 13:54:34 -0500 Subject: [PATCH 1/3] .NET 9 Upgrade --- .../workflows/template-build-test-project.yml | 7 ++-- Directory.Build.props | 1 + Directory.Packages.props | 34 +++++++------------ .../ApplicationBuilderMiddleware.cs | 9 +---- ...BlazorFocused.Exceptions.Middleware.csproj | 2 +- .../src/ExceptionsMiddlewareException.cs | 4 +-- ...rFocused.Exceptions.Middleware.Test.csproj | 2 +- 7 files changed, 22 insertions(+), 37 deletions(-) diff --git a/.github/workflows/template-build-test-project.yml b/.github/workflows/template-build-test-project.yml index 53300e9..3ef9eee 100644 --- a/.github/workflows/template-build-test-project.yml +++ b/.github/workflows/template-build-test-project.yml @@ -32,12 +32,11 @@ jobs: matrix: dotnet-target-framework: ["net6.0", "net7.0", "net8.0"] include: - - dotnet-install-framework: 6.0.x - dotnet-target-framework: net6.0 - - dotnet-install-framework: 7.0.x - dotnet-target-framework: net7.0 - dotnet-install-framework: 8.0.x dotnet-target-framework: net8.0 + + - dotnet-install-framework: 9.0.x + dotnet-target-framework: net9.0 env: source-directory: ${{ inputs.source-directory }} source-project: ${{ inputs.source-project }} diff --git a/Directory.Build.props b/Directory.Build.props index 1444376..0f3f28c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -3,6 +3,7 @@ true true + preview diff --git a/Directory.Packages.props b/Directory.Packages.props index 1a0f656..ca56277 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -6,37 +6,29 @@ + + - - - - - - - - - - + + - - - - + + - - - - + + + + - - - + + + diff --git a/src/Middleware/src/ApplicationBuilder/ApplicationBuilderMiddleware.cs b/src/Middleware/src/ApplicationBuilder/ApplicationBuilderMiddleware.cs index 34b6d1f..7f87448 100644 --- a/src/Middleware/src/ApplicationBuilder/ApplicationBuilderMiddleware.cs +++ b/src/Middleware/src/ApplicationBuilder/ApplicationBuilderMiddleware.cs @@ -14,15 +14,8 @@ namespace BlazorFocused.Exceptions.Middleware.ApplicationBuilder; -internal class ApplicationBuilderMiddleware +internal class ApplicationBuilderMiddleware(RequestDelegate next) { - private readonly RequestDelegate next; - - public ApplicationBuilderMiddleware(RequestDelegate next) - { - this.next = next; - } - public async Task Invoke( HttpContext httpContext, IOptions exceptionsMiddlewareOptions, diff --git a/src/Middleware/src/BlazorFocused.Exceptions.Middleware.csproj b/src/Middleware/src/BlazorFocused.Exceptions.Middleware.csproj index 1c6194a..4a2e85d 100644 --- a/src/Middleware/src/BlazorFocused.Exceptions.Middleware.csproj +++ b/src/Middleware/src/BlazorFocused.Exceptions.Middleware.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0;net8.0 + net8.0;net9.0 diff --git a/src/Middleware/src/ExceptionsMiddlewareException.cs b/src/Middleware/src/ExceptionsMiddlewareException.cs index f1ef614..fabd7b0 100644 --- a/src/Middleware/src/ExceptionsMiddlewareException.cs +++ b/src/Middleware/src/ExceptionsMiddlewareException.cs @@ -28,7 +28,7 @@ public abstract class ExceptionsMiddlewareException : Exception /// Desired status code of a given exception /// Message that should be logged in case of given exception /// Passed in "message" will also be output to client/user if "clientErrorMessage" not specified - public ExceptionsMiddlewareException(HttpStatusCode httpStatusCode, string message) : + protected ExceptionsMiddlewareException(HttpStatusCode httpStatusCode, string message) : base(message) { StatusCode = httpStatusCode; @@ -41,7 +41,7 @@ public ExceptionsMiddlewareException(HttpStatusCode httpStatusCode, string messa /// Message that should be logged in case of given exception /// Inner exception that triggered exception response /// Passed in "message" will also be output to client/user if "clientErrorMessage" not specified - public ExceptionsMiddlewareException(HttpStatusCode httpStatusCode, string message, Exception innerException) : + protected ExceptionsMiddlewareException(HttpStatusCode httpStatusCode, string message, Exception innerException) : base(message, innerException) { StatusCode = httpStatusCode; diff --git a/src/Middleware/test/BlazorFocused.Exceptions.Middleware.Test.csproj b/src/Middleware/test/BlazorFocused.Exceptions.Middleware.Test.csproj index 54053b6..7a8d36d 100644 --- a/src/Middleware/test/BlazorFocused.Exceptions.Middleware.Test.csproj +++ b/src/Middleware/test/BlazorFocused.Exceptions.Middleware.Test.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0;net8.0 + net8.0;net9.0 false true From 7e16fdc83239df950fa46ee58b7cb4ae1f0aa8f5 Mon Sep 17 00:00:00 2001 From: Ken Swan <49496839+kenswan@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:01:06 -0500 Subject: [PATCH 2/3] Correct Build Target Framework --- .github/workflows/template-build-test-project.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/template-build-test-project.yml b/.github/workflows/template-build-test-project.yml index 3ef9eee..256b3c5 100644 --- a/.github/workflows/template-build-test-project.yml +++ b/.github/workflows/template-build-test-project.yml @@ -30,7 +30,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - dotnet-target-framework: ["net6.0", "net7.0", "net8.0"] + dotnet-target-framework: ["net8.0", "net9.0"] include: - dotnet-install-framework: 8.0.x dotnet-target-framework: net8.0 From 894c5a34700b012b4aa6fbce775820120b7ffafd Mon Sep 17 00:00:00 2001 From: Ken Swan <49496839+kenswan@users.noreply.github.com> Date: Fri, 20 Jun 2025 09:24:39 -0500 Subject: [PATCH 3/3] Update Sample/Test Packages --- .../template-build-test-solution.yml | 2 +- samples/Directory.Packages.props | 19 +++++++++---------- .../MiddlewareSample.Api.Test.csproj | 2 +- .../MiddlewareSample.Api.csproj | 3 +-- .../MiddlewareSample.Api.http | 8 ++++++++ .../MiddlewareSample.Api/Program.cs | 7 +++---- .../Properties/launchSettings.json | 12 +----------- 7 files changed, 24 insertions(+), 29 deletions(-) create mode 100644 samples/MiddlewareSample/MiddlewareSample.Api/MiddlewareSample.Api.http diff --git a/.github/workflows/template-build-test-solution.yml b/.github/workflows/template-build-test-solution.yml index 6c9f83d..5282f67 100644 --- a/.github/workflows/template-build-test-solution.yml +++ b/.github/workflows/template-build-test-solution.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest env: - dotnet-install-framework: 8.0.x + dotnet-install-framework: 9.0.x defaults: run: diff --git a/samples/Directory.Packages.props b/samples/Directory.Packages.props index 41679ce..66dae7b 100644 --- a/samples/Directory.Packages.props +++ b/samples/Directory.Packages.props @@ -5,22 +5,21 @@ - - + - - - - - + + + + + - - - + + + diff --git a/samples/MiddlewareSample/MiddlewareSample.Api.Test/MiddlewareSample.Api.Test.csproj b/samples/MiddlewareSample/MiddlewareSample.Api.Test/MiddlewareSample.Api.Test.csproj index d8960ba..1f7066e 100644 --- a/samples/MiddlewareSample/MiddlewareSample.Api.Test/MiddlewareSample.Api.Test.csproj +++ b/samples/MiddlewareSample/MiddlewareSample.Api.Test/MiddlewareSample.Api.Test.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 false true diff --git a/samples/MiddlewareSample/MiddlewareSample.Api/MiddlewareSample.Api.csproj b/samples/MiddlewareSample/MiddlewareSample.Api/MiddlewareSample.Api.csproj index 3b0720b..c5a4fa9 100644 --- a/samples/MiddlewareSample/MiddlewareSample.Api/MiddlewareSample.Api.csproj +++ b/samples/MiddlewareSample/MiddlewareSample.Api/MiddlewareSample.Api.csproj @@ -1,13 +1,12 @@ - net8.0 + net9.0 false - diff --git a/samples/MiddlewareSample/MiddlewareSample.Api/MiddlewareSample.Api.http b/samples/MiddlewareSample/MiddlewareSample.Api/MiddlewareSample.Api.http new file mode 100644 index 0000000..ec6425f --- /dev/null +++ b/samples/MiddlewareSample/MiddlewareSample.Api/MiddlewareSample.Api.http @@ -0,0 +1,8 @@ +@baseAddress = https://localhost:7288 + +GET {{baseAddress}}/ThrowRandomException + +### + +GET {{baseAddress}}/ThrowCustomClientException?statusCode=400&message=Test%20Exception%20Throw + diff --git a/samples/MiddlewareSample/MiddlewareSample.Api/Program.cs b/samples/MiddlewareSample/MiddlewareSample.Api/Program.cs index e78a9d5..ea2551e 100644 --- a/samples/MiddlewareSample/MiddlewareSample.Api/Program.cs +++ b/samples/MiddlewareSample/MiddlewareSample.Api/Program.cs @@ -11,7 +11,7 @@ WebApplicationBuilder builder = WebApplication.CreateBuilder(args); builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); +builder.Services.AddOpenApi(); // Register custom exceptions and status codes builder.Services @@ -20,15 +20,14 @@ { options.CorrelationKey = "X-TestCorrelation-Id"; options.CorrelationKey = CORRELATION_HEADER_KEY; - options.ConfigureCorrelationValue = (httpContext) => { return httpContext.TraceIdentifier; }; + options.ConfigureCorrelationValue = (httpContext) => httpContext.TraceIdentifier; }) // Use this extension for default correlation key/value .AddException(HttpStatusCode.FailedDependency); WebApplication app = builder.Build(); -app.UseSwagger(); -app.UseSwaggerUI(); app.UseHttpsRedirection(); +app.MapOpenApi(); // Register Exceptions API Middleware app.UseExceptionsMiddleware(); diff --git a/samples/MiddlewareSample/MiddlewareSample.Api/Properties/launchSettings.json b/samples/MiddlewareSample/MiddlewareSample.Api/Properties/launchSettings.json index b6f68fa..bd79831 100644 --- a/samples/MiddlewareSample/MiddlewareSample.Api/Properties/launchSettings.json +++ b/samples/MiddlewareSample/MiddlewareSample.Api/Properties/launchSettings.json @@ -1,21 +1,11 @@ { "$schema": "https://json.schemastore.org/launchsettings.json", "profiles": { - "Sample API - Http": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "launchUrl": "swagger", - "applicationUrl": "http://localhost:5176", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, "Sample API - Https": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "launchUrl": "swagger", + "launchUrl": "openapi/v1.json", "applicationUrl": "https://localhost:7288;http://localhost:5101", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development"