-
-
Notifications
You must be signed in to change notification settings - Fork 271
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
BasePathStrategy is not respecting the strategy chain order when setted with WithBasePathStrategy builder method #877
Comments
Proposed fix: public static MultiTenantBuilder<TTenantInfo> WithBasePathStrategy<TTenantInfo>(
this MultiTenantBuilder<TTenantInfo> builder, Action<BasePathStrategyOptions> configureOptions)
where TTenantInfo : class, ITenantInfo, new()
{
builder.Services.Configure(configureOptions);
builder.Services.Configure<MultiTenantOptions>(options =>
{
var origOnTenantResolved = options.Events.OnTenantResolved;
options.Events.OnTenantResolved = tenantResolvedContext =>
{
if (tenantResolvedContext.StrategyType == typeof(BasePathStrategy))
{
var httpContext = tenantResolvedContext.Context as HttpContext ??
throw new MultiTenantException("BasePathStrategy expects HttpContext.");
if (httpContext.RequestServices.GetRequiredService<IOptions<BasePathStrategyOptions>>().Value
.RebaseAspNetCorePathBase)
{
httpContext.Request.Path.StartsWithSegments($"/{tenantResolvedContext.TenantInfo?.Identifier}",
out var matched, out var
newPath);
httpContext.Request.PathBase = httpContext.Request.PathBase.Add(matched);
httpContext.Request.Path = newPath;
}
}
return origOnTenantResolved(tenantResolvedContext);
};
});
return builder.WithStrategy<BasePathStrategy>(ServiceLifetime.Singleton);
} It worked for me and seems perfectly fine! |
Thanks for flagging. I will be removing fixing this in the upcoming release. |
🎉 This issue has been resolved in version 8.0.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steps to reproduce
BasePathStrategy
with theWithBasePathStrategy
builder methodMultiTenantException
with the following message: "BasePathStrategy expects HttpContext."My code:
Calling WithBasePathStrategy will not respect the chain of strategies because there are some checks regarding HttpContext that are being done, even if the previous strategy is resolved (in this case it is my custom ForcedTenantStrategy).
Please, check the following code:
https://github.com/Finbuckle/Finbuckle.MultiTenant/blob/main/src/Finbuckle.MultiTenant.AspNetCore/Extensions/MultiTenantBuilderExtensions.cs#L224C35-L224C106
Expected behaviour
These checks that are made because of the
BasePathStrategy
register process (during theOnTenantResolved
delegate registration), but should should only be made if the strategy type isBasePathStrategy
The text was updated successfully, but these errors were encountered: