OrionLedger.EntityFrameworkCore 0.5.0

dotnet add package OrionLedger.EntityFrameworkCore --version 0.5.0
                    
NuGet\Install-Package OrionLedger.EntityFrameworkCore -Version 0.5.0
                    
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="OrionLedger.EntityFrameworkCore" Version="0.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OrionLedger.EntityFrameworkCore" Version="0.5.0" />
                    
Directory.Packages.props
<PackageReference Include="OrionLedger.EntityFrameworkCore" />
                    
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 OrionLedger.EntityFrameworkCore --version 0.5.0
                    
#r "nuget: OrionLedger.EntityFrameworkCore, 0.5.0"
                    
#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 OrionLedger.EntityFrameworkCore@0.5.0
                    
#: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=OrionLedger.EntityFrameworkCore&version=0.5.0
                    
Install as a Cake Addin
#tool nuget:?package=OrionLedger.EntityFrameworkCore&version=0.5.0
                    
Install as a Cake Tool

OrionLedger.EntityFrameworkCore

NuGet

An Entity Framework Core reference store for OrionLedger. It implements IApiKeyStore over EF Core so issued keys survive a restart and are shared across instances, instead of living in the process-local in-memory store.

Part of the Orion family.

What it does

  • Maps ApiKeyRecord to a relational table through ApiKeyRecordConfiguration, with the token hash uniquely indexed (it is the verification lookup key, so lookups are an index seek) and the subject indexed (it backs bulk revoke).
  • Persists every mutable lifecycle field: RevokedAt, LastUsedAt, LastUsedCount, and the rotation timestamps (SupersededAt, SupersededById, RetiresAt).
  • Increments last-used atomically. A successful verify applies LastUsedCount = LastUsedCount + 1 as a server-side update, so two concurrent verifications both land their increment rather than racing on a read-modify-write and losing a count.
  • Ships FindBySubjectAsync, so RevokeAllForSubjectAsync (bulk revoke by owner) works out of the box.
  • Provider agnostic: depends only on Microsoft.EntityFrameworkCore.Relational, so you choose the database provider (SQL Server, PostgreSQL, SQLite, and so on).

Install

dotnet add package OrionLedger.EntityFrameworkCore

You also need an EF Core provider package for your database, for example Microsoft.EntityFrameworkCore.SqlServer or Npgsql.EntityFrameworkCore.PostgreSQL.

Quick start

Register the store before AddOrionLedger(), configuring the context inline. The bundled OrionLedgerDbContext is ready to use:

using Moongazing.OrionLedger.EntityFrameworkCore;

// Register the EF store first: AddOrionLedger only adds the in-memory store if no IApiKeyStore
// is already present. This also registers a pooled context factory the store resolves a
// short-lived context from per operation.
builder.Services.AddOrionLedgerEntityFrameworkCoreStore<OrionLedgerDbContext>(o =>
    o.UseSqlServer(builder.Configuration.GetConnectionString("Keys")));

builder.Services.AddOrionLedger(o => o.Prefix = "ork_live_");

That is all the wiring the lifecycle needs: IssueAsync, VerifyAsync, RotateAsync, RevokeAsync, and RevokeAllForSubjectAsync now persist through EF Core.

The store opens its own context per operation, so a single registration is safe under concurrent verifications. If you already register an IDbContextFactory<TContext> yourself, call the parameterless AddOrionLedgerEntityFrameworkCoreStore<TContext>() overload instead.

Using your own DbContext

If you already have a context, host the key table in it by applying the configuration in OnModelCreating, then point the store at that context:

public sealed class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
{
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.ApplyConfiguration(new ApiKeyRecordConfiguration());
        // ... your own entities
    }
}

builder.Services.AddOrionLedgerEntityFrameworkCoreStore<AppDbContext>();

ApiKeyRecordConfiguration also accepts a custom table name if the default OrionLedgerApiKeys clashes with an existing table.

Migrations

The store does not create the schema. Add a migration for the mapped entity the usual way and apply it as part of your deployment:

dotnet ef migrations add AddOrionLedgerApiKeys
dotnet ef database update

Concurrency note

LastUsedCount is exact under this store, not best-effort: the increment is applied in the database, so concurrent verifications do not lose counts. The remaining lifecycle fields (revocation and rotation timestamps) are last-writer-wins, which matches their intent: revoking an already-revoked key or re-stamping a rotation is idempotent.

Versioning

Multi-targets net8.0, net9.0, and net10.0, pinning the matching EF Core major per target framework. Tracks the OrionLedger version line. See the root README and CHANGELOG.

License

Licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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
0.5.0 129 7/28/2026
0.4.0 114 7/20/2026