Coder Social home page Coder Social logo

gpeipman / aspnetcoremultitenant Goto Github PK

View Code? Open in Web Editor NEW
191.0 18.0 64.0 1.01 MB

Multitenant ASP.NET Core application to serve as a starting point for real multitenant applications

Home Page: https://gunnarpeipman.com

C# 79.15% CSS 1.72% JavaScript 0.46% HTML 18.66%
multi-tenant-asp aspnetcore ef-core multitenant

aspnetcoremultitenant's Introduction

Multi-tenant ASP.NET Core

This is demo project for my Multi-tenant ASP.NET Core presentation. It demonstrates multi-tenant solutions I have worked out for ASP.NET Core. I'm using the same demo also for presentations. Solutions provided here are not absolute truth. There are cases when something different is needed and then the code here serves as a good starting point.

Features

There are multiple features and solutions demonstrated in demo application:

Setting every thing up

To demonstrate multi-tenant features I have built I'm using SQL Server LocalDB and MySQL databases. SQL Server LocalDB uses integrated security. For MySQL some user account is needed to access database. Those who plan to run this example on Linux must use some Linux version of SQL Server or SQL Server running on some other machine.

There are two web applications in the solution:

  • AspNetCoreMultitenant.Web - safe multitenant web application to use as an example and starting point
  • AspNetCoreMultitenant.WebDangerous - dangerous approach to shared resources (shared database tables)

AspNetCoreMultitenant.Web defines three tenants:

  • bigcorp - uses dedicated MySQL database
  • sme1 - uses SQL Server database
  • sme2 - uses SQL Server database

AspNetCoreMultitenant.WebDangerous defines two tenants:

  • sme1 - uses same SQL Server database as sme2
  • sme2 - uses same SQL Server database as sme1

There are also some host name mappings needed to run this demo on local machine:

  • 127.0.0.1 bigcorp
  • 127.0.0.1 sme1
  • 127.0.0.1 sme2

Web application uses port 5000 and it must be added to URL of all tenants:

Dangerous web application uses port 5001 and it must be added to URL of all tenants:

When using public server to host this application make sure you turn on HTTPS in application startup.

Concepts

This solution has some important concepts to know:

  • Tenant source - class that knows how to read tenant definitions from tenants store
  • Tenant provider - class that knows how to find current tenant
  • Dynamic cache key provider - class that provides EF Core with caching keys for DbContext model
  • Missing tenant middleware - ASP.NET Core request pipeline middleware that acts when tenant is not found

aspnetcoremultitenant's People

Contributors

gpeipman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aspnetcoremultitenant's Issues

Dashboard with all Tenant data and Creating Database on Tenant Registration.

I am trying to implement Multi-Tenant -per Tenant separate Schema (Database single Instance).
https://gunnarpeipman.com/aspnet-core-database-per-tenant/ Taking help from this tutorial. Now I have one Situation That the Owner of the Application wants to have a dashboard which will show data from all the Tenant - Is this possible to connect with different DBContext and get data, the number of Tenant is not fixed it can increase at run time.
Apart from that -
Is this possible to create database at runtime - when the send metadata is added in DB - That time if we can have a button to initiate the the process.
Need some suggestion- which way should I go.
Thanks

Use StorageConnectionString in Startup.cs

The Startup.cs file under AspNetCoreMultitenant.Web uses the following code:

services.AddScoped<IFileClient>(service =>
{
	var provider = service.GetRequiredService<ITenantProvider>();
	var tenant = provider.GetTenant();

	if(tenant.StorageType == "GoogleDrive")
	{
		return new GoogleDriveFileClient(tenant.ConnectionString);
	}

	if(tenant.StorageType == "AzureBlob")
	{
		return new AzureBlobStorageFileClient(tenant.ConnectionString);
	}

	return null;
});

The code should be return new GoogleDriveFileClient(tenant.StorageConnectionString); and return new AzureBlobStorageFileClient(tenant.StorageConnectionString);

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.