From 41351c0b6cc2bcbfdec815e9870ac9d67bf4d4c7 Mon Sep 17 00:00:00 2001 From: Pierre Arnaud Date: Mon, 16 Sep 2024 17:57:49 +0200 Subject: [PATCH 1/3] Fix try/finally block If getting existingFeature fails, we don't want the finally block to be executed. --- .../Middleware/MultiTenantRequestServicesMiddleware.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Infrastructure/Middleware/MultiTenantRequestServicesMiddleware.cs b/src/Infrastructure/Middleware/MultiTenantRequestServicesMiddleware.cs index 3809cf3..25cc4cd 100644 --- a/src/Infrastructure/Middleware/MultiTenantRequestServicesMiddleware.cs +++ b/src/Infrastructure/Middleware/MultiTenantRequestServicesMiddleware.cs @@ -27,10 +27,9 @@ public async Task Invoke(HttpContext context) httpContextAccessor.HttpContext ??= context; //Replace the service providers feature with our tenant specific one - IServiceProvidersFeature existingFeature = null!; + var existingFeature = context.Features.Get()!; try { - existingFeature = context.Features.Get()!; context.Features.Set(new RequestServicesFeature(context, multiTenantServiceProviderScopeFactory)); await next.Invoke(context); } From 4056a893683dc6db67a0bf55e58e2e54d941babe Mon Sep 17 00:00:00 2001 From: Pierre Arnaud Date: Mon, 16 Sep 2024 19:19:14 +0200 Subject: [PATCH 2/3] Keep explicit type --- .../Middleware/MultiTenantRequestServicesMiddleware.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Infrastructure/Middleware/MultiTenantRequestServicesMiddleware.cs b/src/Infrastructure/Middleware/MultiTenantRequestServicesMiddleware.cs index 25cc4cd..54e032b 100644 --- a/src/Infrastructure/Middleware/MultiTenantRequestServicesMiddleware.cs +++ b/src/Infrastructure/Middleware/MultiTenantRequestServicesMiddleware.cs @@ -27,7 +27,7 @@ public async Task Invoke(HttpContext context) httpContextAccessor.HttpContext ??= context; //Replace the service providers feature with our tenant specific one - var existingFeature = context.Features.Get()!; + IServiceProvidersFeature? existingFeature = context.Features.Get()!; try { context.Features.Set(new RequestServicesFeature(context, multiTenantServiceProviderScopeFactory)); From c0ff7e55ed0ad7d02922e261d440d836e8bfe980 Mon Sep 17 00:00:00 2001 From: Pierre Arnaud Date: Mon, 16 Sep 2024 19:20:35 +0200 Subject: [PATCH 3/3] Fix nullability --- .../Middleware/MultiTenantRequestServicesMiddleware.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Infrastructure/Middleware/MultiTenantRequestServicesMiddleware.cs b/src/Infrastructure/Middleware/MultiTenantRequestServicesMiddleware.cs index 54e032b..68283a8 100644 --- a/src/Infrastructure/Middleware/MultiTenantRequestServicesMiddleware.cs +++ b/src/Infrastructure/Middleware/MultiTenantRequestServicesMiddleware.cs @@ -27,7 +27,7 @@ public async Task Invoke(HttpContext context) httpContextAccessor.HttpContext ??= context; //Replace the service providers feature with our tenant specific one - IServiceProvidersFeature? existingFeature = context.Features.Get()!; + IServiceProvidersFeature? existingFeature = context.Features.Get(); try { context.Features.Set(new RequestServicesFeature(context, multiTenantServiceProviderScopeFactory));