DKNet.EfCore.DataAuthorization 10.0.3

dotnet add package DKNet.EfCore.DataAuthorization --version 10.0.3
                    
NuGet\Install-Package DKNet.EfCore.DataAuthorization -Version 10.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DKNet.EfCore.DataAuthorization" Version="10.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DKNet.EfCore.DataAuthorization" Version="10.0.3" />
                    
Directory.Packages.props
<PackageReference Include="DKNet.EfCore.DataAuthorization" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DKNet.EfCore.DataAuthorization --version 10.0.3
                    
#r "nuget: DKNet.EfCore.DataAuthorization, 10.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DKNet.EfCore.DataAuthorization@10.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DKNet.EfCore.DataAuthorization&version=10.0.3
                    
Install as a Cake Addin
#tool nuget:?package=DKNet.EfCore.DataAuthorization&version=10.0.3
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.3 256 11/21/2025
10.0.2 330 11/20/2025
9.5.40 336 11/19/2025
9.5.39 256 11/13/2025
9.5.38 174 11/6/2025
9.5.37 171 11/5/2025
9.5.36 175 11/5/2025
9.5.35 179 11/4/2025
9.5.34 168 11/4/2025
9.5.33 179 11/3/2025
9.5.32 171 11/3/2025
9.5.31 152 10/31/2025
9.5.30 186 10/31/2025
9.5.29 182 10/30/2025
9.5.28 170 10/27/2025
9.5.27 166 10/27/2025
9.5.26 169 10/27/2025
9.5.25 164 10/26/2025
9.5.24 93 10/25/2025
9.5.23 89 10/25/2025
9.5.22 88 10/25/2025
9.5.21 148 10/24/2025
9.5.20 169 10/23/2025
9.5.19 156 10/23/2025
9.5.18 165 10/22/2025
9.5.17 194 10/17/2025
9.5.16 141 10/17/2025
9.5.15 182 10/15/2025
9.5.14 174 10/14/2025
9.5.13 167 10/14/2025
9.5.12 166 10/14/2025
9.5.11 173 10/14/2025
9.5.10 164 10/14/2025
9.5.9 159 10/13/2025
9.5.8 110 10/11/2025
9.5.7 115 10/10/2025
9.5.6 127 10/10/2025
9.5.5 127 10/10/2025
9.5.4 132 10/10/2025
9.5.3 193 10/8/2025
9.5.2 158 10/8/2025
9.5.1 187 10/7/2025
9.0.42 167 10/6/2025
9.0.41 185 10/2/2025
9.0.40 139 9/27/2025
9.0.39 152 9/26/2025
9.0.38 183 9/24/2025
9.0.37 162 9/23/2025
9.0.36 184 9/23/2025
9.0.35 165 9/23/2025
9.0.34 190 9/23/2025
9.0.33 174 9/21/2025
9.0.32 166 9/21/2025
9.0.31 277 9/19/2025
9.0.30 284 9/18/2025
9.0.29 269 9/18/2025
9.0.28 295 9/17/2025
9.0.27 292 9/17/2025
9.0.26 278 9/16/2025
9.0.25 246 9/15/2025
9.0.24 230 9/15/2025
9.0.23 131 9/6/2025
9.0.22 172 9/3/2025
9.0.21 153 9/1/2025
9.0.20 172 7/15/2025
9.0.19 167 7/14/2025
9.0.18 172 7/14/2025
9.0.17 164 7/14/2025
9.0.16 140 7/11/2025
9.0.15 139 7/11/2025
9.0.14 147 7/11/2025
9.0.13 160 7/11/2025
9.0.12 169 7/8/2025
9.0.11 159 7/8/2025
9.0.10 166 7/7/2025
9.0.9 158 7/2/2025
9.0.8 162 7/2/2025
9.0.7 176 7/1/2025
9.0.6 154 6/30/2025
9.0.5 163 6/24/2025
9.0.4 177 6/24/2025
9.0.3 147 6/23/2025
9.0.2 159 6/23/2025
9.0.1 155 6/23/2025
0.0.1 339 11/19/2025