-
-
Notifications
You must be signed in to change notification settings - Fork 269
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
Query returns no results and NullReferenceException #920
Comments
hello @Hulkstance, by any chance are you using minimal API's? This was happening to me because the tenant was not being resolved. In my case its because of the usage of minimal API's but there are many reasons this might be failing. If you are using minimal API's i created a middleware to handle this for me which I've provided below. public class TenantResolutionMiddleware(RequestDelegate next)
{
public async Task InvokeAsync(HttpContext httpContext, AppDbContext tenantStore)
{
var routeTenantId = httpContext.Request.RouteValues["tenantId"]?.ToString();
if (!string.IsNullOrEmpty(routeTenantId))
{
var tenantInfo = await tenantStore.AppTenantInfo.FindAsync(routeTenantId);
if (tenantInfo != null)
{
httpContext.SetTenantInfo(tenantInfo, true);
}
}
await next(httpContext);
}
} you will have to modify this to support the kind of store your using but this was much easier then moving from minimal API's back to controllers. |
@Hulkstance thanks for the detail you provided. I’m on vacation right now and will take a closer look next week. @funkel1989 thanks for chiming in |
Thank you for the replies! @AndrewTriesToCode, have a great one! @funkel1989, the The issue was with this call in var tenantInfo = await wrappedStore.TryGetByIdentifierAsync(identifier); It returned null because I had used It works fine now. However, I still wonder if I have implemented this part https://github.com/Hulkstance/multi-tenancy/blob/main/src/SharedDatabase.Infrastructure/Auth/Jwt/ConfigureJwtBearerOptions.cs#L59 and https://github.com/Hulkstance/multi-tenancy/blob/main/src/SharedDatabase.Infrastructure/MultiTenancy/CurrentTenantService.cs correctly. If @AndrewTriesToCode you could take a look whenever you get a chance |
Environment Details
Description
I'm implementing a shared database multi-tenancy sample project using the Finbuckle.MultiTenant library (GitHub). While setting it up, I encountered the following two issues:
Issue 1: Query Returns No Results
Despite having companies populated for a valid tenant (e.g.
tenant1
), no data is returned from the queries. Here are some screenshots for context:Issue 2: NullReferenceException for Invalid Tenant
When an invalid tenant identifier (e.g.
asd
) is passed, the application throws aNullReferenceException
.Screenshot:
Any thoughts on these issues? I could've debugged the source code myself, but I feel it’s better to ask this question at this point, as the documentation is somewhat outdated or limited in certain areas. I’d appreciate feedback on whether my implementation aligns with the intended usage.
Source Code
The text was updated successfully, but these errors were encountered: