-
-
Notifications
You must be signed in to change notification settings - Fork 266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Manually set tenant for new scope after migration to 7.0.1 version #844
Comments
I'm currently looking into this as well. My use case is that when processing a message from a queue, I want to set the specific tenant based on a specific message property. I've currently solved it as follows:
Then add it to DI as follows:
Then wherever you want to manually set the tenant, use this:
Mind that this solution currently abuses the fact that the Imho, the |
Edit: @robinabganpat beat me to the details above, thanks! Hi, I abstracted setting it behind var mtcSetter = context.RequestServices.GetRequiredService<IMultiTenantContextSetter>();
var resolver = context.RequestServices.GetRequiredService<ITenantResolver>();
var multiTenantContext = await resolver.ResolveAsync(context);
mtcSetter.MultiTenantContext = multiTenantContext; |
No problem. Thank you for creating this library. Given my comment:
What is your opinion on this and what is your idea behind the |
I like this change and it fits in with a new strategy I am adding that ‘HttpContextStrategy` that just takes a delegate taking http context and wraps the cast from object to http context so the user doesn’t need to worry about it. It could return null as you describe rather than an exception. Although the current checks that return exceptions only make sense in http context use cases. Which strategy are you using with a non http context that is throwing the exception? I’d like to learn more about your use case. |
I'm currently using the The TenantResolver just loops through the Strategies using the context that is given, so it doesn't know which Strategy is using the context as HttpContext or something else. I've now tackled this issue by first registering my custom Strategy before any HttpContext related strategy to prevent an Exception to be thrown in case it tries to resolve the tenant when a message is received from a queue. What also would be nice, if this behaviour would be configurable if you really want the strategy to throw an exception if it doesn't know what to do with the given context. This could be handy if you really want to force a strategy to be adhered to. |
Makes sense. I will prioritize this change. On Jun 26, 2024, at 1:21 AM, robinabganpat ***@***.***> wrote:
Although the current checks that return exceptions only make sense in http context use cases. Which strategy are you using with a non http context that is throwing the exception? I’d like to learn more about your use case.
I'm currently using the HeaderStrategy, which is a HttpContext use case, however in my use case I mix between a HttpContext use case and the use case mentioned above: A message is received from a queue, where a message property mentions the TenantIdentifier.
The TenantResolver just loops through the Strategies using the context that is given, so it doesn't know which Strategy is using the context as HttpContext or something else.
I've now tackled this issue by first registering my custom Strategy before any HttpContext related strategy to prevent an Exception to be thrown in case it tries to resolve the tenant when a message is received from a queue.
Although, it would be nice if the HeaderStrategy would just check whether the given context is a HttpContext and would 'skip' the strategy if it isn't, instead of throwing an exception.
What also would be nice, if this behaviour would be configurable if you really want the strategy to throw an exception if it doesn't know what to do with the given context. This could be handy if you really want to force a strategy to be adhered to.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: ***@***.***>
|
Hi, I updated the package to the 7.0.1 version and I have a question:
How do we set the tenant to the current scope?
in 6.. versions I use this approach:
but now it has become read-only:
The text was updated successfully, but these errors were encountered: