Tenantry CoreAPI reference
TenantBuilderEfCoreExtensions class
Namespace: Tenantry.EfCore.Extensions · Package: Tenantry.EfCore · API reference
Extension methods for configuring EF Core tenant isolation on ITenantBuilder<TKey>.
public static class TenantBuilderEfCoreExtensionsMethods
AddEfCoreIsolation<TKey>(ITenantBuilder<TKey>, Action<EfCoreIsolationOptions>?)
Registers EF Core tenant isolation services (the SaveChanges interceptor and the configured isolation policy). Call this inside your AddTenantry configuration lambda.
public static ITenantBuilder<TKey> AddEfCoreIsolation<TKey>(this ITenantBuilder<TKey> builder, Action<EfCoreIsolationOptions>? configure = null) where TKey : IEquatable<TKey>, IParsable<TKey>Type parameters:
TKey: The tenant identifier type.
Parameters:
builderITenantBuilder<TKey>: The tenant builder.configureAction<EfCoreIsolationOptions>: Sets the isolation options, such as what happens to a write without a tenant, or null for the defaults.
Returns: ITenantBuilder<TKey>
builder.Services.AddTenantry<Guid>(tenant =>
{
tenant.ResolveFromHeader("X-Tenant-Id");
tenant.UseInMemoryStore(tenants);
tenant.AddEfCoreIsolation(options =>
{
options.OnMissingTenant = MissingTenantBehavior.Reject;
options.DetectSpoofedWrites = true;
});
});