Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
alistairjevans committed Nov 15, 2021
2 parents dfc226e + f5a276c commit e909cfd
Show file tree
Hide file tree
Showing 28 changed files with 159 additions and 104 deletions.
7 changes: 3 additions & 4 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"recommendations": [
"ms-dotnettools.csharp",
"formulahendry.dotnet-test-explorer",
"editorconfig.editorconfig",
"shd101wyy.markdown-preview-enhanced",
"davidanson.vscode-markdownlint",
"editorconfig.editorconfig",
"formulahendry.dotnet-test-explorer",
"ms-dotnettools.csharp",
"stkb.rewrap"
]
}
52 changes: 52 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"configurations": [
{
"cwd": "${workspaceFolder}",
"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:5555"
},
"launchBrowser": {
"enabled": false
},
"name": "Sandbox 2.1-2.2",
"preLaunchTask": "build",
"program": "${workspaceFolder}/samples/Sandbox.AspNetCore2_1_To_2_2/bin/Debug/netcoreapp2.1/Sandbox.AspNetCore2_1_To_2_2.dll",
"request": "launch",
"stopAtEntry": false,
"type": "coreclr"
},
{
"cwd": "${workspaceFolder}",
"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:5555"
},
"launchBrowser": {
"enabled": false
},
"name": "Sandbox 2-3.1",
"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",
"request": "launch",
"stopAtEntry": false,
"type": "coreclr"
}
]
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"cSpell.words": [
"autofac",
"multitenant"
],
"dotnet-test-explorer.runInParallel": true,
"dotnet-test-explorer.testProjectPath": "test/**/*.Test.csproj"
}
2 changes: 1 addition & 1 deletion Autofac.AspNetCore.Multitenant.sln
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ProjectSection(SolutionItems) = preProject
build\stylecop.json = build\stylecop.json
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sandbox.AspNetCore5", "samples\Sandbox.AspNetCore5\Sandbox.AspNetCore5.csproj", "{B64B6D62-AD07-49BE-AF65-3E4C92284AD5}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sandbox.AspNetCore5_To_6", "samples\Sandbox.AspNetCore5_To_6\Sandbox.AspNetCore5_To_6.csproj", "{B64B6D62-AD07-49BE-AF65-3E4C92284AD5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

ASP.NET Core support for multitenant DI via [Autofac.Multitenant](https://github.com/autofac/Autofac.Multitenant).

[![Build status](https://ci.appveyor.com/api/projects/status/u6epu5sc9f9sgav3?svg=true)](https://ci.appveyor.com/project/Autofac/autofac-aspnetcore-multitenant) [![codecov](https://codecov.io/gh/Autofac/Autofac.AspNetCore.Multitenant/branch/develop/graph/badge.svg)](https://codecov.io/gh/Autofac/Autofac.AspNetCore.Multitenant)
[![Build status](https://ci.appveyor.com/api/projects/status/u6epu5sc9f9sgav3?svg=true)](https://ci.appveyor.com/project/Autofac/autofac-aspnetcore-multitenant) [![codecov](https://codecov.io/gh/Autofac/Autofac.AspNetCore.Multitenant/branch/develop/graph/badge.svg)](https://codecov.io/gh/Autofac/Autofac.AspNetCore.Multitenant) [![Open in Visual Studio Code](https://open.vscode.dev/badges/open-in-vscode.svg)](https://open.vscode.dev/autofac/Autofac.AspNetCore.Multitenant)

Please file issues and pull requests for this package in this repository rather than in the Autofac core repo.

Expand Down
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
image: Ubuntu

version: 5.0.0.{build}
version: 5.1.0.{build}

dotnet_csproj:
version_prefix: '5.0.0'
version_prefix: '5.1.0'
patch: true
file: 'src\**\*.csproj'

Expand Down Expand Up @@ -33,7 +33,7 @@ deploy:
- provider: NuGet
server: https://www.myget.org/F/autofac/api/v2/package
api_key:
secure: rCUEY75fXN0wxtMy6QL4jCrLdaYbxIBzIXWeN+wEu/XDpyqimzreOc5AH5jMd5ah
secure: xUXExgVAagrdEicCjSxsQVrwiLo2TtnfqMbYB9Cauq2cpbm/EVz957PBK0v/GEYq
skip_symbols: true
symbol_server: https://www.myget.org/F/autofac/symbols/api/v2/package
artifact: MyGet
32 changes: 10 additions & 22 deletions build/Autofac.Build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,6 @@ function Install-DotNetCli {
[string]
$Version = "Latest"
)

if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue)) {
$installedVersions = dotnet --list-sdks
foreach ($sdkListLine in $installedVersions)
{
$splitParts = $sdkListLine.Split(" ");

$versionPart = $splitParts[0];

$globalInstallLocation = $splitParts[1].Replace("[", "").Replace("]", "")

if ($versionPart -eq $Version)
{
Write-Message ".NET Core SDK version $Version is already installed in $globalInstallLocation"
Add-Path "$globalInstallLocation"
return;
}
}
}

Write-Message "Installing .NET SDK version $Version"

$callerPath = Split-Path $MyInvocation.PSCommandPath
Expand Down Expand Up @@ -93,11 +73,19 @@ function Add-Path {
[string]
$Path
)
$pathValues = $env:PATH.Split(";");

$pathSeparator = ":";

if ($IsWindows) {
$pathSeparator = ";";
}

$pathValues = $env:PATH.Split($pathSeparator);
if ($pathValues -Contains $Path) {
return;
}
$env:PATH = "$Path;$env:PATH"

$env:PATH = "${Path}${pathSeparator}$env:PATH"
}

<#
Expand Down
3 changes: 2 additions & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"sdk": {
"version": "5.0.100",
"version": "6.0.100",
"rollForward": "latestFeature"
},

"additionalSdks": [
"5.0.403",
"2.1.811",
"3.1.302"
]
Expand Down
36 changes: 36 additions & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Sample ASP.NET Core Multitenant Applications

Each of the 'sandbox' applications shows, in the respective framework version, the functionality of Autofac.AspNetCore.Multitenant in action. You can launch them from Visual Studio or VS Code with the settings in this project; or you can run from the command line with `dotnet run`.

## Try It Out

You can see different dependencies used by querying the `api/values` route:

```sh
# Get the default value - will show `base` since there's no tenant ID.
curl http://localhost:5555/api/values

# Get some tenant-specific values - will show the tenant ID due to overrides.
curl http://localhost:5555/api/values?tenant=a
curl http://localhost:5555/api/values?tenant=b

# Only tenant a and b have overrides. Tenant c will show `base` again.
curl http://localhost:5555/api/values?tenant=c
```

## Points of Interest

### Program.cs

When using the `WebHostBuilder` the `UseAutofacMultitenantRequestServices` extension is used to tie the multitenant container to the request lifetime scope generation process.

**If you comment out the `UseAutofacMultitenantRequestServices` line it'll stop working** and you'll only ever see `base`. This illustrates why this package is required.

## Startup.cs

In `ConfigureServices` we...

- Create a tenant ID strategy.
- Set up the multitenant container.
- Store the multitenant container in a place that the request services middleware can access it later.
- Return an `AutofacServiceProvider` so services can be resolved normally.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"Sandbox.AspNetCore2_1": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"applicationUrl": "http://localhost:5555",
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"launchBrowser": true,
"launchUrl": "api/values"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<!-- netcoreapp2.1 is out of support, we don't need a warning about it. -->
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<RootNamespace>Sandbox</RootNamespace>
<NoWarn>$(NoWarn);CS1591;SA1600</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
3 changes: 1 addition & 2 deletions samples/Sandbox.AspNetCore2_1_To_2_2/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public void ConfigureServices(IServiceCollection services)

public void Configure(IApplicationBuilder app)
{
app.UseHttpsRedirection();
app.UseMvc();
}

Expand All @@ -34,4 +33,4 @@ public void ConfigureContainer(ContainerBuilder builder)
ContainerSetup.SetupContainer(builder);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"Sandbox.Sandbox.AspNetCore3_To_3_1": {
"applicationUrl": "http://localhost:5555",
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:35115"
"launchBrowser": true,
"launchUrl": "api/values"
}
}
}
}
28 changes: 0 additions & 28 deletions samples/Sandbox.AspNetCore3_To_3_1/README.md

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"Sandbox.AspNetCore5": {
"applicationUrl": "http://localhost:5555",
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:35116"
"launchBrowser": true,
"launchUrl": "api/values"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>Sandbox</RootNamespace>
<NoWarn>$(NoWarn);CS1591;SA1600</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Description>ASP.NET Core support for multitenant DI via Autofac.Multitenant.</Description>
<!-- VersionPrefix patched by AppVeyor -->
<VersionPrefix>0.0.1</VersionPrefix>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Autofac.Integration.AspNetCore.Multitenant</AssemblyName>
Expand Down Expand Up @@ -47,7 +47,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.1.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.2.0" />
<PackageReference Include="Autofac.Multitenant" Version="6.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="2.6.1">
<PrivateAssets>All</PrivateAssets>
Expand All @@ -58,7 +58,7 @@
<PackageReference Include="Microsoft.Net.RoslynDiagnostics" Version="2.6.1">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" Condition="Exists('$(MSBuildThisFileDirectory)../../.git')">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" Condition="Exists('$(MSBuildThisFileDirectory)../../.git')">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
Expand All @@ -81,4 +81,4 @@
</EmbeddedResource>
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using Autofac;
using Autofac.Integration.AspNetCore.Multitenant;
using Autofac.Multitenant;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Collections.Generic;
using System.Reflection;
using Autofac;
using Autofac.Builder;
using Autofac.Extensions.DependencyInjection;
using Autofac.Integration.AspNetCore.Multitenant;
using Autofac.Integration.AspNetCore.Multitenant.Properties;
using Autofac.Multitenant;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.AspNetCore.Hosting
Expand Down
Loading

0 comments on commit e909cfd

Please sign in to comment.