diff --git a/Autofac.AspNetCore.Multitenant.sln b/Autofac.AspNetCore.Multitenant.sln index 0796cce..e10e78a 100644 --- a/Autofac.AspNetCore.Multitenant.sln +++ b/Autofac.AspNetCore.Multitenant.sln @@ -19,7 +19,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution codecov.yml = codecov.yml EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sandbox.AspNetCore3", "samples\Sandbox.AspNetCore3\Sandbox.AspNetCore3.csproj", "{12445470-D348-467F-8D3F-FBD6EF525CEE}" +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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 0a1f9b5..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,88 +0,0 @@ -# Contributor Guide - -Contributions to Autofac, whether new features or bug fixes, are deeply appreciated and benefit the whole user community. - -The following guidelines help ensure the smooth running of the project, and keep a consistent standard across the codebase. They are guidelines only - should you feel a need to deviate from them it is probably for a good reason - but please adhere to them as closely as possible. - -If you'd like to contribute code or documentation to Autofac, we welcome pull requests. [Questions and suggestions are welcome on the newsgroup.](https://groups.google.com/forum/#!forum/autofac>). - -**Your contributions must be your own work and licensed under the same terms as Autofac.** - -## Process - -**When working through contributions, please file issues and submit pull requests in the repository containing the code in question.** For example, if the issue is with the Autofac MVC integration, file it in that repo rather than the core Autofac repo. - -- **File an issue.** Either suggest a feature or note a defect. If it's a feature, explain the challenge you're facing and how you think the feature should work. If it's a defect, include a description and reproduction (ideally one or more failing unit tests). -- **Design discussion.** For new features, some discussion on the issue will take place to determine if it's something that should be included with Autofac or be a user-supplied extension. For defects, discussion may happen around whether the issue is truly a defect or if the behavior is correct. -- **Pull request.** Create [a pull request](https://help.github.com/articles/using-pull-requests/) on the `develop` branch of the repository to submit changes to the code based on the information in the issue. Pull requests need to pass the CI build and follow coding standards. See below for more on coding standards in use with Autofac. Note all pull requests should include accompanying unit tests to verify the work. -- **Code review.** Some iteration may take place requiring updates to the pull request (e.g., to fix a typo or add error handling). -- **Pull request acceptance.** The pull request will be accepted into the `develop` branch and pushed to `master` with the next release. - -## License - -By contributing to Autofac, you assert that: - -1. The contribution is your own original work. -2. You have the right to assign the *copyright* for the work (it is not owned by your employer, or you have been given copyright assignment in writing). -3. You license it under the terms applied to the rest of the Autofac project. - -## Coding - -### Workflow - -Autofac and the associated integration libraries follow the [Gitflow workflow process](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow/) for handling releases. This means active development is done on the `develop` branch and we push to `master` when it's release time. **If you're creating a pull request or contribution, please do it on the `develop` branch.** We can then build, push to MyGet for testing, and release to NuGet when everything's verified. - -### Developer Environment - -- Visual Studio 2017 (with latest patches/updates). -- PowerShell 4+ - -### Dependencies - -The core Autofac assemblies depend _only_ on the .NET Base Class Libraries (BCL). `Autofac.dll` proper is a Portable Class Library so only depends on a subset of that BCL functionality. This is a conscious decision to keep the project lightweight and easier to maintain. - -For core integration assemblies (`Autofac.Integration.*`) the latest version of Autofac relies on the latest version of the integration target. For example, `Autofac.Integration.Mvc` always relies on the latest ASP.NET MVC libraries. This also helps keep the project easier to maintain. - -The `Autofac.Extras` features include assemblies that depend on other Open Source (OSS) libraries. It is important when including new dependencies that: - -- The project can be built straight out of Git (no additional installation needs to take place on the developer's machine). This means NuGet package references and/or checking in dependencies. -- Any third-party libraries have licenses compatible with Autofac's (the GPL and licenses like it are incompatible - please ask on the discussion forum if you're unsure). - -Unit tests are written in XUnit. - -### Build / Test - -Project codelines with scripted builds generally have a `build.ps1` script. This Powershell script will build, package, and execute tests. - -Some project codelines rely on convention-based builds so do not have a specific script. In these cases you will not see a `.ps1` or `.proj` file to execute. In these cases... - -- The build is executed by running it in Visual Studio or by executing `msbuild Solution.sln` on the solution in the codeline root. -- Unit tests can be run from the Visual Studio test explorer or by manually executing the command-line unit test runner from the `packages` folder against the built unit test assembly. - -### Code Documentation - -It is *strongly* encouraged that you update the Autofac documentation when making changes. If your changes impact existing features, the documentation may be updated regardless of whether a binary distribution has been made that includes the changes. [This can also be done through pull request.](https://github.com/autofac/Documentation) - -You should also include XML API comments in the code. These are used to generate API documentation as well as for IntelliSense. - -**The Golden Rule of Documentation: Write the documentation you'd want to read.** Every developer has seen self explanatory docs and wondered why there wasn't more information. (Parameter: "index." Documentation: "The index.") Please write the documentation you'd want to read if you were a developer first trying to understand how to make use of a feature. - -### Coding Standards - -Normal .NET coding guidelines apply. See the [Framework Design Guidelines](https://msdn.microsoft.com/en-us/library/ms229042.aspx) for suggestions. If you have access to ReSharper, code should be 'green' - that is, have no ReSharper warnings or errors with the default settings. - -Autofac source code uses four spaces for indents (rather than tabs). - -[If you have the EditorConfig add-in for your editor of choice (Visual Studio, Sublime Text, etc.)](https://editorconfig.org/), there are `.editorconfig` settings in the various repositories to help make your life easier. - -## Autofac.Extras - -Autofac.Extras are companion libraries that get distributed alongside the main Autofac distribution. The Extras are distinguished by: - -- Experimental features -- Integrations with other Open Source projects -- Alternatives to the 'typical' way of doing something in the core (e.g. a different configuration syntax) - -In many cases, Autofac.Extras is a way of testing alternatives and getting visibility for new ideas that could eventually end up in the core. - -If your contribution is accepted to Autofac.Extras it is unlikely that the rest of the project team will have the knowledge to maintain it, so please expect to have bug reports assigned to you for the area (which you may subsequently reassign if you're unable to action them). diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md deleted file mode 100644 index f61a012..0000000 --- a/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,11 +0,0 @@ -Try StackOverflow! If you have a _usage question_ ("How do I...?" "Others have this working but I can't get it...") please try [StackOverflow](https://stackoverflow.com) and tag your question `autofac`. We, along with a great community, monitor those questions. - -**Have you [read the docs?](https://autofac.readthedocs.io/)** - -**This repo is for Autofac.AspNetCore.Multitenant only.** If you are encountering issues with another package (MVC, Web API, etc.) or core Autofac, please file it in the appropriate repo. Thanks! - -**When filing an issue, please include:** - -- Assembly version information for _all_ project dependencies (packages.config, project.json) -- The stack trace and message of any exception(s) encountered. -- If possible, a reproduction of the issue (ideally in a unit test form). diff --git a/appveyor.yml b/appveyor.yml index 18e5e7e..f1030be 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,9 +1,9 @@ image: Ubuntu -version: 3.0.2.{build} +version: 4.0.0.{build} dotnet_csproj: - version_prefix: '3.0.2' + version_prefix: '4.0.0' patch: true file: 'src\**\*.csproj' diff --git a/codecov.yml b/codecov.yml index 79311a6..21faf6d 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,3 +1,8 @@ codecov: branch: develop require_ci_to_pass: yes +coverage: + status: + project: + default: + threshold: 1% \ No newline at end of file diff --git a/global.json b/global.json index 83c3bc7..cc37e78 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "3.1.302", + "version": "3.1.401", "rollForward": "latestFeature" } } diff --git a/samples/Sandbox.AspNetCore2_1_To_2_2/Program.cs b/samples/Sandbox.AspNetCore2_1_To_2_2/Program.cs index 722b888..2a017f3 100644 --- a/samples/Sandbox.AspNetCore2_1_To_2_2/Program.cs +++ b/samples/Sandbox.AspNetCore2_1_To_2_2/Program.cs @@ -7,14 +7,14 @@ namespace Sandbox.AspNetCore2_1_To_2_2 { - public class Program + public static class Program { public static Task Main(string[] args) { return CreateWebHostBuilder(args).Build().RunAsync(); } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + private static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup() .UseAutofacMultitenantRequestServices() diff --git a/samples/Sandbox.AspNetCore3/Properties/launchSettings.json b/samples/Sandbox.AspNetCore3/Properties/launchSettings.json deleted file mode 100644 index ee90d36..0000000 --- a/samples/Sandbox.AspNetCore3/Properties/launchSettings.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:35114/", - "sslPort": 0 - } - }, - "profiles": { - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "launchUrl": "api/values", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "Example": { - "commandName": "Project", - "launchBrowser": true, - "launchUrl": "api/values", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "http://localhost:35115" - } - } -} diff --git a/samples/Sandbox.AspNetCore3/Program.cs b/samples/Sandbox.AspNetCore3_To_3_1/Program.cs similarity index 58% rename from samples/Sandbox.AspNetCore3/Program.cs rename to samples/Sandbox.AspNetCore3_To_3_1/Program.cs index 0c3e959..f06efa0 100644 --- a/samples/Sandbox.AspNetCore3/Program.cs +++ b/samples/Sandbox.AspNetCore3_To_3_1/Program.cs @@ -1,21 +1,22 @@ -using Microsoft.AspNetCore.Hosting; -using System.Threading.Tasks; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; using Sandbox.Shared; namespace Sandbox { - public class Program + public static class Program { public static async Task Main(string[] args) { var host = Host.CreateDefaultBuilder(args) - .UseServiceProviderFactory(new AutofacMultitenantServiceProviderFactory(MultitenantContainerSetup.ConfigureMultitenantContainer)) + .UseServiceProviderFactory( + new AutofacMultitenantServiceProviderFactory( + MultitenantContainerSetup.ConfigureMultitenantContainer)) .ConfigureWebHostDefaults(webHostBuilder => webHostBuilder.UseStartup()) .Build(); - await host.RunAsync(); } } -} +} \ No newline at end of file diff --git a/samples/Sandbox.AspNetCore3_To_3_1/Properties/launchSettings.json b/samples/Sandbox.AspNetCore3_To_3_1/Properties/launchSettings.json new file mode 100644 index 0000000..b610e58 --- /dev/null +++ b/samples/Sandbox.AspNetCore3_To_3_1/Properties/launchSettings.json @@ -0,0 +1,13 @@ +{ + "profiles": { + "Sandbox.Sandbox.AspNetCore3_To_3_1": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api/values", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "http://localhost:35115" + } + } +} diff --git a/samples/Sandbox.AspNetCore3/README.md b/samples/Sandbox.AspNetCore3_To_3_1/README.md similarity index 100% rename from samples/Sandbox.AspNetCore3/README.md rename to samples/Sandbox.AspNetCore3_To_3_1/README.md diff --git a/samples/Sandbox.AspNetCore3/Sandbox.AspNetCore3.csproj b/samples/Sandbox.AspNetCore3_To_3_1/Sandbox.AspNetCore3_To_3_1.csproj similarity index 81% rename from samples/Sandbox.AspNetCore3/Sandbox.AspNetCore3.csproj rename to samples/Sandbox.AspNetCore3_To_3_1/Sandbox.AspNetCore3_To_3_1.csproj index 3e352c8..93c8bbe 100644 --- a/samples/Sandbox.AspNetCore3/Sandbox.AspNetCore3.csproj +++ b/samples/Sandbox.AspNetCore3_To_3_1/Sandbox.AspNetCore3_To_3_1.csproj @@ -1,7 +1,7 @@  - netcoreapp3.0 + netcoreapp3.1 Sandbox diff --git a/samples/Sandbox.AspNetCore3/Startup.cs b/samples/Sandbox.AspNetCore3_To_3_1/Startup.cs similarity index 79% rename from samples/Sandbox.AspNetCore3/Startup.cs rename to samples/Sandbox.AspNetCore3_To_3_1/Startup.cs index 963cf8d..e736c35 100644 --- a/samples/Sandbox.AspNetCore3/Startup.cs +++ b/samples/Sandbox.AspNetCore3_To_3_1/Startup.cs @@ -1,14 +1,8 @@ -using System; -using Autofac; -using Autofac.Extensions.DependencyInjection; -using Autofac.Multitenant; +using Autofac; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; using Sandbox.Shared; namespace Sandbox diff --git a/samples/Sandbox.AspNetCore3/appsettings.Development.json b/samples/Sandbox.AspNetCore3_To_3_1/appsettings.Development.json similarity index 100% rename from samples/Sandbox.AspNetCore3/appsettings.Development.json rename to samples/Sandbox.AspNetCore3_To_3_1/appsettings.Development.json diff --git a/samples/Sandbox.AspNetCore3/appsettings.json b/samples/Sandbox.AspNetCore3_To_3_1/appsettings.json similarity index 100% rename from samples/Sandbox.AspNetCore3/appsettings.json rename to samples/Sandbox.AspNetCore3_To_3_1/appsettings.json 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 2528e6d..888773d 100644 --- a/src/Autofac.Integration.AspNetCore.Multitenant/Autofac.Integration.AspNetCore.Multitenant.csproj +++ b/src/Autofac.Integration.AspNetCore.Multitenant/Autofac.Integration.AspNetCore.Multitenant.csproj @@ -4,7 +4,7 @@ ASP.NET Core support for multitenant DI via Autofac.Multitenant. 0.0.1 - netstandard2.0;netcoreapp3.0 + netstandard2.0;netcoreapp3.1 true true Autofac.Integration.AspNetCore.Multitenant @@ -37,13 +37,13 @@ - + - - + + All diff --git a/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantServiceProvider.cs b/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantServiceProvider.cs deleted file mode 100644 index 8de0c2d..0000000 --- a/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantServiceProvider.cs +++ /dev/null @@ -1,47 +0,0 @@ -// This software is part of the Autofac IoC container -// Copyright © 2019 Autofac Contributors -// https://autofac.org -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. - -using System; -using Autofac.Extensions.DependencyInjection; -using Autofac.Multitenant; - -namespace Autofac.Integration.AspNetCore.Multitenant -{ - /// - /// Autofac implementation of the ASP.NET Core for a . - /// - /// - public sealed class AutofacMultitenantServiceProvider : AutofacServiceProvider - { - /// - /// Initializes a new instance of the class. - /// - /// The . - public AutofacMultitenantServiceProvider(MultitenantContainer multitenantContainer) - : base(multitenantContainer) - { - } - } -} diff --git a/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantServiceProviderExtensions.cs b/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantServiceProviderExtensions.cs index 6fce44e..5a19ef0 100644 --- a/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantServiceProviderExtensions.cs +++ b/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantServiceProviderExtensions.cs @@ -31,15 +31,15 @@ namespace Autofac.Integration.AspNetCore.Multitenant { /// - /// Extension methods for use with the . + /// Extension methods for use with the . /// public static class AutofacMultitenantServiceProviderExtensions { /// - /// Tries to cast the instance of from when possible. + /// Tries to cast the instance of from when possible. /// /// The instance of . - /// Returns the instance of exposed by when it can be casted down from . + /// Returns the instance of exposed by when it can be casted down from . /// /// Thrown if can't be casted to . /// diff --git a/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantServiceProviderFactory.cs b/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantServiceProviderFactory.cs index 2257fbc..820442a 100644 --- a/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantServiceProviderFactory.cs +++ b/src/Autofac.Integration.AspNetCore.Multitenant/AutofacMultitenantServiceProviderFactory.cs @@ -93,7 +93,7 @@ public IServiceProvider CreateServiceProvider(ContainerBuilder containerBuilder) if (multitenantContainer == null) throw new InvalidOperationException(Resources.NoMultitenantContainerAvailable); - return new AutofacMultitenantServiceProvider(multitenantContainer); + return new AutofacServiceProvider(multitenantContainer); } } } 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 7f35170..51e3709 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 @@ -21,9 +21,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers @@ -31,9 +31,9 @@ All - - - + + + diff --git a/test/Autofac.Integration.AspNetCore.Multitenant.Test/AutofacMultitenantServiceCollectionExtensionsTests.cs b/test/Autofac.Integration.AspNetCore.Multitenant.Test/AutofacMultitenantServiceCollectionExtensionsTests.cs index 6a99dcf..45ca13d 100644 --- a/test/Autofac.Integration.AspNetCore.Multitenant.Test/AutofacMultitenantServiceCollectionExtensionsTests.cs +++ b/test/Autofac.Integration.AspNetCore.Multitenant.Test/AutofacMultitenantServiceCollectionExtensionsTests.cs @@ -1,4 +1,5 @@ using System; +using Autofac.Integration.AspNetCore.Multitenant.Properties; using Autofac.Multitenant; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; diff --git a/test/Autofac.Integration.AspNetCore.Multitenant.Test/AutofacMultitenantServiceProviderFactoryTests.cs b/test/Autofac.Integration.AspNetCore.Multitenant.Test/AutofacMultitenantServiceProviderFactoryTests.cs new file mode 100644 index 0000000..ecef7ce --- /dev/null +++ b/test/Autofac.Integration.AspNetCore.Multitenant.Test/AutofacMultitenantServiceProviderFactoryTests.cs @@ -0,0 +1,31 @@ +using System; +using Autofac.Integration.AspNetCore.Multitenant.Properties; +using Autofac.Multitenant; +using Microsoft.AspNetCore.Hosting; +using Xunit; + +namespace Autofac.Integration.AspNetCore.Multitenant.Test +{ + public class AutofacMultitenantServiceProviderFactoryTests + { + [Fact] + public void + NewAutofacMultitenantServiceProviderFactory_MultitenantContainerAccessorRetursNull_ThrowsInvalidOperationExecption() + { + var ex = Assert.Throws(() => new AutofacMultitenantServiceProviderFactory(null!)); + + Assert.Contains(nameof(MultitenantContainer), ex.Message, StringComparison.InvariantCultureIgnoreCase); + } + + [Fact] + public void CreateServiceProvider_MultitenantContainerAccessorRetursNull_ThrowsInvalidOperationExecption() + { + var factory = new AutofacMultitenantServiceProviderFactory(_ => null!); + + var ex = Assert.Throws(() => + factory.CreateServiceProvider(new ContainerBuilder())); + + Assert.Equal(Resources.NoMultitenantContainerAvailable, ex.Message); + } + } +}