MiCake.EntityFrameworkCore
11.0.0-preview.12
Prefix Reserved
See the version list below for details.
dotnet add package MiCake.EntityFrameworkCore --version 11.0.0-preview.12
NuGet\Install-Package MiCake.EntityFrameworkCore -Version 11.0.0-preview.12
<PackageReference Include="MiCake.EntityFrameworkCore" Version="11.0.0-preview.12" />
<PackageVersion Include="MiCake.EntityFrameworkCore" Version="11.0.0-preview.12" />
<PackageReference Include="MiCake.EntityFrameworkCore" />
paket add MiCake.EntityFrameworkCore --version 11.0.0-preview.12
#r "nuget: MiCake.EntityFrameworkCore, 11.0.0-preview.12"
#:package MiCake.EntityFrameworkCore@11.0.0-preview.12
#addin nuget:?package=MiCake.EntityFrameworkCore&version=11.0.0-preview.12&prerelease
#tool nuget:?package=MiCake.EntityFrameworkCore&version=11.0.0-preview.12&prerelease
MiCake.EntityFrameworkCore
Entity Framework Core integration for the MiCake DDD toolkit.
Overview
MiCake.EntityFrameworkCore provides EF Core support for MiCake:
- MiCakeDbContext - Enhanced DbContext with DDD support
- Repository Implementation - Auto-generated repositories
- Unit of Work - Transaction management with EF Core
- Store Conventions - Automatic entity configuration
- Domain Event Dispatch - Events triggered on SaveChanges
Installation
dotnet add package MiCake.EntityFrameworkCore
Quick Start
// Inherit from MiCakeDbContext
public class AppDbContext : MiCakeDbContext
{
public DbSet<Order> Orders { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder); // Required!
// Your configurations...
}
}
Automatic Write Pipeline (Interceptors)
The write pipeline (write guard, transaction binding, and save lifecycle) is installed
automatically for every DbContext registered in the container: the MiCake EF Core
module registers an IDbContextOptionsConfiguration<TContext> configurator
(ConfigureDbContext) that attaches the interceptors and the UseMiCake() options for
you. No interceptor-install API call is required:
// Register the DbContext in the container — that is all.
services.AddDbContext<AppDbContext>(opt => opt.UseSqlite(connectionString));
- Permissive policy: a direct DbContext write without an ambient writable unit of work passes through with native EF Core semantics (e.g. implicit transaction). Guards, transaction binding, and lifecycle processing apply only when an ambient writable unit of work is active. MiCake never interferes with vanilla EF usage.
- Inside a unit of work, every write is guarded and transaction-bound: the first
SaveChanges,ExecuteUpdate/ExecuteDelete, and raw SQL command executes inside the active unit-of-work transaction. - Inheriting
MiCakeDbContextis optional — plainDbContexttypes registered in the container get the same pipeline through the configurator.UseMiCake()remains the options-level entry forOnConfiguringscenarios.
Key Features
| Feature | Description |
|---|---|
MiCakeDbContext |
Base DbContext with DDD integration |
IRepository<T, TKey> |
Auto-implemented repository |
IEFSaveChangesLifetime |
SaveChanges lifecycle hooks |
IEFCorePhysicalOperationExecutor |
Explicit lifecycle-bypassing physical operations |
Repository and Persistence Ownership
Repositories never save or commit independently. Mutations are tracked on the stable context bound to the ambient unit of work; the unit of work is the sole persistence owner:
public class BookService
{
private readonly IRepository<Book, Guid> _bookRepository;
private readonly IUnitOfWorkManager _uowManager;
public async Task ChangeAuthorAsync(Guid bookId, string author)
{
using var uow = await _uowManager.BeginAsync();
var book = await _bookRepository.FindAsync(bookId);
book.ChangeAuthor(author);
// No repository save call: the unit of work commits the tracked changes
await uow.CommitAsync();
}
}
AddAsync/UpdateAsync/DeleteAsync/DeleteByIdAsynconly track changes.DeleteByIdAsyncloads the aggregate into the stable unit-of-work context and uses tracked deletion, so audit, soft-delete, domain-event, and lifecycle behavior is preserved.- Paging always produces a total order before
Skip/Takeby appending missing primary-key properties; keyless entities are rejected.
Explicit Physical and Bulk Operations
Operations that bypass aggregate lifecycle behavior (loading, audit mutation, soft deletion, domain events) are explicitly named and stay inside the unit-of-work transaction:
// Physical delete: bypasses aggregate lifecycle but is transaction-bound
var executor = provider.GetRequiredService<IEFCorePhysicalOperationExecutor<AppDbContext>>();
await executor.ExecuteDeleteAsync<Book>(b => b.PublishedAt < cutoff);
// EF bulk and raw SQL APIs are guarded and transaction-bound as well
await context.Books.Where(b => b.Price == 0).ExecuteUpdateAsync(s => s.SetProperty(b => b.Price, 1));
await context.Database.ExecuteSqlRawAsync("DELETE FROM \"Books\" WHERE ...");
Transactional Domain Events vs. Integration Events
- Domain events raised by aggregates are collected and dispatched inside the unit-of-work transaction during
CommitAsync. A domain event handler failure aborts the commit and rolls back the whole unit of work. - Integration events (cross-service notifications) must be published only after the transaction durably commits. Publish them after
CommitAsyncsucceeds, or from theOnCommittedhook, never inside the transaction.
Migration Guide
| Removed / Changed API | Replacement |
|---|---|
IRepository.SaveChangesAsync() |
IUnitOfWork.CommitAsync() on the ambient unit of work |
IRepository.AddAndReturnAsync(...) |
AddAsync(...) plus IUnitOfWork.FlushAsync() where a generated key is required |
IDbContextWrapper |
IUnitOfWorkResource (provider integration contract) |
PersistenceStrategy / Timeout |
Removed; every writable unit of work uses explicit transactions |
UseMiCakeInterceptors() / UseMiCakeInterceptors(sp) |
Removed; interceptors are installed automatically via ConfigureDbContext — register the DbContext in the container and the MiCake EF Core module |
IEFCoreContextFactory / IEFCoreAnchoredContextFactory / GetDbContextWrapper() |
Merged into IEFCoreContextFactory<TDbContext> with GetDbContext() and GetOrCreateWrapperFor(DbContext); the non-generic interface and the parameterless wrapper method were removed |
Documentation
License
MIT License - see LICENSE
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- MiCake (>= 11.0.0-preview.12)
- Microsoft.EntityFrameworkCore (>= 10.0.7)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.7)
- Microsoft.Extensions.Logging.Console (>= 10.0.7)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on MiCake.EntityFrameworkCore:
| Package | Downloads |
|---|---|
|
MiCake.AspNetCore
ASP.NET Core integration extensions for MiCake. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.0.0-preview.2608081400 | 63 | 8/8/2026 |
| 11.0.0-preview.2608081123 | 65 | 8/8/2026 |
| 11.0.0-preview.12 | 57 | 8/8/2026 |
| 10.0.0 | 140 | 5/11/2026 |
| 10.0.0-preview.11 | 125 | 3/16/2026 |
| 10.0.0-preview.10 | 89 | 2/23/2026 |
| 10.0.0-preview.9 | 101 | 2/9/2026 |
| 10.0.0-preview.8 | 84 | 1/21/2026 |
| 10.0.0-preview.7 | 77 | 1/20/2026 |
| 10.0.0-preview.5 | 91 | 1/15/2026 |
| 1.0.0-CI-20251227-143701 | 155 | 12/27/2025 |
| 1.0.0-CI-20251227-131439 | 117 | 12/27/2025 |
| 1.0.0-CI-20251203-144406 | 684 | 12/3/2025 |
| 1.0.0-CI-20251202-144550 | 686 | 12/2/2025 |
| 1.0.0-CI-20251128-083448 | 183 | 11/28/2025 |
| 1.0.0-CI-20251123-045010 | 170 | 11/23/2025 |
| 0.9.0-CI-20251107-105430 | 178 | 11/7/2025 |
| 0.9.0-CI-20251030-064729 | 217 | 10/30/2025 |
| 0.9.0-CI-20251019-130615 | 244 | 10/19/2025 |
| 0.9.0-CI-20251009-024518 | 216 | 10/9/2025 |