Posts

Showing posts with the label multitenancy

Multitenancy Techniques for the UI in ASP.NET Core

Updated view expander code, thanks Thomas Ardal ! Introduction I've been writing some posts on multitenancy with ASP.NET Core. So far we have: Tenant identification Data filtering (for EF Core) UI customisation (this article) Business logic  This time I'm going to talk about the User Interface (UI) and give some suggestions for: Loading contents inside of a view conditionally per tenant Loading different views for different tenants Using code for making tenant-dependent choices We shall be referencing the same ITenantIdProvider abstraction shown before. All the views I'll be talking about are, of course, Razor views , which can be views in a MVC app or Razor Pages . Loading Different Views per Tenant Views are used to render HTML contents in a MVC project. The actual service that is responsible for locating the views files is IViewLocationExpander . We will implement our own version that sticks another path to the list of paths used to search for views ...

Multitenancy Techniques for ASP.NET Core

Introduction This will be another post on the multitenancy subject. For now, I plan to write or already wrote: Tenant identification (this article) Data filtering (for EF Core) UI customisation Business logic If you've been following this blog, you know about data filtering with EF Core as an example. This time, I will focus on tenant identification. A tenant is identified by some id. It may have some data, configuration, etc, against it, but, for now, we just want to be able to identify who it is. Tenant Identification When it comes to identifying a tenant, there are some options: A query string parameter (mostly for testing) A route part An HTTP header A JWT token property A cookie Other options might include: Using the HTTP Host header and mapping it to a tenant Using the source IP for the request and mapping it to a tenant I won't cover these for now. A single tenant will be associated with a request, and it won't change during its pro...

Multitenancy Techniques for EF Core

Introduction Multitenancy is a hot topic, which I covered a few times on my old blog. I won't dwell on its concepts, but, instead, I will present ways to apply multitenancy to EF Core. When it comes to data, multitenancy means that we should only retrieve data for the current tenant. I will present three ways to obtain the tenant id from inside of a  DbContext , which can then be used to set up query filters, connection strings, or mapping configuration. Multitenancy in Databases So, as I blogged before, there are essentially three strategies for applying multitenancy to databases: Using a tenant column on tenant-aware tables and filter by it Using a different schema, meaning, tenant-aware tables will be duplicated in different schemas and for each request, one schema will be used Using different databases, one for each tenant, and, for each request, pick the right connection string There are obviously pros and cons to each approach, but I won't go through them now. Instead,...