Hello,
this issue is somewhat related to #14625 but I'd like to suggest something slightly different.
Basically, I need global filter values to be resolved on a per-request basis, even if the DbContext instance comes from the pool. Please, let's not discuss performance gains here, like in #14625, and just assume my app DOES benefit from using the pool.
Here's my suggestion for a new overload of the HasQueryFilter API.
First, I'd register a global filter in the OnModelCreating like this. Please note no actual value is provided here, but just a link between the TenantId property of an entity class and a string identifier such as "TenantId".
modelBuilder.Entity<Product>().HasQueryFilter(p => p.TenantId, "TenantId");
Then, each time a DbContext is needed (e.g. user sending a request), the identifier "TenantId" has to be resolved to an actual value. So, I would need to add a method to the DbContext to do just that. Maybe marked by an atttribute such as GlobalFilterResolverAttribute. Please note this method must be dependency injection enabled so I can get a reference to scoped services like the ITenantProvider here.
[GlobalFilterResolver("TenantId")]
protected object ResolveTenantId(ITenantProvider provider)
{
return provider.GetTenantId();
}
What do you think?
Thanks for your attention.
Moreno
Hello,
this issue is somewhat related to #14625 but I'd like to suggest something slightly different.
Basically, I need global filter values to be resolved on a per-request basis, even if the
DbContextinstance comes from the pool. Please, let's not discuss performance gains here, like in #14625, and just assume my app DOES benefit from using the pool.Here's my suggestion for a new overload of the
HasQueryFilterAPI.First, I'd register a global filter in the
OnModelCreatinglike this. Please note no actual value is provided here, but just a link between theTenantIdproperty of an entity class and a string identifier such as "TenantId".Then, each time a DbContext is needed (e.g. user sending a request), the identifier "TenantId" has to be resolved to an actual value. So, I would need to add a method to the
DbContextto do just that. Maybe marked by an atttribute such asGlobalFilterResolverAttribute. Please note this method must be dependency injection enabled so I can get a reference to scoped services like theITenantProviderhere.What do you think?
Thanks for your attention.
Moreno