Deveel Repository
Deveel
  • Why Another Repository Pattern Library?
  • The Repository Pattern
  • Getting Started
  • Customize the Repository
  • Multi-Tenancy of Data Sources
  • User Entities
  • Repository Implementations
    • In-Memory Repositories
    • Entity Framework Core Repositories
    • MongoDB Repositories
  • The Entity Manager
    • Caching Entities
Powered by GitBook
On this page
  • The Tenant Context
  • Repository Providers
Edit on GitHub

Multi-Tenancy of Data Sources

PreviousCustomize the RepositoryNextUser Entities

Last updated 1 year ago

Software-as-a-Service (SaaS) applications and Enterprise-level applications often need to segregate data between different tenants of the application, that could be different customers or different departments of the same company.

By default, the kernel library doesn't provides any set of abstractions and implementations to support multi-tenancy in your application, but the single drivers can provide it, accordingly to their specific capabilities.

Driver
Multi-Tenancy

In-Memory

MongoDB

Entity Framework Core

The Tenant Context

On a general basis, the tenant context is resolved through the identity of a user of the application, using mechanisms like claims or roles (see at how this is implemented in ASP.NET Core).

Some scenarios anyway require the access to those segregated information from a service or a background task, where the user identity is not available: for this reason the framework provides an abstraction named IRepositoryProvider<TEntity> that will be used to resolve the repository to access the data, for the tenant identifier.

To learn more about the usage of the IRepositoryProvider<TEntity> interface, you can read the documentation .

Repository Providers

The preferred approach of the library is to use the framework to implement multi-tenant applications, and to use the ITenantInfo interface to retrieve the current tenant information: this is obtained by scanning the current HTTP request, and retrieving the tenant information from the request.

In some cases, like in background services, where the identity of the tenant is not available through the user (eg. machine-to-machine communication), it is possible to obtain the repository for a specific tenant by using the IRepositoryProvider<TEntity> interface: these are still drivers-specific, and produce instances of the repository for a specific tenant and specific driver.

The IRepositoryProvider<TEntity> interface

The IRepositoryProvider<TEntity> exposes a single method that allows to obtain an instance of IRepository<TEntity> for a specific tenant.

Task<IRepository<TEntity>> GetRepositoryAsync(string tenantId, CancellationToken cancellationToken = default);

Every driver that supports multi-tenancy will implement this interface, and the IRepository<TEntity> instance returned will be specific for the tenant identifier passed as parameter.

Finbuckle Multi-Tenant
here
Finbuckle.MultiTenant
❌
✅
✅