DKNet.EfCore.DataAuthorization
10.0.2
dotnet add package DKNet.EfCore.DataAuthorization --version 10.0.2
NuGet\Install-Package DKNet.EfCore.DataAuthorization -Version 10.0.2
<PackageReference Include="DKNet.EfCore.DataAuthorization" Version="10.0.2" />
<PackageVersion Include="DKNet.EfCore.DataAuthorization" Version="10.0.2" />
<PackageReference Include="DKNet.EfCore.DataAuthorization" />
paket add DKNet.EfCore.DataAuthorization --version 10.0.2
#r "nuget: DKNet.EfCore.DataAuthorization, 10.0.2"
#:package DKNet.EfCore.DataAuthorization@10.0.2
#addin nuget:?package=DKNet.EfCore.DataAuthorization&version=10.0.2
#tool nuget:?package=DKNet.EfCore.DataAuthorization&version=10.0.2
DKNet.EfCore.DataAuthorization
A .NET library for secure, multi-tenant data authorization in Entity Framework Core. Enables automatic filtering of data based on ownership, supports DDD and API scenarios, and is designed for extensibility.
Features
- Automatic global query filtering based on data ownership keys
- Interfaces for associating entities with owners (
IOwnedBy), providing ownership keys (IDataOwnerProvider), and integrating with DbContext (IDataOwnerDbContext) - Extension methods for easy setup via dependency injection (
EfCoreDataAuthSetup) - Support for multi-tenancy and secure data isolation
- .NET 9.0 compatible
Installation
Add the NuGet package to your project:
dotnet add package DKNet.EfCore.DataAuthorization
Usage
Register the data authorization provider and setup in your DI container:
using Microsoft.Extensions.DependencyInjection;
using DKNet.EfCore.DataAuthorization;
services.AddAutoDataKeyProvider<MyDbContext, MyOwnerProvider>();
Implement IOwnedBy on your entities:
public class Document : IOwnedBy
{
public string? OwnedBy { get; private set; }
public void SetOwnedBy(string ownerKey) => OwnedBy = ownerKey;
}
Implement IDataOwnerProvider to supply ownership keys and accessible keys:
public class MyOwnerProvider : IDataOwnerProvider
{
public IEnumerable<string> GetAccessibleKeys() => ...; // e.g., from user context
public string GetOwnershipKey() => ...; // e.g., current user's tenant key
}
API
EfCoreDataAuthSetup.AddAutoDataKeyProvider<TDbContext, TProvider>(IServiceCollection): Registers automatic data key management for a DbContext.IOwnedBy: Interface for entities supporting ownership, with methods to get/set the owner key.IDataOwnerProvider: Interface for providing accessible keys and ownership key for new entities.IDataOwnerDbContext: Interface for DbContexts supporting data authorization, exposing accessible keys.
License
MIT © 2026 drunkcoding
Repository
https://github.com/baoduy/DKNet
Contributing
Pull requests and issues are welcome!
| 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.0.2)
- DKNet.EfCore.Hooks (>= 10.0.2)
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.0.2 | 24 | 11/20/2025 |
| 9.5.40 | 41 | 11/19/2025 |
| 9.5.39 | 253 | 11/13/2025 |
| 9.5.38 | 171 | 11/6/2025 |
| 9.5.37 | 170 | 11/5/2025 |
| 9.5.36 | 174 | 11/5/2025 |
| 9.5.35 | 178 | 11/4/2025 |
| 9.5.34 | 166 | 11/4/2025 |
| 9.5.33 | 175 | 11/3/2025 |
| 9.5.32 | 167 | 11/3/2025 |
| 9.5.31 | 149 | 10/31/2025 |
| 9.5.30 | 183 | 10/31/2025 |
| 9.5.29 | 179 | 10/30/2025 |
| 9.5.28 | 169 | 10/27/2025 |
| 9.5.27 | 165 | 10/27/2025 |
| 9.5.26 | 168 | 10/27/2025 |
| 9.5.25 | 163 | 10/26/2025 |
| 9.5.24 | 92 | 10/25/2025 |
| 9.5.23 | 88 | 10/25/2025 |
| 9.5.22 | 87 | 10/25/2025 |
| 9.5.21 | 147 | 10/24/2025 |
| 9.5.20 | 168 | 10/23/2025 |
| 9.5.19 | 155 | 10/23/2025 |
| 9.5.18 | 164 | 10/22/2025 |
| 9.5.17 | 193 | 10/17/2025 |
| 9.5.16 | 140 | 10/17/2025 |
| 9.5.15 | 181 | 10/15/2025 |
| 9.5.14 | 173 | 10/14/2025 |
| 9.5.13 | 166 | 10/14/2025 |
| 9.5.12 | 165 | 10/14/2025 |
| 9.5.11 | 172 | 10/14/2025 |
| 9.5.10 | 163 | 10/14/2025 |
| 9.5.9 | 158 | 10/13/2025 |
| 9.5.8 | 109 | 10/11/2025 |
| 9.5.7 | 114 | 10/10/2025 |
| 9.5.6 | 126 | 10/10/2025 |
| 9.5.5 | 126 | 10/10/2025 |
| 9.5.4 | 131 | 10/10/2025 |
| 9.5.3 | 192 | 10/8/2025 |
| 9.5.2 | 157 | 10/8/2025 |
| 9.5.1 | 186 | 10/7/2025 |
| 9.0.42 | 166 | 10/6/2025 |
| 9.0.41 | 184 | 10/2/2025 |
| 9.0.40 | 138 | 9/27/2025 |
| 9.0.39 | 151 | 9/26/2025 |
| 9.0.38 | 182 | 9/24/2025 |
| 9.0.37 | 161 | 9/23/2025 |
| 9.0.36 | 183 | 9/23/2025 |
| 9.0.35 | 164 | 9/23/2025 |
| 9.0.34 | 189 | 9/23/2025 |
| 9.0.33 | 173 | 9/21/2025 |
| 9.0.32 | 165 | 9/21/2025 |
| 9.0.31 | 276 | 9/19/2025 |
| 9.0.30 | 283 | 9/18/2025 |
| 9.0.29 | 268 | 9/18/2025 |
| 9.0.28 | 294 | 9/17/2025 |
| 9.0.27 | 291 | 9/17/2025 |
| 9.0.26 | 277 | 9/16/2025 |
| 9.0.25 | 244 | 9/15/2025 |
| 9.0.24 | 229 | 9/15/2025 |
| 9.0.23 | 130 | 9/6/2025 |
| 9.0.22 | 171 | 9/3/2025 |
| 9.0.21 | 152 | 9/1/2025 |
| 9.0.20 | 171 | 7/15/2025 |
| 9.0.19 | 166 | 7/14/2025 |
| 9.0.18 | 171 | 7/14/2025 |
| 9.0.17 | 163 | 7/14/2025 |
| 9.0.16 | 139 | 7/11/2025 |
| 9.0.15 | 138 | 7/11/2025 |
| 9.0.14 | 146 | 7/11/2025 |
| 9.0.13 | 159 | 7/11/2025 |
| 9.0.12 | 168 | 7/8/2025 |
| 9.0.11 | 158 | 7/8/2025 |
| 9.0.10 | 165 | 7/7/2025 |
| 9.0.9 | 157 | 7/2/2025 |
| 9.0.8 | 161 | 7/2/2025 |
| 9.0.7 | 175 | 7/1/2025 |
| 9.0.6 | 153 | 6/30/2025 |
| 9.0.5 | 162 | 6/24/2025 |
| 9.0.4 | 176 | 6/24/2025 |
| 9.0.3 | 146 | 6/23/2025 |
| 9.0.2 | 158 | 6/23/2025 |
| 9.0.1 | 154 | 6/23/2025 |
| 0.0.1 | 43 | 11/19/2025 |