-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Configuration tenant resolver #23162
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
Configuration tenant resolver #23162
Conversation
|
hi
The multi-tenant middleware primarily obtains the tenant from the HTTP request, and the
Can you explain more about this case? Thanks. |
The For non-HTTP scenarios (e.g. console apps, workers), tenant resolution is still possible manually using the Since non-HTTP scenarios are rare and not officially supported at the moment, related documentation will be removed. If needed in the future, a dedicated resolver can still be implemented and invoked manually. |
|
hi These For example, you can add a query string or cookies to change the current tenant. It's very easy. QueryStringTenantResolveContributor
RouteTenantResolveContributor
HeaderTenantResolveContributor
CookieTenantResolveContributorIf we really need a default tenant, We can add an Then we can configure the options. which also support get value from The QueryStringTenantResolveContributor
RouteTenantResolveContributor
HeaderTenantResolveContributor
CookieTenantResolveContributor
DefaultTenantResolveContributorThanks. |
|
The case where I used So I conditionally register the configuration resolver like this: if (env.IsDevelopment())
{
options.TenantResolvers.InsertAfter(
r => r is CurrentUserTenantResolveContributor,
new ConfigurationTenantResolveContributor()
);
}
else
{
options.AddDomainTenantResolver(configuration["App:Wildcard"]!);
options.TenantResolvers.InsertBefore(
r => r is DomainTenantResolveContributor,
new CustomHostnameTenantResolveContributor()
);
}I agree that it may not be suitable to include this as a default resolver in If this is considered too specific for the framework, I’m okay with removing it and instead write a small article to demonstrate how developers can handle this pattern manually when needed — or I can contribute a |
|
Hi @maliming I went ahead and pushed the implementation before your response — wanted to proactively address the scenario, especially for local development where domain-based resolution isn’t always practical. If you think this doesn’t align with the core framework direction, I’m okay with shifting it to an article community post instead. Just let me know your take. |
hikalkan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we add this to AbpAspNetCoreMultiTenancyOptions, only ASP.NET Core apps can use this, not console and other apps.
My suggestion:
Introduce string AbpTenantResolveOptions.FallbackTenant property.
In TenantResolver.ResolveTenantIdOrNameAsync method, just before the return result; statement, set result.TenantIdOrName if FallbackTenant was not null or empty.
In this way, it will be backward compatible and usable in any scenario. Please also update the documentation.
Thanks , @hikalkan That was actually the idea from the beginning — to solve the local dev scenario using a configuration-based resolver. But I agree that having a I’ll proceed with your suggestion and update the implementation and documentation accordingly. |
|
Thanks @suhaib-mousa |
|
The implementation is fine, thanks. But I will revise the documentation part. Then we can merge @maliming |
|
I will separately update the doc. |
|
Updated: 8fdc5c1 |
Adds a new tenant resolve contributor that resolves the tenant ID or name
from appsettings.json, under the key:
"MultiTenancy:Tenant"