GithubHelp home page GithubHelp logo

gnschenker / multi-tenant-poc Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 11 KB

POC for a multi tenant app using a DB per tenant - Implemented in .NET Core and EF

C# 94.17% Dockerfile 0.66% TSQL 5.16%

multi-tenant-poc's Introduction

Multi Tenancy POC

This is a POC showing how one can use Entity Framework with a Postgres DB per tenant. Different tenant identification strategies can be used. The following ones are implemented:

  • Using a request header (X-Tenant) to provide the tenant and a database lookup to map the tenant
    DbTenantIdentificationService.cs

  • Using a request header (X-Tenant) to provide the tenant and a configuration file lookup to map the tenant
    HeaderTenantIdentificationService.cs

  • Using the request host to provide the tenant and a configuration file lookup to map the tenant
    HostTenantIdentificationService.cs

Using multiple DbScopes

To use multiple DbScope objects one must use generic options in the constructor (DbContextOptions<T>).

It is also advised to implement factory objects to generate the DB context objects when using tools such as dotnet ef migrations (see: https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dbcontext-creation)

Creating the Code First Migrations

  • To create the (first) migration for the tenants context use:

    dotnet ef migrations add InitialCreate --context TenantsDbContext -o Migrations/Tenants
  • To create the SQL scripts for the (first) migration for the tenants context use:

    dotnet ef migrations script --context TenantsDbContext -o Migrations/Tenants/scripts/00-initial-create.sql
  • To create the (first) migration for the blogs context use:

    dotnet ef migrations add InitialCreate --context BlogsDbContext -o Migrations/Blogs
  • To create the SQL scripts for the (first) migration for the tenants context use:

    dotnet ef migrations script --context BlogsDbContext -o Migrations/blogs/scripts/00-initial-create.sql

Creating a DB per Tenant

TODO: how do we want to create (and/or migrate) all tenant databases?

multi-tenant-poc's People

Contributors

gnschenker avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.