Muonroi.Data.EntityFrameworkCore.Events
1.0.0-alpha.16
dotnet add package Muonroi.Data.EntityFrameworkCore.Events --version 1.0.0-alpha.16
NuGet\Install-Package Muonroi.Data.EntityFrameworkCore.Events -Version 1.0.0-alpha.16
<PackageReference Include="Muonroi.Data.EntityFrameworkCore.Events" Version="1.0.0-alpha.16" />
<PackageVersion Include="Muonroi.Data.EntityFrameworkCore.Events" Version="1.0.0-alpha.16" />
<PackageReference Include="Muonroi.Data.EntityFrameworkCore.Events" />
paket add Muonroi.Data.EntityFrameworkCore.Events --version 1.0.0-alpha.16
#r "nuget: Muonroi.Data.EntityFrameworkCore.Events, 1.0.0-alpha.16"
#:package Muonroi.Data.EntityFrameworkCore.Events@1.0.0-alpha.16
#addin nuget:?package=Muonroi.Data.EntityFrameworkCore.Events&version=1.0.0-alpha.16&prerelease
#tool nuget:?package=Muonroi.Data.EntityFrameworkCore.Events&version=1.0.0-alpha.16&prerelease
Muonroi.Data.EntityFrameworkCore.Events
Adds event dispatch, transactional outbox persistence, and saga support on top of
Muonroi.Data.EntityFrameworkCore— the mediator and messaging layer you reach for when your EF Core context needs to publish domain events and coordinate long-running processes.
Muonroi.Data.EntityFrameworkCore.Events extends the persistence-only core with two complementary patterns: a transactional outbox (MEventOutboxDbContext) that stores domain events atomically with business state, and saga persistence (MSagaDbContext) that tracks long-running process state keyed by CorrelationId with automatic tenant stamping. Both are wired through Muonroi.Mediator so domain events raised during SaveChangesAsync are dispatched via the same pipeline as the rest of the application.
Installation
dotnet add package Muonroi.Data.EntityFrameworkCore.Events --prerelease
Quick Start
Register the Muonroi mediator first (required by MSagaDbContext), then call AddMuonroiSagaDbContext<TContext> with your concrete context:
using Microsoft.EntityFrameworkCore;
using Muonroi.Data.EntityFrameworkCore.Extensions;
using Muonroi.Mediator.Mediator;
// 1. Register the mediator (required — MSagaDbContext dispatches domain events through it)
builder.Services.AddMMediator();
// 2. Register your saga context
builder.Services.AddMuonroiSagaDbContext<OrderSagaDbContext>(options =>
options.UseSqlServer(connectionString));
Define your saga state by implementing IMuonroiSaga and derive your context from MSagaDbContext:
using Muonroi.Messaging.Abstractions.Contracts;
public class OrderSaga : IMuonroiSaga
{
public Guid CorrelationId { get; set; }
public string? TenantId { get; set; }
public DateTime CreationTime { get; set; }
public DateTime? LastModificationTime { get; set; }
// your domain fields
public string State { get; set; } = "Pending";
public decimal Amount { get; set; }
}
public class OrderSagaDbContext(
DbContextOptions options,
IMediator mediator,
ILicenseGuard? licenseGuard = null,
IMLog<MDbContext>? logger = null,
IMDateTimeService? dateTimeService = null,
ISystemExecutionContextAccessor? executionContextAccessor = null)
: MSagaDbContext(options, mediator, licenseGuard, logger, dateTimeService, executionContextAccessor)
{
public DbSet<OrderSaga> OrderSagas => Set<OrderSaga>();
}
MSagaDbContext.OnModelCreating discovers every IMuonroiSaga entity automatically, sets CorrelationId as the primary key, and adds an index on TenantId. SaveChangesAsync stamps CreationTime / LastModificationTime and injects the ambient TenantId from ISystemExecutionContextAccessor on new entries.
Features
- Saga persistence —
MSagaDbContextauto-configures anyIMuonroiSagaentity:CorrelationIdPK,TenantIdindex, creation/modification timestamps stamped on every save - Transactional outbox —
MEventOutboxDbContextpersistsEventOutboxentries and aMessageInboxdeduplication table inside the same EF Core transaction as business state - Mediator integration —
MSagaDbContextrequiresIMediator; domain events raised during persistence flow through the Muonroi mediator pipeline - Design-time support —
SharedDbContextFactory<TContext>resolvesDatabaseConfigsfromappsettings.jsonat migration time; supports SQL Server, MySQL, PostgreSQL, and SQLite - Multi-provider — design-time factory selects the provider branch from
DatabaseConfigs:DbType; connection strings are decrypted viaMStringExtension.DecryptConfigurationValue - Tenant-aware — saga entities auto-inherit
TenantIdfrom the ambient execution context when not explicitly set
Configuration
Register via AddMuonroiSagaDbContext<TContext> from Muonroi.Data.EntityFrameworkCore.Extensions:
builder.Services.AddMMediator(); // required
builder.Services.AddMuonroiSagaDbContext<OrderSagaDbContext>(opts =>
opts.UseNpgsql(builder.Configuration.GetConnectionString("Default")));
For the design-time factory (dotnet ef migrations add), add the following section to appsettings.json:
{
"DatabaseConfigs": {
"DbType": "SqlServer",
"ConnectionStrings": {
"SqlServerConnectionString": "<your-connection-string>"
}
}
}
Supported DbType values: SqlServer, MySql, PostgreSql, Sqlite.
API Reference
| Type | Purpose |
|---|---|
MSagaDbContext |
Abstract base context for saga state; auto-configures IMuonroiSaga entities (PK, index, timestamps) and dispatches domain events via IMediator |
MEventOutboxDbContext |
Concrete outbox context exposing DbSet<EventOutbox> and DbSet<MessageInbox>; implements IEventOutboxStore |
IMuonroiSaga |
Contract (from Muonroi.Messaging.Abstractions) all saga state classes must implement; defines CorrelationId, TenantId, and timestamp fields |
IEventOutboxStore |
Contract (from Muonroi.Messaging.Abstractions) for querying and appending EventOutbox entries |
MessageInbox |
Entity for at-least-once deduplication; keyed by MessageId + ConsumerName |
SharedDbContextFactory<TContext> |
IDesignTimeDbContextFactory<TContext> implementation; reads DatabaseConfigs from appsettings.json at migration time |
MuonroiSagaServiceCollectionExtensions |
Provides AddMuonroiSagaDbContext<TContext>(IServiceCollection, Action<DbContextOptionsBuilder>) |
Samples
- Quickstart.Data.Events — minimal ASP.NET Core API demonstrating
AddMuonroiSagaDbContext,MSagaDbContext, andIMuonroiSagausing an in-memory provider
Compatibility
- Target framework:
net8.0 - License: Apache-2.0 (OSS)
Related Packages
Muonroi.Data.EntityFrameworkCore— persistence-only core (MDbContext); this package builds on top of itMuonroi.Messaging.Abstractions— definesIMuonroiSaga,IEventOutboxStore, andEventOutboxMuonroi.Mediator— providesIMediatorandAddMMediator; required for domain-event dispatch
License
Apache-2.0. See LICENSE-APACHE for details.
| 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
- Muonroi.Data.EntityFrameworkCore (>= 1.0.0-alpha.16)
- Muonroi.Mediator (>= 1.0.0-alpha.16)
- Muonroi.Messaging.Abstractions (>= 1.0.0-alpha.16)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Muonroi.Data.EntityFrameworkCore.Events:
| Package | Downloads |
|---|---|
|
Muonroi.BuildingBlock.All
Metapackage for Muonroi Building Block - Includes all sub-packages for a complete infrastructure setup. |
|
|
Muonroi.Messaging.MassTransit
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-alpha.16 | 55 | 6/22/2026 |
| 1.0.0-alpha.15 | 103 | 5/31/2026 |
| 1.0.0-alpha.14 | 89 | 5/15/2026 |
| 1.0.0-alpha.13 | 76 | 5/2/2026 |
| 1.0.0-alpha.12 | 73 | 4/2/2026 |
| 1.0.0-alpha.11 | 127 | 4/2/2026 |
| 1.0.0-alpha.8 | 153 | 3/28/2026 |