Muonroi.Data.EntityFrameworkCore 1.0.0-alpha.16

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

Muonroi.Data.EntityFrameworkCore

EF Core infrastructure for Muonroi services: a batteries-included MDbContext with automatic audit timestamping, soft-delete, multi-tenant global query filters, domain-event dispatch, and a generic repository base.

NuGet License: Apache 2.0

Writing EF Core boilerplate — audit columns, soft-delete interceptors, tenant isolation filters, and transaction helpers — is repetitive across every service. This package provides MDbContext and MRepository<T> as drop-in bases that handle all of that automatically. Provider selection (SQL Server, PostgreSQL, MySQL, SQLite, MongoDB), permission sync, and authentication repositories are wired via a single AddDbContextConfigure<TDbContext, TPermission> extension.

Installation

dotnet add package Muonroi.Data.EntityFrameworkCore --prerelease

Quick Start

1. Define your context

Subclass MDbContext and add your application DbSet properties:

using Microsoft.EntityFrameworkCore;
using Muonroi.Data.EntityFrameworkCore.Entity;

public class AppDbContext(DbContextOptions<AppDbContext> options)
    : MDbContext(options)
{
    public DbSet<Order> Orders => Set<Order>();

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        // Wires audit/soft-delete/tenant filters for every entity, including Order.
        base.OnModelCreating(modelBuilder);

        modelBuilder.Entity<Order>(e => e.Property(x => x.Reference).HasMaxLength(64));
    }
}

2. Register via DI (production path)

AddDbContextConfigure reads DatabaseConfigs from appsettings.json, selects the correct provider, registers ITenantContext, IPermissionSyncService, auth repositories, and the license interceptor:

// Program.cs
builder.Services.AddDbContextConfigure<AppDbContext, AppPermission>(
    builder.Configuration);

appsettings.json:

{
  "DatabaseConfigs": {
    "DbType": "PostgreSql",
    "ConnectionStrings": {
      "PostgreSqlConnectionString": "Host=localhost;Database=app;..."
    }
  }
}

Supported DbType values: SqlServer, MySql, PostgreSql, Sqlite, MongoDb.

3. Use a repository

public class OrderService(MDbContext db)
{
    // MDbContext.Set<T>() is safe for core operations.
    // For a full repository, extend MRepository<T>.
}

public class OrderRepository(
    MDbContext dbContext,
    IAuthenticateInfoContext authContext,
    ILicenseGuard licenseGuard,
    IMDateTimeService dateTimeService)
    : MRepository<Order>(dbContext, authContext, licenseGuard, dateTimeService)
{
    public Task<int> CreateAsync(Order order) => AddBatchAsync([order]);
}

Features

  • Automatic audit stampingSaveChangesAsync sets CreationTime, CreatorUserId, LastModificationTime, LastModificationUserId, and Unix timestamp variants on every MEntity without any caller code.
  • Soft-deleteEntityState.Deleted is intercepted and converted to an IsDeleted = true update; deleted rows are filtered out of all queries automatically.
  • Multi-tenant global query filters — entities implementing ITenantScoped get an EF global filter keyed to TenantContext.CurrentTenantId; TenantContext.AllowCrossTenantAccess bypasses it for admin operations.
  • Domain-event dispatchSaveEntitiesAsync wraps save + IMediator.Publish in a resilient execution strategy; events are tracked via TrackEntity(MEntity).
  • Transaction helpersBeginTransactionAsync, CommitTransactionAsync, RollbackTransaction, and ExecuteTransactionAsync(Func<Task<MVoidMethodResult>>) simplify two-phase operations.
  • Multi-provider supportAddDbContextConfigure selects IDbContextConfigurator for SQL Server, PostgreSQL, MySQL, SQLite, or MongoDB based on configuration; no code changes needed to switch providers.
  • Permission sync — registers IPermissionSyncService and scans assemblies for IPermissionProvider implementations.
  • Authentication repositories — registers IAuthenticateRepository, IRefreshTokenValidator, and MAuthenticateTokenHelper<TPermission>.
  • Tenant quota management — opt-in via AddTenantQuotaManagement<TContext>() to register ITenantQuotaStore and ITenantQuotaTracker.
  • WebAuthn credential store — opt-in via AddEfWebAuthnCredentialStore().
  • Bulk insertMRepository<T>.BulkInsertAsync delegates to DbContext.BulkInsertAsync for high-throughput writes.
  • Encrypted connection strings — opt-in via EnableEncryption: true in configuration; decryption is performed inside ILicenseGuard.DecryptSecurely.

Configuration

appsettings.json structure

{
  "DatabaseConfigs": {
    "DbType": "SqlServer",
    "ConnectionStrings": {
      "SqlServerConnectionString": "Server=...;Database=...;...",
      "PostgreSqlConnectionString": "",
      "MySqlConnectionString": "",
      "SqliteConnectionString": "",
      "MongoDbConnectionString": ""
    }
  },
  "MultiTenantOptions": {
    "Enabled": true
  },
  "EnableEncryption": false
}

Optional extensions

// Tenant quota tracking (ITenantQuotaStore + ITenantQuotaTracker)
services.AddTenantQuotaManagement<AppDbContext>();

// WebAuthn credential store
services.AddEfWebAuthnCredentialStore();

// Permission provider assembly scan (called automatically by AddDbContextConfigure)
services.AddPermissionProviders(typeof(AppDbContext).Assembly);

API Reference

Type Purpose
MDbContext Base DbContext — audit, soft-delete, tenant filters, domain-event dispatch, transaction helpers; ships built-in DbSets for Identity entities
MDbContextBase<TContext> Lighter abstract base for schema-divergent multi-tenancy; no built-in Identity DbSets; override ConfigureSiteSpecific(ModelBuilder)
MRepository<T> Generic repository base for any MEntity; provides Add, AddBatchAsync, AddOrUpdateBatchAsync, UpdateAsync, UpdateBatchAsync, DeleteAsync, DeleteBatchAsync, BulkInsertAsync, SoftRestoreAsync, ExecuteTransactionAsync
MDbContextConfiguration (static) Hosts AddDbContextConfigure<TDbContext, TPermission> — the single DI entry point
TenantQuotaEfServiceCollectionExtensions (static) AddTenantQuotaManagement<TContext>
PermissionProviderExtensions (static) AddPermissionProviders(params Assembly[])
IDbContextConfigurator<T> Provider-specific configuration strategy (SQL Server / PostgreSQL / MySQL / SQLite / MongoDB implementations included)
IPermissionSyncService Syncs declared permissions to the database
EfTenantQuotaStore<TContext> EF implementation of ITenantQuotaStore

Samples

  • Quickstart.Data.EntityFrameworkCore — minimal ASP.NET Core API demonstrating MDbContext subclassing, audit timestamping, and soft-delete with the EF Core in-memory provider

Compatibility

  • Target framework: net8.0
  • License: Apache-2.0 (OSS)

License

Apache-2.0. See LICENSE-APACHE for the full text.

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 was computed.  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 was computed.  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 (9)

Showing the top 5 NuGet packages that depend on Muonroi.Data.EntityFrameworkCore:

Package Downloads
Muonroi.RuleEngine.DecisionTable

Decision table models, converters, validators, and serializers for Muonroi Rule Engine.

Muonroi.AspNetCore

ASP.NET Core integration: auto-CRUD controllers, middleware pipeline, license protection, and Muonroi hosting extensions.

Muonroi.Tenancy.SiteProfile.Web

ASP.NET Core middleware and SignalR hot-reload for Muonroi.Tenancy.SiteProfile.

Muonroi.RuleEngine.CEP

Complex Event Processing integration for Muonroi Rule Engine. Pattern-based event correlation and temporal windowing.

Muonroi.BuildingBlock.All

Metapackage for Muonroi Building Block - Includes all sub-packages for a complete infrastructure setup.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-alpha.16 85 6/22/2026
1.0.0-alpha.15 159 5/31/2026
1.0.0-alpha.14 157 5/15/2026
1.0.0-alpha.13 140 5/2/2026
1.0.0-alpha.12 91 4/2/2026
1.0.0-alpha.11 143 4/2/2026
1.0.0-alpha.9 82 3/30/2026
1.0.0-alpha.8 301 3/28/2026
1.0.0-alpha.7 70 3/27/2026
1.0.0-alpha.5 65 3/27/2026
1.0.0-alpha.4 70 3/27/2026
1.0.0-alpha.3 68 3/27/2026
1.0.0-alpha.2 70 3/26/2026
1.0.0-alpha.1 93 3/8/2026