I have a multi-tenant app in which user can select "current company" after they log in. There is a DB per company but the model is the same, the workflow is the same, and the controller actions are same....The user can switch companies while being logged in and all actions need to be 'directed' to proper DB.

I know it is possible to customize context creation in EFContextProvider<T> by overriding CreateContext() but how do I pass the extra info (parameter, e.g. CompanyId) that would allow me to create context with correct connection string?

Is this possible?

有帮助吗?

解决方案

I find the easiest way is to include the tenant id in a custom HTTP header.

Because the tenant id changes during the session, you probably want to create a custom Breeze ajax adapter (wrap the one you're using now) that sets this header dynamically during its implementation of the ajax method.

On the server you fish the header out of the request.

MAKE SURE YOU ARE VALIDATING USER AND HEADER ON THE SERVER

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top