Ideal setup for a SaaS Multi Tenant System #37
-
Hello Ramy, first of all, thank you very much for this great bundle! I think you have solved a fundamental problem for everyone who wants to use Symfony Mandant-enabled. I am wondering if it is possible to centralize the tenant switch event Instead of using it everywhere I want to create, edit or delete some tenant specific entites, would it be easier to generally switch the main entity manager after e.g. you successfully logged in with your Main/TenantUser and got authorized? Many thanks for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi Marvin, Thank you for your question and for your kind words about the Multi-Tenancy Bundle. To answer your question, yes, it is possible to centralize the tenant switch event (SwitchDbEvent) instead of dispatching it everywhere you need to create, edit, or delete tenant-specific entities. A common approach is to automatically switch the entity manager to the correct tenant database after a successful login or another key event, like when a user session starts In this scenario, you can listen to Symfony events such as |
Beta Was this translation helpful? Give feedback.
Hi Marvin,
Thank you for your question and for your kind words about the Multi-Tenancy Bundle.
To answer your question, yes, it is possible to centralize the tenant switch event (SwitchDbEvent) instead of dispatching it everywhere you need to create, edit, or delete tenant-specific entities. A common approach is to automatically switch the entity manager to the correct tenant database after a successful login or another key event, like when a user session starts
In this scenario, you can listen to Symfony events such as
security.interactive_login
orkernel.request
to dispatch the SwitchDbEvent with the appropriate tenant identifier. This way, whenever a user logs in or starts a new sessio…