Finbuckle.MultiTenant
Finbuckle.MultiTenant copied to clipboard
Feature Request: AddInterceptors for Shared Database
Add support for https://docs.microsoft.com/en-us/ef/core/logging-events-diagnostics/interceptors
Today, when using Data Isolation with Entity Framework Core - Shared Database, we have two options:
- Implement IMultiTenantDbContext and used the helper methods as described here, or
- Derive from MultiTenantDbContext which handles the details for you.
It would be nice for a third options:
public class MyContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.AddInterceptors(new MultiTenantInterceptor());
}
// ...
}
or in Startup.cs:
var options = new DbContextOptionsBuilder()
.AddInterceptors(new MultiTenantInterceptor())
.UseSqlServer(...)
.Options;
using (var ctx = new MyContext(options))
{
// ...
}
Thanks for the suggestion. Seems like a good alternative method.
Well the cool thing about it is you can register multiple, and you don't have to inherit anything or override save changes.
For example when using something like this https://github.com/thepirat000/Audit.NET/tree/master/src/Audit.EntityFramework#3-with-the-provided-save-changes-interceptor
Then I'd just have to register a couple interceptors and be done.