Finbuckle / Finbuckle.MultiTenant

Finbuckle.MultiTenant is an open-source multitenancy middleware library for .NET. It enables tenant resolution, per-tenant app behavior, and per-tenant data isolation.
https://www.finbuckle.com/multitenant
Apache License 2.0
1.26k stars 256 forks source link

TenantInfo null in AppDbContext, getting exception - Finbuckle.MultiTenant.MultiTenantException: 'MultiTenant Entity cannot be changed if TenantInfo is null.' #846

Open PiyushKumar19 opened 1 week ago

PiyushKumar19 commented 1 week ago

I'm trying to implement multi-tenancy by saving and fetching tenants from the database. For that, I created a custom store and registered it in the Program.cs . I've also injected IMultiTenantContextAccessor in AppDbContext.

When I try to make any request for an entity that has IsMultiTenant applied to it, the _multiTenantContextAccessor.MultiTenantContext.TenantInfo gets initialized as null in the AppDbContext constructor, which stays as null until the code execution passes through the Custom store from where it fetches the Tenant from the database (it stays null there also), TenantInfo gets Db fetched tenant data only after executing the Controller constructor.

It does not set the TenantInfo globally with the tenant data fetched from the Db from the custom store.

Here's the repo link - https://github.com/PiyushKumar19/BuckleUp

Please ignore those middlewares and ContextFactory classes, they're not being used anywhere.