Muonroi.Data.EntityFrameworkCore.Events 1.0.0-alpha.16

This is a prerelease version of Muonroi.Data.EntityFrameworkCore.Events.
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
                    
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.Events" 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.Events" Version="1.0.0-alpha.16" />
                    
Directory.Packages.props
<PackageReference Include="Muonroi.Data.EntityFrameworkCore.Events" />
                    
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.Events --version 1.0.0-alpha.16
                    
#r "nuget: Muonroi.Data.EntityFrameworkCore.Events, 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.Events@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.Events&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Muonroi.Data.EntityFrameworkCore.Events&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Tool

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.

NuGet License: Apache 2.0

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 persistenceMSagaDbContext auto-configures any IMuonroiSaga entity: CorrelationId PK, TenantId index, creation/modification timestamps stamped on every save
  • Transactional outboxMEventOutboxDbContext persists EventOutbox entries and a MessageInbox deduplication table inside the same EF Core transaction as business state
  • Mediator integrationMSagaDbContext requires IMediator; domain events raised during persistence flow through the Muonroi mediator pipeline
  • Design-time supportSharedDbContextFactory<TContext> resolves DatabaseConfigs from appsettings.json at 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 via MStringExtension.DecryptConfigurationValue
  • Tenant-aware — saga entities auto-inherit TenantId from 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, and IMuonroiSaga using an in-memory provider

Compatibility

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

License

Apache-2.0. See LICENSE-APACHE for details.

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 (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