Search code examples
c#asp.net-mvcasp.net-core.net-coremulti-tenant

.NET Core Multi Tenancy practicality


I was wondering if it is practical to develop a .NET Core application to be multi tenanted or would having a normal single tenant application be sufficient?

My current db structure is as follows:

  • Users Table
  • Organization Table
  • Product Table

A user belongs to an organization (with the exception of system administrators) and an organization can have multiple products

When a user logs in, part of their claims is the OrganizationId meaning they can only see Products that their OrganizationId owns.

At the moment, my urls look like this:

  • www.localhost.com:9988
  • www.localhost.com:9988/Products/Product/Create

My Startup.cs url routing looks like this:

app.UseMvc(routes =>
{
    routes.MapRoute(
      name: "areas",
      template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
    );
    routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?}"
    );

});

Would it be difficult to transform what I have now into a multi tenanted application? Something like when a User belonging to an Organization logs in, their url will be

organizationname.localhost.com:9988/Products/Product

Or is my current method enough?

I intend on building it to support multiple organizations.


Solution

  • We do something very similar to your theoretical setup currently. Same code runs for each tenant on their own 'server' (containerized). Most of the "difficulty" in the configuration should be related to the server rather than .Net itself.

    Depending on your area of business you might want to determine if any clients might be upset that their data is commingled with other's. If it's not a big deal and just the logical (org) separation works ignore me on that.