From fc15de0aadbd33ad1ac73d44181809fbe0321675 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 12 Mar 2024 08:25:54 -0700 Subject: [PATCH 1/9] Fix typo. --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9f7aeb2..cfaad24 100644 --- a/.gitignore +++ b/.gitignore @@ -170,5 +170,5 @@ $RECYCLE.BIN/ # Mac crap .DS_Store -# Rider crap +# JetBrains Rider .idea From c0c67c89270090e20523c6772d26a9ade6d20212 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 12 Mar 2024 08:26:09 -0700 Subject: [PATCH 2/9] Semver 7 => 8 for Autofac breaking changes coming. --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 50d7063..ba0f70d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,9 +1,9 @@ image: Ubuntu -version: 7.0.0.{build} +version: 8.0.0.{build} dotnet_csproj: - version_prefix: "7.0.0" + version_prefix: "8.0.0" patch: true file: 'src\**\*.csproj' From 247e6e852b64024b6ab67b8247e3bc0c70b63c0e Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 12 Mar 2024 08:28:42 -0700 Subject: [PATCH 3/9] Added .NET 8 support, dropped .NET 3.1. --- global.json | 8 +++----- samples/Sandbox.Shared/Sandbox.Shared.csproj | 5 +++-- ...Autofac.Integration.AspNetCore.Multitenant.csproj | 11 +++-------- ...ac.Integration.AspNetCore.Multitenant.Test.csproj | 12 ++++++------ 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/global.json b/global.json index d4dc791..7840a58 100644 --- a/global.json +++ b/global.json @@ -1,12 +1,10 @@ { "sdk": { - "version": "7.0.203", + "version": "8.0.101", "rollForward": "latestFeature" }, - "additionalSdks": [ - "6.0.300", - "5.0.403", - "3.1.302" + "6.0.418", + "7.0.405" ] } diff --git a/samples/Sandbox.Shared/Sandbox.Shared.csproj b/samples/Sandbox.Shared/Sandbox.Shared.csproj index fbc5666..58526d5 100644 --- a/samples/Sandbox.Shared/Sandbox.Shared.csproj +++ b/samples/Sandbox.Shared/Sandbox.Shared.csproj @@ -1,13 +1,14 @@ - netcoreapp3.1 + net6.0 Sandbox - $(NoWarn);CA1848;CS1591;SA1600 true latest true + enable true ../../build/Analyzers.ruleset + true AllEnabledByDefault enable diff --git a/src/Autofac.Integration.AspNetCore.Multitenant/Autofac.Integration.AspNetCore.Multitenant.csproj b/src/Autofac.Integration.AspNetCore.Multitenant/Autofac.Integration.AspNetCore.Multitenant.csproj index 2232f19..dc4ca4d 100644 --- a/src/Autofac.Integration.AspNetCore.Multitenant/Autofac.Integration.AspNetCore.Multitenant.csproj +++ b/src/Autofac.Integration.AspNetCore.Multitenant/Autofac.Integration.AspNetCore.Multitenant.csproj @@ -15,10 +15,10 @@ true en-US - net7.0;net6.0;netcoreapp3.1 + net8.0;net7.0;net6.0 latest - enable true + enable true ../../build/Analyzers.ruleset true @@ -60,15 +60,10 @@ - - - - - - + all diff --git a/test/Autofac.Integration.AspNetCore.Multitenant.Test/Autofac.Integration.AspNetCore.Multitenant.Test.csproj b/test/Autofac.Integration.AspNetCore.Multitenant.Test/Autofac.Integration.AspNetCore.Multitenant.Test.csproj index aafde22..50d0a25 100644 --- a/test/Autofac.Integration.AspNetCore.Multitenant.Test/Autofac.Integration.AspNetCore.Multitenant.Test.csproj +++ b/test/Autofac.Integration.AspNetCore.Multitenant.Test/Autofac.Integration.AspNetCore.Multitenant.Test.csproj @@ -1,7 +1,7 @@  - net7.0;net6.0;netcoreapp3.1; + net8.0;net7.0;net6.0 $(NoWarn);CS1591 true ../../Autofac.snk @@ -55,6 +55,11 @@ + + + + + @@ -65,9 +70,4 @@ - - - - - From e14d5145716aa012cb8c17dd68fec9e8106cc3ca Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 12 Mar 2024 08:28:56 -0700 Subject: [PATCH 4/9] Use C# dev kit. --- .vscode/extensions.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 5710952..ca1fb63 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -2,8 +2,7 @@ "recommendations": [ "davidanson.vscode-markdownlint", "editorconfig.editorconfig", - "formulahendry.dotnet-test-explorer", - "ms-dotnettools.csharp", + "ms-dotnettools.csdevkit", "stkb.rewrap" ] } From f6d74ba217bb224c0391116ade7ca80dde1712f6 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 12 Mar 2024 08:29:55 -0700 Subject: [PATCH 5/9] Sandbox app targets a single framework to make it easier to add/update support. --- .vscode/launch.json | 20 +------ Autofac.AspNetCore.Multitenant.sln | 9 +--- samples/Sandbox.AspNetCore3_To_3_1/Program.cs | 23 -------- .../Properties/AssemblyInfo.cs | 8 --- .../Properties/launchSettings.json | 14 ----- .../Sandbox.AspNetCore3_To_3_1.csproj | 28 ---------- samples/Sandbox.AspNetCore3_To_3_1/Startup.cs | 33 ------------ .../appsettings.Development.json | 10 ---- .../appsettings.json | 8 --- samples/Sandbox.AspNetCore5_To_7/Program.cs | 17 ------ samples/Sandbox.AspNetCore5_To_7/Startup.cs | 28 ---------- samples/Sandbox.AspNetCore6/Program.cs | 32 ++++++++++++ .../Properties/AssemblyInfo.cs | 0 .../Properties/launchSettings.json | 0 .../Sandbox.AspNetCore6.csproj} | 4 +- samples/Sandbox.AspNetCore6/Startup.cs | 51 ++++++++++++++++++ .../appsettings.Development.json | 0 .../appsettings.json | 0 samples/Sandbox.Shared/ContainerSetup.cs | 52 ++++++++++++++++++- samples/Sandbox.Shared/Dependency.cs | 43 ++++++++------- samples/Sandbox.Shared/IDependency.cs | 10 ++++ .../MultitenantContainerSetup.cs | 38 -------------- ...QueryStringTenantIdentificationStrategy.cs | 37 ++++++++++--- samples/Sandbox.Shared/ValuesController.cs | 27 +++++++++- 24 files changed, 230 insertions(+), 262 deletions(-) delete mode 100644 samples/Sandbox.AspNetCore3_To_3_1/Program.cs delete mode 100644 samples/Sandbox.AspNetCore3_To_3_1/Properties/AssemblyInfo.cs delete mode 100644 samples/Sandbox.AspNetCore3_To_3_1/Properties/launchSettings.json delete mode 100644 samples/Sandbox.AspNetCore3_To_3_1/Sandbox.AspNetCore3_To_3_1.csproj delete mode 100644 samples/Sandbox.AspNetCore3_To_3_1/Startup.cs delete mode 100644 samples/Sandbox.AspNetCore3_To_3_1/appsettings.Development.json delete mode 100644 samples/Sandbox.AspNetCore3_To_3_1/appsettings.json delete mode 100644 samples/Sandbox.AspNetCore5_To_7/Program.cs delete mode 100644 samples/Sandbox.AspNetCore5_To_7/Startup.cs create mode 100644 samples/Sandbox.AspNetCore6/Program.cs rename samples/{Sandbox.AspNetCore5_To_7 => Sandbox.AspNetCore6}/Properties/AssemblyInfo.cs (100%) rename samples/{Sandbox.AspNetCore5_To_7 => Sandbox.AspNetCore6}/Properties/launchSettings.json (100%) rename samples/{Sandbox.AspNetCore5_To_7/Sandbox.AspNetCore5_To_7.csproj => Sandbox.AspNetCore6/Sandbox.AspNetCore6.csproj} (90%) create mode 100644 samples/Sandbox.AspNetCore6/Startup.cs rename samples/{Sandbox.AspNetCore5_To_7 => Sandbox.AspNetCore6}/appsettings.Development.json (100%) rename samples/{Sandbox.AspNetCore5_To_7 => Sandbox.AspNetCore6}/appsettings.json (100%) delete mode 100644 samples/Sandbox.Shared/MultitenantContainerSetup.cs diff --git a/.vscode/launch.json b/.vscode/launch.json index f3c557e..0f5fd5e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,25 +9,9 @@ "launchBrowser": { "enabled": false }, - "name": "Sandbox 2-3.1", + "name": "Sandbox 6", "preLaunchTask": "build", - "program": "${workspaceFolder}/samples/Sandbox.AspNetCore3_To_3_1/bin/Debug/netcoreapp3.1/Sandbox.AspNetCore3_To_3_1.dll", - "request": "launch", - "stopAtEntry": false, - "type": "coreclr" - }, - { - "cwd": "${workspaceFolder}", - "env": { - "ASPNETCORE_ENVIRONMENT": "Development", - "ASPNETCORE_URLS": "http://localhost:5555" - }, - "launchBrowser": { - "enabled": false - }, - "name": "Sandbox 5-6", - "preLaunchTask": "build", - "program": "${workspaceFolder}/samples/Sandbox.AspNetCore5_To_6/bin/Debug/net6.0/Sandbox.AspNetCore5_To_6.dll", + "program": "${workspaceFolder}/samples/Sandbox.AspNetCore6/bin/Debug/net6.0/Sandbox.AspNetCore6.dll", "request": "launch", "stopAtEntry": false, "type": "coreclr" diff --git a/Autofac.AspNetCore.Multitenant.sln b/Autofac.AspNetCore.Multitenant.sln index 115179f..d9712c1 100644 --- a/Autofac.AspNetCore.Multitenant.sln +++ b/Autofac.AspNetCore.Multitenant.sln @@ -19,8 +19,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution codecov.yml = codecov.yml EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sandbox.AspNetCore3_To_3_1", "samples\Sandbox.AspNetCore3_To_3_1\Sandbox.AspNetCore3_To_3_1.csproj", "{12445470-D348-467F-8D3F-FBD6EF525CEE}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8C9BBEEC-0C4B-4ECD-B927-63899C265FB4}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{5227B99C-6D0F-4E7B-9DF8-82C53488E173}" @@ -39,7 +37,7 @@ ProjectSection(SolutionItems) = preProject build\stylecop.json = build\stylecop.json EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sandbox.AspNetCore5_To_7", "samples\Sandbox.AspNetCore5_To_7\Sandbox.AspNetCore5_To_7.csproj", "{B64B6D62-AD07-49BE-AF65-3E4C92284AD5}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sandbox.AspNetCore6", "samples\Sandbox.AspNetCore6\Sandbox.AspNetCore6.csproj", "{B64B6D62-AD07-49BE-AF65-3E4C92284AD5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -55,10 +53,6 @@ Global {BA923A91-3A4B-40CE-8788-70A641694945}.Debug|Any CPU.Build.0 = Debug|Any CPU {BA923A91-3A4B-40CE-8788-70A641694945}.Release|Any CPU.ActiveCfg = Release|Any CPU {BA923A91-3A4B-40CE-8788-70A641694945}.Release|Any CPU.Build.0 = Release|Any CPU - {12445470-D348-467F-8D3F-FBD6EF525CEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {12445470-D348-467F-8D3F-FBD6EF525CEE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {12445470-D348-467F-8D3F-FBD6EF525CEE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {12445470-D348-467F-8D3F-FBD6EF525CEE}.Release|Any CPU.Build.0 = Release|Any CPU {C1C581D6-57C2-4448-BF83-59C39CED7ABC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C1C581D6-57C2-4448-BF83-59C39CED7ABC}.Debug|Any CPU.Build.0 = Debug|Any CPU {C1C581D6-57C2-4448-BF83-59C39CED7ABC}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -74,7 +68,6 @@ Global GlobalSection(NestedProjects) = preSolution {241CD558-86C8-493B-9FA1-D913167D527C} = {8C9BBEEC-0C4B-4ECD-B927-63899C265FB4} {BA923A91-3A4B-40CE-8788-70A641694945} = {5227B99C-6D0F-4E7B-9DF8-82C53488E173} - {12445470-D348-467F-8D3F-FBD6EF525CEE} = {BD3275CD-8B4C-4CEA-8DDB-BEF386DD48B5} {C1C581D6-57C2-4448-BF83-59C39CED7ABC} = {BD3275CD-8B4C-4CEA-8DDB-BEF386DD48B5} {B64B6D62-AD07-49BE-AF65-3E4C92284AD5} = {BD3275CD-8B4C-4CEA-8DDB-BEF386DD48B5} EndGlobalSection diff --git a/samples/Sandbox.AspNetCore3_To_3_1/Program.cs b/samples/Sandbox.AspNetCore3_To_3_1/Program.cs deleted file mode 100644 index f9f5dca..0000000 --- a/samples/Sandbox.AspNetCore3_To_3_1/Program.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) Autofac Project. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Hosting; - -namespace Sandbox; - -public static class Program -{ - public static async Task Main(string[] args) - { - var host = Host.CreateDefaultBuilder(args) - .UseServiceProviderFactory( - new AutofacMultitenantServiceProviderFactory( - MultitenantContainerSetup.ConfigureMultitenantContainer)) - .ConfigureWebHostDefaults(webHostBuilder => webHostBuilder.UseStartup()) - .Build(); - - await host.RunAsync(); - } -} diff --git a/samples/Sandbox.AspNetCore3_To_3_1/Properties/AssemblyInfo.cs b/samples/Sandbox.AspNetCore3_To_3_1/Properties/AssemblyInfo.cs deleted file mode 100644 index 58e399b..0000000 --- a/samples/Sandbox.AspNetCore3_To_3_1/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) Autofac Project. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using System; -using System.Runtime.InteropServices; - -[assembly: CLSCompliant(false)] -[assembly: ComVisible(false)] diff --git a/samples/Sandbox.AspNetCore3_To_3_1/Properties/launchSettings.json b/samples/Sandbox.AspNetCore3_To_3_1/Properties/launchSettings.json deleted file mode 100644 index 3e88659..0000000 --- a/samples/Sandbox.AspNetCore3_To_3_1/Properties/launchSettings.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/launchsettings.json", - "profiles": { - "Sandbox.Sandbox.AspNetCore3_To_3_1": { - "applicationUrl": "http://localhost:5555", - "commandName": "Project", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "launchBrowser": true, - "launchUrl": "api/values" - } - } -} diff --git a/samples/Sandbox.AspNetCore3_To_3_1/Sandbox.AspNetCore3_To_3_1.csproj b/samples/Sandbox.AspNetCore3_To_3_1/Sandbox.AspNetCore3_To_3_1.csproj deleted file mode 100644 index d44968c..0000000 --- a/samples/Sandbox.AspNetCore3_To_3_1/Sandbox.AspNetCore3_To_3_1.csproj +++ /dev/null @@ -1,28 +0,0 @@ - - - netcoreapp3.1 - Sandbox - $(NoWarn);CA1707;CA1848;CS1591;SA1600 - true - latest - true - true - ../../build/Analyzers.ruleset - true - AllEnabledByDefault - - - - - All - - - - - - - - - - - diff --git a/samples/Sandbox.AspNetCore3_To_3_1/Startup.cs b/samples/Sandbox.AspNetCore3_To_3_1/Startup.cs deleted file mode 100644 index 0016b32..0000000 --- a/samples/Sandbox.AspNetCore3_To_3_1/Startup.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) Autofac Project. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using Autofac; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.DependencyInjection; - -namespace Sandbox; - -public class Startup -{ - public void ConfigureServices(IServiceCollection services) - { - services - .AddAutofacMultitenantRequestServices() - .AddControllers() - .SetCompatibilityVersion(CompatibilityVersion.Version_3_0); - } - - public void ConfigureContainer(ContainerBuilder builder) - { - ContainerSetup.SetupContainer(builder); - } - - public void Configure(IApplicationBuilder app) - { - app.UseRouting(); - - app.UseEndpoints(builder => builder.MapControllers()); - } -} diff --git a/samples/Sandbox.AspNetCore3_To_3_1/appsettings.Development.json b/samples/Sandbox.AspNetCore3_To_3_1/appsettings.Development.json deleted file mode 100644 index a694187..0000000 --- a/samples/Sandbox.AspNetCore3_To_3_1/appsettings.Development.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "Logging": { - "IncludeScopes": false, - "LogLevel": { - "Default": "Debug", - "System": "Warning", - "Microsoft": "Warning" - } - } -} diff --git a/samples/Sandbox.AspNetCore3_To_3_1/appsettings.json b/samples/Sandbox.AspNetCore3_To_3_1/appsettings.json deleted file mode 100644 index 5fff67b..0000000 --- a/samples/Sandbox.AspNetCore3_To_3_1/appsettings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "IncludeScopes": false, - "LogLevel": { - "Default": "Warning" - } - } -} diff --git a/samples/Sandbox.AspNetCore5_To_7/Program.cs b/samples/Sandbox.AspNetCore5_To_7/Program.cs deleted file mode 100644 index b7d7fec..0000000 --- a/samples/Sandbox.AspNetCore5_To_7/Program.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) Autofac Project. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -namespace Sandbox; - -public static class Program -{ - public static async Task Main(string[] args) - { - var host = Host.CreateDefaultBuilder(args) - .UseServiceProviderFactory(new AutofacMultitenantServiceProviderFactory(MultitenantContainerSetup.ConfigureMultitenantContainer)) - .ConfigureWebHostDefaults(webHostBuilder => webHostBuilder.UseStartup()) - .Build(); - - await host.RunAsync(); - } -} diff --git a/samples/Sandbox.AspNetCore5_To_7/Startup.cs b/samples/Sandbox.AspNetCore5_To_7/Startup.cs deleted file mode 100644 index 5daa63a..0000000 --- a/samples/Sandbox.AspNetCore5_To_7/Startup.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Autofac Project. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using Autofac; - -namespace Sandbox; - -public class Startup -{ - public void ConfigureServices(IServiceCollection services) - { - services - .AddAutofacMultitenantRequestServices() - .AddControllers(); - } - - public void ConfigureContainer(ContainerBuilder builder) - { - ContainerSetup.SetupContainer(builder); - } - - public void Configure(IApplicationBuilder app) - { - app.UseRouting(); - - app.UseEndpoints(builder => builder.MapControllers()); - } -} diff --git a/samples/Sandbox.AspNetCore6/Program.cs b/samples/Sandbox.AspNetCore6/Program.cs new file mode 100644 index 0000000..e6a8739 --- /dev/null +++ b/samples/Sandbox.AspNetCore6/Program.cs @@ -0,0 +1,32 @@ +// Copyright (c) Autofac Project. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace Sandbox; + +/// +/// Entry pont for the ASP.NET sandbox application. +/// +public static class Program +{ + /// + /// Primary method for execution of the sandbox application. + /// + /// + /// The set of command line arguments provided to the application. + /// + /// + /// A to await completion of the host execution. + /// + public static async Task Main(string[] args) + { + // Note the AutofacMultitenantServiceProviderFactory takes the method + // that configures the tenant-specific overrides. That doesn't show up + // in your Startup class. + var host = Host.CreateDefaultBuilder(args) + .UseServiceProviderFactory(new AutofacMultitenantServiceProviderFactory(ContainerSetup.ConfigureMultitenantContainer)) + .ConfigureWebHostDefaults(webHostBuilder => webHostBuilder.UseStartup()) + .Build(); + + await host.RunAsync(); + } +} diff --git a/samples/Sandbox.AspNetCore5_To_7/Properties/AssemblyInfo.cs b/samples/Sandbox.AspNetCore6/Properties/AssemblyInfo.cs similarity index 100% rename from samples/Sandbox.AspNetCore5_To_7/Properties/AssemblyInfo.cs rename to samples/Sandbox.AspNetCore6/Properties/AssemblyInfo.cs diff --git a/samples/Sandbox.AspNetCore5_To_7/Properties/launchSettings.json b/samples/Sandbox.AspNetCore6/Properties/launchSettings.json similarity index 100% rename from samples/Sandbox.AspNetCore5_To_7/Properties/launchSettings.json rename to samples/Sandbox.AspNetCore6/Properties/launchSettings.json diff --git a/samples/Sandbox.AspNetCore5_To_7/Sandbox.AspNetCore5_To_7.csproj b/samples/Sandbox.AspNetCore6/Sandbox.AspNetCore6.csproj similarity index 90% rename from samples/Sandbox.AspNetCore5_To_7/Sandbox.AspNetCore5_To_7.csproj rename to samples/Sandbox.AspNetCore6/Sandbox.AspNetCore6.csproj index 5da1d63..0aa64c4 100644 --- a/samples/Sandbox.AspNetCore5_To_7/Sandbox.AspNetCore5_To_7.csproj +++ b/samples/Sandbox.AspNetCore6/Sandbox.AspNetCore6.csproj @@ -1,11 +1,11 @@  - net7.0 + net6.0 Sandbox - $(NoWarn);CA1707;CA1848;CS1591;SA1600 true latest true + enable true ../../build/Analyzers.ruleset true diff --git a/samples/Sandbox.AspNetCore6/Startup.cs b/samples/Sandbox.AspNetCore6/Startup.cs new file mode 100644 index 0000000..eab4a28 --- /dev/null +++ b/samples/Sandbox.AspNetCore6/Startup.cs @@ -0,0 +1,51 @@ +// Copyright (c) Autofac Project. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using Autofac; + +namespace Sandbox; + +/// +/// Startup logic for the sandbox application. +/// +public class Startup +{ + /// + /// Configures default services using the standard Microsoft container. + /// + /// + /// The into which registrations will be made. + /// + public void ConfigureServices(IServiceCollection services) + { + services + .AddAutofacMultitenantRequestServices() + .AddControllers(); + } + + /// + /// Configures default services that override standard Microsoft services. This method is called after but before multitenant overrides occur. + /// + /// + /// The Autofac into which default registrations will occur. + /// + public void ConfigureContainer(ContainerBuilder builder) + { + // Note the multitenant registrations aren't here! They're in + // Program.cs, and they're passed into the + // AutofacMultitenantServiceProviderFactory. + ContainerSetup.ConfigureContainer(builder); + } + + /// + /// Configures the pipeline for the sandbox application. + /// + /// + /// The with which the pipeline is being built. + /// + public void Configure(IApplicationBuilder app) + { + app.UseRouting(); + app.UseEndpoints(builder => builder.MapControllers()); + } +} diff --git a/samples/Sandbox.AspNetCore5_To_7/appsettings.Development.json b/samples/Sandbox.AspNetCore6/appsettings.Development.json similarity index 100% rename from samples/Sandbox.AspNetCore5_To_7/appsettings.Development.json rename to samples/Sandbox.AspNetCore6/appsettings.Development.json diff --git a/samples/Sandbox.AspNetCore5_To_7/appsettings.json b/samples/Sandbox.AspNetCore6/appsettings.json similarity index 100% rename from samples/Sandbox.AspNetCore5_To_7/appsettings.json rename to samples/Sandbox.AspNetCore6/appsettings.json diff --git a/samples/Sandbox.Shared/ContainerSetup.cs b/samples/Sandbox.Shared/ContainerSetup.cs index d3e5a8c..a1be8f8 100644 --- a/samples/Sandbox.Shared/ContainerSetup.cs +++ b/samples/Sandbox.Shared/ContainerSetup.cs @@ -2,16 +2,66 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. using Autofac; +using Autofac.Multitenant; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; namespace Sandbox; +/// +/// Common methods used to set up the default and multitenant container registrations in the sandbox projects. +/// public static class ContainerSetup { - public static void SetupContainer(ContainerBuilder builder) + /// + /// Configures the container with default dependencies. These can be + /// overridden by multitenant registrations. + /// + /// + /// The with which registrations are being + /// added. + /// + public static void ConfigureContainer(ContainerBuilder builder) { builder.RegisterType() .As() .WithProperty("Id", "base") .InstancePerLifetimeScope(); } + + /// + /// Configures tenant-specific overrides for the multitenant container. + /// + /// + /// The container supplying base dependency registrations that will be + /// overridden by tenant-specific registrations. + /// + /// + /// A multitenant container with two tenants configured. + /// + public static MultitenantContainer ConfigureMultitenantContainer(IContainer container) + { + var strategy = new QueryStringTenantIdentificationStrategy( + container.Resolve(), + container.Resolve>()); + + var multitenantContainer = new MultitenantContainer(strategy, container); + + multitenantContainer.ConfigureTenant( + "a", + cb => cb + .RegisterType() + .As() + .WithProperty("Id", "a") + .InstancePerLifetimeScope()); + multitenantContainer.ConfigureTenant( + "b", + cb => cb + .RegisterType() + .As() + .WithProperty("Id", "b") + .InstancePerLifetimeScope()); + + return multitenantContainer; + } } diff --git a/samples/Sandbox.Shared/Dependency.cs b/samples/Sandbox.Shared/Dependency.cs index 3fc55d2..a02c39d 100644 --- a/samples/Sandbox.Shared/Dependency.cs +++ b/samples/Sandbox.Shared/Dependency.cs @@ -5,35 +5,42 @@ namespace Sandbox; -public class Dependency : IDependency, IDisposable +/// +/// Simple dependency used to illustrate multitenant overrides. +/// +public sealed class Dependency : IDependency, IDisposable { + private static readonly Action LogDisposal = LoggerMessage.Define(LogLevel.Information, new EventId(0), "Disposing dependency '{Id}'."); + private readonly ILogger _logger; - private bool _disposedValue; + /// + /// Initializes a new instance of the class. + /// + /// + /// The logger to use for diagnostic messages. + /// public Dependency(ILogger logger) { _logger = logger; + Id = ""; } + /// + /// Gets or sets a unique identifier for the component. + /// + /// + /// A that can be used to illustrate which dependency + /// is being resolved by a given tenant. + /// public string Id { get; set; } + /// + /// Disposes the component. This will be called when the owning lifetime + /// scope is disposed. + /// public void Dispose() { - // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - Dispose(disposing: true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (!_disposedValue) - { - if (disposing) - { - _logger.LogInformation("Disposing dependency '{Id}'.", Id); - } - - _disposedValue = true; - } + LogDisposal(_logger, Id, null); } } diff --git a/samples/Sandbox.Shared/IDependency.cs b/samples/Sandbox.Shared/IDependency.cs index 74276b5..29b50b3 100644 --- a/samples/Sandbox.Shared/IDependency.cs +++ b/samples/Sandbox.Shared/IDependency.cs @@ -3,7 +3,17 @@ namespace Sandbox; +/// +/// Simple dependency interface to provide a way to differentiate between components. +/// public interface IDependency { + /// + /// Gets a unique identifier for the component. + /// + /// + /// A that can be used to illustrate which dependency + /// is being resolved by a given tenant. + /// string Id { get; } } diff --git a/samples/Sandbox.Shared/MultitenantContainerSetup.cs b/samples/Sandbox.Shared/MultitenantContainerSetup.cs deleted file mode 100644 index 8609834..0000000 --- a/samples/Sandbox.Shared/MultitenantContainerSetup.cs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) Autofac Project. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using Autofac; -using Autofac.Multitenant; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Logging; - -namespace Sandbox; - -public static class MultitenantContainerSetup -{ - public static MultitenantContainer ConfigureMultitenantContainer(IContainer container) - { - var strategy = new QueryStringTenantIdentificationStrategy( - container.Resolve(), - container.Resolve>()); - - var multitenantContainer = new MultitenantContainer(strategy, container); - - multitenantContainer.ConfigureTenant( - "a", - cb => cb - .RegisterType() - .As() - .WithProperty("Id", "a") - .InstancePerLifetimeScope()); - multitenantContainer.ConfigureTenant( - "b", - cb => cb - .RegisterType() - .As() - .WithProperty("Id", "b") - .InstancePerLifetimeScope()); - - return multitenantContainer; - } -} diff --git a/samples/Sandbox.Shared/QueryStringTenantIdentificationStrategy.cs b/samples/Sandbox.Shared/QueryStringTenantIdentificationStrategy.cs index 3f7b4a3..52ffd6b 100644 --- a/samples/Sandbox.Shared/QueryStringTenantIdentificationStrategy.cs +++ b/samples/Sandbox.Shared/QueryStringTenantIdentificationStrategy.cs @@ -8,21 +8,44 @@ namespace Sandbox; +/// +/// Tenant identification strategy that uses a query string parameter to determine the current tenant. +/// public class QueryStringTenantIdentificationStrategy : ITenantIdentificationStrategy { + private static readonly Action LogTenantIdentified = LoggerMessage.Define(LogLevel.Information, new EventId(0), "Identified tenant: {Tenant}"); + private static readonly Action LogNoTenantIdentity = LoggerMessage.Define(LogLevel.Warning, new EventId(1), "Unable to identify tenant from query string. Falling back to default."); private readonly ILogger _logger; + private readonly IHttpContextAccessor _accessor; + /// + /// Initializes a new instance of the class. + /// + /// + /// An that can provide the current request context. + /// + /// + /// The logger for diagnostic messages. + /// public QueryStringTenantIdentificationStrategy(IHttpContextAccessor accessor, ILogger logger) { - Accessor = accessor; + _accessor = accessor; _logger = logger; } - public IHttpContextAccessor Accessor { get; private set; } - - public bool TryIdentifyTenant(out object tenantId) + /// + /// Attempts to identify the tenant from the current request query string. + /// + /// + /// The current tenant identifier. + /// + /// + /// if the tenant could be identified; + /// if not. + /// + public bool TryIdentifyTenant(out object? tenantId) { - var context = Accessor.HttpContext; + var context = _accessor.HttpContext; if (context == null) { // No current HttpContext. This happens during app startup @@ -46,11 +69,11 @@ public bool TryIdentifyTenant(out object tenantId) { tenantId = tenantValues[0]; context.Items["_tenantId"] = tenantId; - _logger.LogInformation("Identified tenant: {Tenant}", tenantId); + LogTenantIdentified(_logger, tenantId, null); return true; } - _logger.LogWarning("Unable to identify tenant from query string. Falling back to default."); + LogNoTenantIdentity(_logger, null); tenantId = null; context.Items["_tenantId"] = null; return false; diff --git a/samples/Sandbox.Shared/ValuesController.cs b/samples/Sandbox.Shared/ValuesController.cs index 9603b17..9a79f0b 100644 --- a/samples/Sandbox.Shared/ValuesController.cs +++ b/samples/Sandbox.Shared/ValuesController.cs @@ -5,17 +5,42 @@ namespace Sandbox; +/// +/// API controller allowing a dependency to be resolved to illustrate multitenant dependency support. +/// [ApiController] [Route("api/[controller]")] public class ValuesController : ControllerBase { + /// + /// Initializes a new instance of the class. + /// + /// + /// The that will be returned in the GET method of the controller. + /// public ValuesController(IDependency dependency) { Dependency = dependency; } - public IDependency Dependency { get; set; } + /// + /// Gets the tenant-specific resolved dependency. + /// + /// + /// An that will have been resolved from a + /// tenant-specific lifetime scope based on the tenant query string + /// parameter. + /// + public IDependency Dependency { get; } + /// + /// Gets the ID of the resolved dependency. + /// + /// + /// The for the dependency that was resolved + /// for the tenant. Change the tenant query string parameter to get + /// the value for different tenants. + /// [HttpGet] public string Get() { From ba9563de50cab83e3e92d2c0e819d5fb69538999 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 12 Mar 2024 08:30:13 -0700 Subject: [PATCH 6/9] Fix analyzer warnings. --- .../AutofacMultitenantServiceCollectionExtensions.cs | 7 +------ .../AutofacMultitenantServiceProviderFactory.cs | 5 +---- .../AutofacMultitenantWebHostBuilderExtensions.cs | 6 +----- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantServiceCollectionExtensions.cs b/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantServiceCollectionExtensions.cs index 0a4dcc6..ad64a3c 100644 --- a/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantServiceCollectionExtensions.cs +++ b/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantServiceCollectionExtensions.cs @@ -24,14 +24,9 @@ public static class AutofacMultitenantServiceCollectionExtensions /// public static IServiceCollection AddAutofacMultitenantRequestServices(this IServiceCollection services) { - if (services == null) - { - throw new ArgumentNullException(nameof(services)); - } - + ArgumentNullException.ThrowIfNull(services); services.Insert(0, ServiceDescriptor.Transient(provider => new MultitenantRequestServicesStartupFilter())); services.AddSingleton(); - return services; } } diff --git a/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantServiceProviderFactory.cs b/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantServiceProviderFactory.cs index abcfa45..23adcad 100644 --- a/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantServiceProviderFactory.cs +++ b/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantServiceProviderFactory.cs @@ -54,10 +54,7 @@ public ContainerBuilder CreateBuilder(IServiceCollection services) /// An . public IServiceProvider CreateServiceProvider(ContainerBuilder containerBuilder) { - if (containerBuilder == null) - { - throw new ArgumentNullException(nameof(containerBuilder)); - } + ArgumentNullException.ThrowIfNull(containerBuilder); MultitenantContainer multitenantContainer = null!; diff --git a/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantWebHostBuilderExtensions.cs b/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantWebHostBuilderExtensions.cs index 91a1922..80a8e57 100644 --- a/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantWebHostBuilderExtensions.cs +++ b/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantWebHostBuilderExtensions.cs @@ -20,11 +20,7 @@ public static class AutofacMultitenantWebHostBuilderExtensions /// public static IWebHostBuilder UseAutofacMultitenantRequestServices(this IWebHostBuilder builder) { - if (builder == null) - { - throw new ArgumentNullException(nameof(builder)); - } - + ArgumentNullException.ThrowIfNull(builder); return builder.ConfigureServices(services => { services.AddAutofacMultitenantRequestServices(); From a8a998db13de3014249b7363e3c4feb1d5ffc40c Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 12 Mar 2024 08:33:58 -0700 Subject: [PATCH 7/9] Correct analyzer issues. --- .../MultitenantRequestServicesMiddlewareTests.cs | 6 +++--- .../TestDependencies/TenantAccessorDependency.cs | 6 +----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/test/Autofac.Integration.AspNetCore.Multitenant.Test/MultitenantRequestServicesMiddlewareTests.cs b/test/Autofac.Integration.AspNetCore.Multitenant.Test/MultitenantRequestServicesMiddlewareTests.cs index 0523d41..4809f12 100644 --- a/test/Autofac.Integration.AspNetCore.Multitenant.Test/MultitenantRequestServicesMiddlewareTests.cs +++ b/test/Autofac.Integration.AspNetCore.Multitenant.Test/MultitenantRequestServicesMiddlewareTests.cs @@ -17,7 +17,7 @@ public async Task Invoke_DoesNotOverrideExistingHttpContextOnAccessor() { var accessor = Mock.Of(); accessor.HttpContext = new DefaultHttpContext(); - var next = new RequestDelegate(ctx => Task.FromResult(0)); + var next = new RequestDelegate(ctx => Task.CompletedTask); var context = CreateContext(); var mtc = CreateServiceProvider().GetRequiredService(); @@ -38,7 +38,7 @@ public async Task Invoke_ReplacesRequestServices() // an updated request services feature. var currentFeature = ctx.Features.Get(); Assert.NotSame(originalFeature, currentFeature); - return Task.FromResult(0); + return Task.CompletedTask; }); var context = CreateContext(); context.Features.Set(originalFeature); @@ -57,7 +57,7 @@ public async Task Invoke_ReplacesRequestServices() public async Task Invoke_SetsHttpContextOnAccessor() { var accessor = Mock.Of(); - var next = new RequestDelegate(ctx => Task.FromResult(0)); + var next = new RequestDelegate(ctx => Task.CompletedTask); var context = CreateContext(); var mtc = CreateServiceProvider().GetRequiredService(); var mw = new MultitenantRequestServicesMiddleware(next, accessor, mtc); diff --git a/test/Autofac.Integration.AspNetCore.Multitenant.Test/TestDependencies/TenantAccessorDependency.cs b/test/Autofac.Integration.AspNetCore.Multitenant.Test/TestDependencies/TenantAccessorDependency.cs index e85944d..658c384 100644 --- a/test/Autofac.Integration.AspNetCore.Multitenant.Test/TestDependencies/TenantAccessorDependency.cs +++ b/test/Autofac.Integration.AspNetCore.Multitenant.Test/TestDependencies/TenantAccessorDependency.cs @@ -9,11 +9,7 @@ public sealed class TenantAccessorDependency : ITenantAccessor { public TenantAccessorDependency(ITenantIdentificationStrategy tenantIdentificationStrategy) { - if (tenantIdentificationStrategy == null) - { - throw new ArgumentNullException(nameof(tenantIdentificationStrategy)); - } - + ArgumentNullException.ThrowIfNull(tenantIdentificationStrategy); if (tenantIdentificationStrategy.TryIdentifyTenant(out var tenantId) && tenantId is string currentTenant) { From 6aa45f45dd8c6527a2be9a256d2a3cbace163686 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 12 Mar 2024 10:56:33 -0700 Subject: [PATCH 8/9] Update dependencies - AEDI => 9.0.0; A.M => 8.0.2 --- .../Sandbox.AspNetCore6.csproj | 4 ++-- samples/Sandbox.Shared/Sandbox.Shared.csproj | 4 ++-- ....Integration.AspNetCore.Multitenant.csproj | 6 ++--- ...gration.AspNetCore.Multitenant.Test.csproj | 24 +++++++++---------- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/samples/Sandbox.AspNetCore6/Sandbox.AspNetCore6.csproj b/samples/Sandbox.AspNetCore6/Sandbox.AspNetCore6.csproj index 0aa64c4..7e97816 100644 --- a/samples/Sandbox.AspNetCore6/Sandbox.AspNetCore6.csproj +++ b/samples/Sandbox.AspNetCore6/Sandbox.AspNetCore6.csproj @@ -14,8 +14,8 @@ - - All + + all diff --git a/samples/Sandbox.Shared/Sandbox.Shared.csproj b/samples/Sandbox.Shared/Sandbox.Shared.csproj index 58526d5..60d0f6a 100644 --- a/samples/Sandbox.Shared/Sandbox.Shared.csproj +++ b/samples/Sandbox.Shared/Sandbox.Shared.csproj @@ -15,8 +15,8 @@ - - All + + all diff --git a/src/Autofac.Integration.AspNetCore.Multitenant/Autofac.Integration.AspNetCore.Multitenant.csproj b/src/Autofac.Integration.AspNetCore.Multitenant/Autofac.Integration.AspNetCore.Multitenant.csproj index dc4ca4d..dbffb77 100644 --- a/src/Autofac.Integration.AspNetCore.Multitenant/Autofac.Integration.AspNetCore.Multitenant.csproj +++ b/src/Autofac.Integration.AspNetCore.Multitenant/Autofac.Integration.AspNetCore.Multitenant.csproj @@ -61,12 +61,12 @@ - - + + all - + all diff --git a/test/Autofac.Integration.AspNetCore.Multitenant.Test/Autofac.Integration.AspNetCore.Multitenant.Test.csproj b/test/Autofac.Integration.AspNetCore.Multitenant.Test/Autofac.Integration.AspNetCore.Multitenant.Test.csproj index 50d0a25..eeb5cbb 100644 --- a/test/Autofac.Integration.AspNetCore.Multitenant.Test/Autofac.Integration.AspNetCore.Multitenant.Test.csproj +++ b/test/Autofac.Integration.AspNetCore.Multitenant.Test/Autofac.Integration.AspNetCore.Multitenant.Test.csproj @@ -35,39 +35,37 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + + all - - + + all runtime; build; native; contentfiles; analyzers - - + - - + - - + From 5e8dc65578959d449920e3d5e572740d74a6f9ab Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 12 Mar 2024 11:12:49 -0700 Subject: [PATCH 9/9] Switch to NSubstitute. --- ...tegration.AspNetCore.Multitenant.Test.csproj | 4 ++-- ...cMultitenantWebHostBuilderExtensionsTests.cs | 17 ++++++----------- ...MultitenantRequestServicesMiddlewareTests.cs | 15 ++++++++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/test/Autofac.Integration.AspNetCore.Multitenant.Test/Autofac.Integration.AspNetCore.Multitenant.Test.csproj b/test/Autofac.Integration.AspNetCore.Multitenant.Test/Autofac.Integration.AspNetCore.Multitenant.Test.csproj index eeb5cbb..54e1145 100644 --- a/test/Autofac.Integration.AspNetCore.Multitenant.Test/Autofac.Integration.AspNetCore.Multitenant.Test.csproj +++ b/test/Autofac.Integration.AspNetCore.Multitenant.Test/Autofac.Integration.AspNetCore.Multitenant.Test.csproj @@ -16,7 +16,7 @@ - + @@ -45,7 +45,7 @@ - + all diff --git a/test/Autofac.Integration.AspNetCore.Multitenant.Test/AutofacMultitenantWebHostBuilderExtensionsTests.cs b/test/Autofac.Integration.AspNetCore.Multitenant.Test/AutofacMultitenantWebHostBuilderExtensionsTests.cs index b81ddfe..86f0cfb 100644 --- a/test/Autofac.Integration.AspNetCore.Multitenant.Test/AutofacMultitenantWebHostBuilderExtensionsTests.cs +++ b/test/Autofac.Integration.AspNetCore.Multitenant.Test/AutofacMultitenantWebHostBuilderExtensionsTests.cs @@ -12,14 +12,11 @@ public class AutofacMultitenantWebHostBuilderExtensionsTests [Fact] public void UseAutofacMultitenantRequestServices_AddsHttpContextAccessor() { - var webHostBuilder = new Mock(); + var webHostBuilder = Substitute.For(); var services = new ServiceCollection(); - webHostBuilder - .Setup(x => x.ConfigureServices(It.IsAny>())) - .Callback>(s => s(services)); - - webHostBuilder.Object.UseAutofacMultitenantRequestServices(); + webHostBuilder.ConfigureServices(Arg.Do>(s => s(services))); + webHostBuilder.UseAutofacMultitenantRequestServices(); var serviceProvider = services.BuildServiceProvider(); var accessor = serviceProvider.GetService(); @@ -30,14 +27,12 @@ public void UseAutofacMultitenantRequestServices_AddsHttpContextAccessor() [Fact] public void UseAutofacMultitenantRequestServices_AddsStartupFilter() { - var webHostBuilder = new Mock(); + var webHostBuilder = Substitute.For(); var services = new ServiceCollection(); - webHostBuilder - .Setup(x => x.ConfigureServices(It.IsAny>())) - .Callback>(s => s(services)); + webHostBuilder.ConfigureServices(Arg.Do>(s => s(services))); - webHostBuilder.Object.UseAutofacMultitenantRequestServices(); + webHostBuilder.UseAutofacMultitenantRequestServices(); var serviceProvider = services.BuildServiceProvider(); var filter = serviceProvider.GetService(); diff --git a/test/Autofac.Integration.AspNetCore.Multitenant.Test/MultitenantRequestServicesMiddlewareTests.cs b/test/Autofac.Integration.AspNetCore.Multitenant.Test/MultitenantRequestServicesMiddlewareTests.cs index 4809f12..5187f82 100644 --- a/test/Autofac.Integration.AspNetCore.Multitenant.Test/MultitenantRequestServicesMiddlewareTests.cs +++ b/test/Autofac.Integration.AspNetCore.Multitenant.Test/MultitenantRequestServicesMiddlewareTests.cs @@ -15,7 +15,7 @@ public class MultitenantRequestServicesMiddlewareTests [Fact] public async Task Invoke_DoesNotOverrideExistingHttpContextOnAccessor() { - var accessor = Mock.Of(); + var accessor = new SimpleHttpAccessor(); accessor.HttpContext = new DefaultHttpContext(); var next = new RequestDelegate(ctx => Task.CompletedTask); var context = CreateContext(); @@ -30,8 +30,8 @@ public async Task Invoke_DoesNotOverrideExistingHttpContextOnAccessor() [Fact] public async Task Invoke_ReplacesRequestServices() { - var accessor = Mock.Of(); - var originalFeature = Mock.Of(); + var accessor = new SimpleHttpAccessor(); + var originalFeature = Substitute.For(); var next = new RequestDelegate(ctx => { // When the next delegate is invoked, it should get @@ -56,7 +56,7 @@ public async Task Invoke_ReplacesRequestServices() [Fact] public async Task Invoke_SetsHttpContextOnAccessor() { - var accessor = Mock.Of(); + var accessor = new SimpleHttpAccessor(); var next = new RequestDelegate(ctx => Task.CompletedTask); var context = CreateContext(); var mtc = CreateServiceProvider().GetRequiredService(); @@ -79,7 +79,7 @@ private static IServiceProvider CreateServiceProvider() private static MultitenantContainer CreateContainer(IContainer container) { - var mtc = new MultitenantContainer(Mock.Of(), container); + var mtc = new MultitenantContainer(Substitute.For(), container); return mtc; } @@ -90,6 +90,11 @@ private static DefaultHttpContext CreateContext() return context; } + private sealed class SimpleHttpAccessor : IHttpContextAccessor + { + public HttpContext? HttpContext { get; set; } + } + private sealed class TestHttpResponseFeature : HttpResponseFeature { public override void OnCompleted(Func callback, object state)