Eodg.MultiTenancy.Middleware 0.5.0-alpha

This is a prerelease version of Eodg.MultiTenancy.Middleware.
dotnet add package Eodg.MultiTenancy.Middleware --version 0.5.0-alpha
NuGet\Install-Package Eodg.MultiTenancy.Middleware -Version 0.5.0-alpha
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Eodg.MultiTenancy.Middleware" Version="0.5.0-alpha" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Eodg.MultiTenancy.Middleware --version 0.5.0-alpha
#r "nuget: Eodg.MultiTenancy.Middleware, 0.5.0-alpha"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Eodg.MultiTenancy.Middleware as a Cake Addin
#addin nuget:?package=Eodg.MultiTenancy.Middleware&version=0.5.0-alpha&prerelease

// Install Eodg.MultiTenancy.Middleware as a Cake Tool
#tool nuget:?package=Eodg.MultiTenancy.Middleware&version=0.5.0-alpha&prerelease

MultiTenancyMiddleware

It's a little black box... kind of

This library allows you to incorporate multitenancy into a .net core 2.0 web api project. After setting up a handful of things (outlined below), you will be able to make a request, and by adding a header to said request containing the account id of the tenant for whose data you want to access you can get said data.

How do you implement it?

  • Write a concrete implementation of the provided MultiTenancyResolverService abstract class / IMultiTenancyResolverService interface.
    • There only has to be a ConnectionString property and a SetConnectionStringByAccountId(string accountId) method that sets the ConnectionString property.
  • In the Startup.cs file, we'll have to do a couple of things:
    • Add your implementation to the built-in DI container a la:

      services.AddScoped<IMultiTenancyResolverService, ExampleMultiTenancyResolverService>();

      where ExampleMultiTenancyResolverService is the name of your concrete implementation of the provided MultiTenancyResolverService abstract class / IMultiTenancyResolverService interface

    • Add the options for the middleware. This only contains a UseHeaderKey property and a HeaderKey property and this will be the header key used in the request that contains the account id of the tenant whose database you want to reference for the particular request... Or set UseHeaderKey to false if your code will be doing things a different way.

      var multiTenancyMiddlewareOptions = new MultiTenancyMiddlewareOptions
      {
           UseHeaderKey = true,
           TenantIdHeaderKey = "Account-Id"
      
      };
      
      services.AddSingleton(multiTenancyMiddlewareOptions);
      
  • Database context class for the tenant template database:
    • Inject the IMultiTenancyResolver into the constructor, and store in private variable:

      private IMultiTenancyResolverService _multiTenancyResolverService;

    • Add the following method:

          protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
          {
              optionsBuilder.UseSqlServer(_multiTenancyResolverService.ConnectionString);
              base.OnConfiguring(optionsBuilder);
          }
      

How do you use it?

  • For any controller/method utilizing multitenancy add the following attribute

    [MiddlewareFilter(typeof(MultiTenancyPipeline))]

  • Any time a request is made to said controllers/methods, a header will have to exist on the request that has the key specified in the Startup.cs class, and will have to have a value of the account id.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 is compatible.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.5.0-alpha 951 4/4/2018
0.4.0-alpha 659 4/4/2018
0.3.0-aplha 693 4/3/2018
0.2.0-aplha 835 3/31/2018
0.1.0-aplha 844 3/31/2018