ASP.NET MVC templates for multiple tenants and plugins?

I am trying to understand how I can create an ASP.NET MVC site that exists as a VS2010 project in a solution, and then for several tenants I would create a site that inherits from it. This would provide the flexibility of adding modular functions to one without affecting the other, and both could benefit from optimizing the core libraries.

Is this a crazy idea? What patterns exist for this kind of thing? I did something similar for a website (adding DLLS as plugins), but not in MVC.

"Tenant" is a business client. Everyone already has their own MSSQL database and separate processing around them, each client is in his own bunker. Databases are similar to several functions added here and there, they are versioned and deployed separately, the whole process works well. The client has n logins. I want to create a single "base site", which can then be used to provide the function to the tenant, and all actions will be divided for the tenant in one database. Where everything becomes ugly, I can add a new component (for example, a forum) to one tenant's site, without letting the site work for other tenants.

All ideas are appreciated. Thanks.

+4
source share
1 answer

I worked a lot on developing a multi-user web application. Here are three key pointers to get you started:

Security

TenantId is part of the login credentials. They are stored in Thread.CurrentPrincipal. This effectively associates each request (stream) with a specific user and, therefore, with the tenant. Thread.CurrentPrincipal can be easily obtained from any code.

Database

We used a single database to store all the data. A separation was made between tables (entities) that were specific to one tenant (multi-user) and tables that were not (cross-tenant). Multi-user tables had a column called "TenantId". In our entity model, we made sure that these objects are inherited from the special IMultiTenant interface. This interface contained the C # equivalent of the TenantId field. We have expanded the Entity Framework architecture to provide default filtering for TenantId for multi-tenant properties. This ensured that one tenant was never able to access or change the data of another tenant.

Plugins

We used some intriguing dependencies to support the implementation of a particular tenant code. Based on the current TenantId, our DI container introduces a concrete implementation of this interface.

0
source

All Articles