DKNet.EfCore.DataAuthorization
10.1.15
dotnet add package DKNet.EfCore.DataAuthorization --version 10.1.15
NuGet\Install-Package DKNet.EfCore.DataAuthorization -Version 10.1.15
<PackageReference Include="DKNet.EfCore.DataAuthorization" Version="10.1.15" />
<PackageVersion Include="DKNet.EfCore.DataAuthorization" Version="10.1.15" />
<PackageReference Include="DKNet.EfCore.DataAuthorization" />
paket add DKNet.EfCore.DataAuthorization --version 10.1.15
#r "nuget: DKNet.EfCore.DataAuthorization, 10.1.15"
#:package DKNet.EfCore.DataAuthorization@10.1.15
#addin nuget:?package=DKNet.EfCore.DataAuthorization&version=10.1.15
#tool nuget:?package=DKNet.EfCore.DataAuthorization&version=10.1.15
DKNet.EfCore.DataAuthorization
Row-level, ownership-based data authorization for EF Core: an automatic global query filter plus a SaveChanges
hook, so multi-tenant or per-user data isolation is enforced by the persistence layer instead of by convention in
every query.
Install
dotnet add package DKNet.EfCore.DataAuthorization
Features
IOwnedBy— marker interface entities implement to opt into ownership-based filtering and stamping.- Automatic global query filter — every
IOwnedByentity is scoped toIDataOwnerDbContext.AccessibleKeysautomatically; deny-by-default when empty, with an explicitIsUnrestrictedAccessescape hatch for admin/system contexts. Not bypassable via specificationIsIgnoreQueryFilters. - Automatic ownership stamping — a
SaveChangeshook stamps the current owner key onto newly addedIOwnedByentities (andCreatedBy/CreatedOnwhen the entity is also audited), and reverts any attempt to silently reassign an existing row's owner to a key the caller can't access. - One DI call to wire it up —
AddDataOwnerProvider<TDbContext, TProvider>()registers the query filter, the hook, and yourIDataOwnerProviderimplementation together.TDbContextmust implementIDataOwnerDbContext; the requirement is compile-enforced by the method's generic constraint.
Quick start
public class Invoice : IOwnedBy
{
public string OwnedBy { get; private set; } = string.Empty;
}
public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options), IDataOwnerDbContext
{
public IEnumerable<string> AccessibleKeys { get; init; } = [];
protected override void OnModelCreating(ModelBuilder modelBuilder)
=> modelBuilder.UseAutoConfigModel(); // required for the global query filter to apply
}
public sealed class TenantOwnerProvider(ICurrentTenant currentTenant) : IDataOwnerProvider
{
public string? GetOwnershipKey() => currentTenant.TenantId;
}
services
.AddDataOwnerProvider<AppDbContext, TenantOwnerProvider>()
.AddDbContextWithHook<AppDbContext>(options => options.UseSqlServer(connectionString));
AddDataOwnerProvider<TDbContext, TProvider>() is declared where TDbContext : DbContext, IDataOwnerDbContext, so a
DbContext without the interface does not compile — and a context that reaches the query filter without it throws
InvalidOperationException at model-build time rather than quietly applying no ownership filter.
Full documentation, configuration options, and gotchas: DKNet.EfCore.DataAuthorization docs
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- DKNet.EfCore.Extensions (>= 10.1.15)
- DKNet.EfCore.Hooks (>= 10.1.15)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.1.15 | 32 | 9/1/2026 |
| 10.1.14 | 34 | 9/1/2026 |
| 10.1.13 | 72 | 8/31/2026 |
| 10.1.12 | 144 | 8/25/2026 |
| 10.1.11 | 92 | 8/24/2026 |
| 10.1.10 | 88 | 8/22/2026 |
| 10.1.9 | 99 | 8/22/2026 |
| 10.1.8 | 84 | 8/21/2026 |
| 10.1.7 | 104 | 8/21/2026 |
| 10.1.6 | 84 | 8/21/2026 |
| 10.1.5 | 92 | 8/20/2026 |
| 10.1.4 | 90 | 8/20/2026 |
| 10.1.3 | 93 | 8/19/2026 |
| 10.1.2 | 87 | 8/19/2026 |
| 10.1.1 | 91 | 8/19/2026 |
| 10.0.36 | 106 | 8/18/2026 |
| 10.0.35 | 109 | 8/5/2026 |
| 10.0.34 | 97 | 8/5/2026 |
| 10.0.33 | 102 | 8/4/2026 |
| 10.0.32 | 98 | 8/3/2026 |