Muonroi.Data.EntityFrameworkCore
1.0.0-alpha.16
dotnet add package Muonroi.Data.EntityFrameworkCore --version 1.0.0-alpha.16
NuGet\Install-Package Muonroi.Data.EntityFrameworkCore -Version 1.0.0-alpha.16
<PackageReference Include="Muonroi.Data.EntityFrameworkCore" Version="1.0.0-alpha.16" />
<PackageVersion Include="Muonroi.Data.EntityFrameworkCore" Version="1.0.0-alpha.16" />
<PackageReference Include="Muonroi.Data.EntityFrameworkCore" />
paket add Muonroi.Data.EntityFrameworkCore --version 1.0.0-alpha.16
#r "nuget: Muonroi.Data.EntityFrameworkCore, 1.0.0-alpha.16"
#:package Muonroi.Data.EntityFrameworkCore@1.0.0-alpha.16
#addin nuget:?package=Muonroi.Data.EntityFrameworkCore&version=1.0.0-alpha.16&prerelease
#tool nuget:?package=Muonroi.Data.EntityFrameworkCore&version=1.0.0-alpha.16&prerelease
Muonroi.Data.EntityFrameworkCore
EF Core infrastructure for Muonroi services: a batteries-included
MDbContextwith automatic audit timestamping, soft-delete, multi-tenant global query filters, domain-event dispatch, and a generic repository base.
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 stamping —
SaveChangesAsyncsetsCreationTime,CreatorUserId,LastModificationTime,LastModificationUserId, and Unix timestamp variants on everyMEntitywithout any caller code. - Soft-delete —
EntityState.Deletedis intercepted and converted to anIsDeleted = trueupdate; deleted rows are filtered out of all queries automatically. - Multi-tenant global query filters — entities implementing
ITenantScopedget an EF global filter keyed toTenantContext.CurrentTenantId;TenantContext.AllowCrossTenantAccessbypasses it for admin operations. - Domain-event dispatch —
SaveEntitiesAsyncwraps save +IMediator.Publishin a resilient execution strategy; events are tracked viaTrackEntity(MEntity). - Transaction helpers —
BeginTransactionAsync,CommitTransactionAsync,RollbackTransaction, andExecuteTransactionAsync(Func<Task<MVoidMethodResult>>)simplify two-phase operations. - Multi-provider support —
AddDbContextConfigureselectsIDbContextConfiguratorfor SQL Server, PostgreSQL, MySQL, SQLite, or MongoDB based on configuration; no code changes needed to switch providers. - Permission sync — registers
IPermissionSyncServiceand scans assemblies forIPermissionProviderimplementations. - Authentication repositories — registers
IAuthenticateRepository,IRefreshTokenValidator, andMAuthenticateTokenHelper<TPermission>. - Tenant quota management — opt-in via
AddTenantQuotaManagement<TContext>()to registerITenantQuotaStoreandITenantQuotaTracker. - WebAuthn credential store — opt-in via
AddEfWebAuthnCredentialStore(). - Bulk insert —
MRepository<T>.BulkInsertAsyncdelegates toDbContext.BulkInsertAsyncfor high-throughput writes. - Encrypted connection strings — opt-in via
EnableEncryption: truein configuration; decryption is performed insideILicenseGuard.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
MDbContextsubclassing, audit timestamping, and soft-delete with the EF Core in-memory provider
Compatibility
- Target framework:
net8.0 - License: Apache-2.0 (OSS)
Related Packages
Muonroi.Data.Abstractions— contracts (IMRepository<T>,IMUnitOfWork,IMDataContext) implemented by this packageMuonroi.Core—MEntitybase class and core domain primitivesMuonroi.Tenancy.Core—ITenantContext,TenantContext,TenantSchemaSelectorused by the global query filtersMuonroi.EntityFrameworkCore.Configuration—DatabaseConfigsoptions type andDbTypesenumMuonroi.Data.Dapper— alternative Dapper-based data layer for raw SQL / Dapper workloads
License
Apache-2.0. See LICENSE-APACHE for the full text.
| Product | Versions 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. |
-
net8.0
- BCrypt.Net-Next (>= 4.1.0)
- Microsoft.EntityFrameworkCore (>= 8.0.24)
- Microsoft.EntityFrameworkCore.InMemory (>= 8.0.24)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.24)
- Microsoft.EntityFrameworkCore.Sqlite (>= 8.0.24)
- Microsoft.EntityFrameworkCore.SqlServer (>= 8.0.24)
- MongoDB.Driver (>= 3.4.0)
- Muonroi.Caching.Memory (>= 1.0.0-alpha.16)
- Muonroi.Core (>= 1.0.0-alpha.16)
- Muonroi.Core.Abstractions (>= 1.0.0-alpha.16)
- Muonroi.Data.Abstractions (>= 1.0.0-alpha.16)
- Muonroi.EntityFrameworkCore.Configuration (>= 1.0.0-alpha.16)
- Muonroi.Governance.Abstractions (>= 1.0.0-alpha.16)
- Muonroi.Mediator (>= 1.0.0-alpha.16)
- Muonroi.Messaging.Abstractions (>= 1.0.0-alpha.16)
- Muonroi.RuleEngine.Abstractions (>= 1.0.0-alpha.16)
- Muonroi.Tenancy.Core (>= 1.0.0-alpha.16)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 8.0.11)
- Pomelo.EntityFrameworkCore.MySql (>= 8.0.2)
- StackExchange.Redis (>= 2.8.37)
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 |