Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

How app.services determine which tenant database to use? #5026


User avatar
0
OriAssurant created

My project is MVC 5.* and AngularJS. I'm using multi-tenancy structure with one host database and multiple tenant databases.

When we're calling the app.services in angularJS module, I see abp is using IApplicationService to identify AngularJS services. I guess IApplicationService is leveraging abpsession.TenantId information to find the correct database. But even if I set the connectionstring in abptenants table to null and add the tenant connectionstring to web.config, app.services is still able to perform CRUB on correct database. I suspect that IApplicationService is selecting database based on the order of connectionstring in web.config.

Anyway, this part confuses me as lot. Could anyone please explain or provide some material?

Thank you,


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @OriAssurant,

    DbPerTenantConnectionStringResolver is used to determine the correct connection string. If TenantId is null on AbpSession, it uses default connection string, otherwise it uses the connection string of tenant if specified.

    So, in your case;

    when you set the connectionstring in abptenants table to null and add the tenant connectionstring to web.config

    Which connection string is picked ? by the way, tenants are cached, so when you set tenant's connection string to null in database, you need to refresh the cache or restart you application.