MultiTenancy.Core 0.0.8

There is a newer version of this package available.
See the version list below for details.
dotnet add package MultiTenancy.Core --version 0.0.8
NuGet\Install-Package MultiTenancy.Core -Version 0.0.8
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="MultiTenancy.Core" Version="0.0.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MultiTenancy.Core --version 0.0.8
#r "nuget: MultiTenancy.Core, 0.0.8"
#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 MultiTenancy.Core as a Cake Addin
#addin nuget:?package=MultiTenancy.Core&version=0.0.8

// Install MultiTenancy.Core as a Cake Tool
#tool nuget:?package=MultiTenancy.Core&version=0.0.8

example workflow Shields.io Shields.io

MultiTenancy

a lightway package to manage and implement multi tenant architecture to your .NET Core Applications

Usage

Usage in Startup

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMultiTenancy<TenantCatalog, Guid>()
                .AddTenantCatalogContext<TenantCatalogContext>(builder => builder.UseSqlServer("<Your connection string>"))
                .AddTenantContext<TenantObjectContext>();
        }
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            // Creates middleware that search for tenant-id in Header for each request and set it's to TenantProvider
            app.UseMultiTenancy<TenantCatalog, Guid>();
            // Use this if you want to migrate all tenants databases specified in Catalog Database
            app.MigrateTenantDatabases<TenantCatalog, Guid>(); 
        }

Create Tenant Catalog object context

    public class ExampleTenantCatalogDbContext : TenantCatalogDbContext<TenantCatalog, Guid>
    {
        public ExampleTenantCatalogDbContext(DbContextOptions<ExampleTenantCatalogDbContext> options) : base(options)
        {
        }
    }

Create tenant Object Context

We need to create our context that will be used across the application for retrivng and inserting data for various clients.

⚠️ It's important to implement DbContext with two constructors - One is for migrations and second is for using the application

    public class TenantObjectContext : TenantDbContext<TenantCatalog, Guid>
    {
        public TenantObjectContext(ITenantProvider<TenantObject, Guid> provider,
            DbContextOptions<TenantObjectContext> options) : base(provider, options)
        {
        }

        public TenantObjectContext(
            SqlConnectionStringBuilder connectionStringBuilder, 
            ITenantProvider<TenantObject, Guid> provider) 
            : base(connectionStringBuilder, provider)
        {
        }
    }

Create tenant catalog object

    public class TenantCatalog : Tenant<Guid>
    {
    }

Create tenant object

    public class TenantObject : Tenancy<Guid>
    {
    }

Database Connection Support

Name Supported
SqlServer
PostgreSQL
MySQL
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 netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on MultiTenancy.Core:

Package Downloads
MultiTenancy.Core.InMemory

EF Core InMemory Database Provider for MT.Core

MultiTenancy.Core.SqlServer

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.10 466 5/20/2021
0.0.9 273 5/20/2021
0.0.8 314 5/8/2021
0.0.7 301 5/8/2021
0.0.6 270 5/5/2021
0.0.5 275 5/5/2021
0.0.4 301 5/4/2021
0.0.3 348 5/3/2021
0.0.2 309 5/2/2021
0.0.1 340 4/30/2021

- Now every method has a comment !
- Added validation on adding tenant into database