ABP Framework version: v9.0.4
-
UI Type: Angular
-
Database System: EF Core (PostgreSQL)
Hi,
We are currently working on a solution that involves Editions, where each Edition should include specific Features. These Features are to be represented as service modules in our architecture.
We intend to set up dynamically a separate database for each tenant for every service module they are using.
What is the best practice to implement this please?
Thanks
3 Answer(s)
-
0
and if i have an EditionId, how to get the features related to it?
-
0
Hi,
ABP Framework allows tenants to use separate databases and Saas module has an UI to separate tenant databases manually at runtime. But there is no built-in feature for creating databases dynamically whenever a tenant created or edition changes for a tenant. You have to implement it in your application according to your logic.
Let me show the TenantAppService.cs implementation from the Saas Module:
If you create each tenant with
ConnectionStrings
property is configured and make sure distributed event is published, you can achieve this logic.You don't have to write all the codes here, I just wanted to explain the logic. You can easily replace TenantAppService in your application and configure connection string for each tenant dynamically:
[Dependency(ReplaceServices = true)] [ExposeServices(typeof(ITenantAppService))] public class CustomTenantAppService : TenantAppService { public CustomTenantAppService(ITenantRepository tenantRepository, IEditionRepository editionRepository, ITenantManager tenantManager, IDataSeeder dataSeeder, ILocalEventBus _localEventBus, IDistributedEventBus distributedEventBus, IOptions<AbpDbConnectionOptions> dbConnectionOptions, IConnectionStringChecker connectionStringChecker) : base(tenantRepository, editionRepository, tenantManager, dataSeeder, _localEventBus, distributedEventBus, dbConnectionOptions, connectionStringChecker) { } public override Task<SaasTenantDto> CreateAsync(SaasTenantCreateDto input) { // 👇 Something similar input.ConnectionStrings.Default = $"Server=localhost;Database=MyProjectName_{input.Name.Normalize()};User=root;Password=123456;"; return base.CreateAsync(input); } }
-
0
I have two questions plz:
1- How can we specify which service tenant database a microservice should work with (e.g., Microservice_Tenant1_Products, Microservice_Tenant2_Products, etc.)?
2- When we add new database migrations at the service, how should we handle them considering that each tenant has its own separate service database? how this migration will be applied to all service tenant dbs?