Manual Tenant Switching Issue #590
Unanswered
Rockstar1989
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Hi, there. It's somewhat of a manual process because in normal operation DI is used to get things going. I will post a solution for you in the next few days. Are you using Identity at all or just regular db contexts? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there;
I hope that you are doing well.
I have an enquiry with regards to switching a tenant at runtime, specifically, cycling through tenant IDs/identifiers to resolve their respective Database Contexts and carry out some sort of persistence.
We are currently making use of the host strategy for tenant resolution which of course works just fine, but we now have a use case where, given a list of tenant IDs, we want to persist some data to each tenant DB. This would be taking place in one of our API services - this can be thought of an "admin-level" task. Therefore, we would like to change the resolved tenant at runtime for each provided tenantId and use its resolved Database Context for persistence.
According to your documentation, the following line seems to provide what we are looking for, however, the Database Context after this call is not resolved.
_httpContextAccessor.HttpContext?.TrySetTenantInfo(tenantInfo, true);
Is the Database Context not being resolved for a newly set tenant expected behavior?
If so, what is value provided by the above line? What use case is the above satisfying/achieving?
If not, may I please ask for some assistance on what we may be doing incorrectly, and for any information that we have missed and should be aware of when tackling this problem/use case.
I look forward to hearing from you, thank you!
Beta Was this translation helpful? Give feedback.
All reactions