Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with multitenancy with separate databases #22272

Open
Gru97 opened this issue Mar 4, 2025 · 1 comment
Open

Issue with multitenancy with separate databases #22272

Gru97 opened this issue Mar 4, 2025 · 1 comment

Comments

@Gru97
Copy link

Gru97 commented Mar 4, 2025

Hi all,

First, thank you for open-sourcing this fantastic framework. I’ve been using the ABP Framework in an application with the following setup:

ABP Framework version: 8.3.1 (non-commercial)
.NET Core: 8
Database: MSSQL

I’m implementing multitenancy with separate databases for each tenant. Everything works fine with a single database, but I’m encountering an issue with the separate database solution. As I understand it, in ABP's generic repository implementation in EfCoreRepository.cs (here), if an entity does not implement the IMultitenant interface, it is considered a host entity and does not follow the tenant context set by the caller code.

This behavior works as expected with a single database. However, in a solution where all entities are multitenant and stored in separate databases, implementing IMultitenant and having the TenantId field on all tables is not very helpful. Originally, it was meant to be a marker, but it’s now performing two roles.

I had to implement the interface for all my custom entities, but the problem arises when using ABP library entities. For example, with the Settings module, I encounter an issue where the entity is inaccessible, and it doesn’t implement the IMultitenant interface. I really don’t want a global storage solution for settings across all tenants.

To work around this, I’m considering implementing my own settings manager. However, I would appreciate a cleaner solution that allows me to retain ABP's built-in settings management while resolving this issue.

Thanks in advance for any suggestions or solutions!

#ABP
#abp
#multitenancy

@maliming
Copy link
Member

maliming commented Mar 5, 2025

hi

implementing IMultitenant and having the TenantId field on all tables is not very helpful. Originally, it was meant to be a marker, but it’s now performing two roles.

If entities stored in the tenant database don't have the IMultitenant interface, it'll cause many problems.

First, you don't know if a queried entity belongs to a tenant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants