MiCake 11.0.0-preview.12
Prefix ReservedSee the version list below for details.
dotnet add package MiCake --version 11.0.0-preview.12
NuGet\Install-Package MiCake -Version 11.0.0-preview.12
<PackageReference Include="MiCake" Version="11.0.0-preview.12" />
<PackageVersion Include="MiCake" Version="11.0.0-preview.12" />
<PackageReference Include="MiCake" />
paket add MiCake --version 11.0.0-preview.12
#r "nuget: MiCake, 11.0.0-preview.12"
#:package MiCake@11.0.0-preview.12
#addin nuget:?package=MiCake&version=11.0.0-preview.12&prerelease
#tool nuget:?package=MiCake&version=11.0.0-preview.12&prerelease
MiCake
A lightweight Domain-Driven Design (DDD) toolkit for .NET.
Overview
MiCake is the main DDD package providing all essential components:
- Entity & Aggregate Root - DDD tactical pattern implementations
- Value Objects - Immutable value type support
- Repository Pattern - Data access abstraction
- Domain Events - Event-driven domain modeling
- Unit of Work - Transaction management (the sole persistence owner)
- Audit Support - Automatic timestamp tracking
Installation
dotnet add package MiCake
Quick Start
// Define your aggregate root
public class Order : AggregateRoot<Guid>
{
public string CustomerName { get; private set; }
public decimal TotalAmount { get; private set; }
public void UpdateTotal(decimal amount)
{
TotalAmount = amount;
AddDomainEvent(new OrderUpdatedEvent(Id));
}
}
Key Components
| Component | Description |
|---|---|
Entity<TKey> |
Base class for domain entities |
AggregateRoot<TKey> |
Base class for aggregate roots |
ValueObject |
Base class for value objects |
IRepository<T> |
Repository interface for data access |
IDomainEvent |
Interface for domain events |
Unit of Work
The unit of work is the sole persistence owner. Repositories track changes but never save or commit independently; persistence happens when the ambient unit of work flushes and commits.
Basic Writable Flow
public class BookService
{
private readonly IRepository<Book, Guid> _bookRepository;
private readonly IUnitOfWorkManager _uowManager;
public async Task<Guid> CreateBookAsync(string name)
{
using var uow = await _uowManager.BeginAsync();
var book = new Book(name);
await _bookRepository.AddAsync(book);
// Explicit flush is only required when the database generates the key.
// If the key is application-generated, it is already available on the instance.
await uow.FlushAsync();
await uow.CommitAsync(); // Dispatches domain events and commits the transaction
return book.Id;
}
}
AddAsynctracks the aggregate; it does not persist.FlushAsyncwrites tracked changes without committing and returns the affected row count.CommitAsyncflushes, dispatches domain events, and commits the transaction.RollbackAsyncrolls back every participating resource.
Read-Only Unit of Work
Read-only units of work reject resource flush and write activation — every attempted write fails before a command executes:
var uow = await _uowManager.BeginAsync(UnitOfWorkOptions.ReadOnly);
Isolated Execution (requiresNew)
Use callback-based APIs instead of the removed requiresNew boolean overloads. ExecuteRequiresNewAsync runs the callback in a fully isolated DI scope with its own root unit of work, and restores the previous ambient unit of work afterwards:
await uowManager.ExecuteRequiresNewAsync(async (provider, ct) =>
{
var repo = provider.GetRequiredService<IRepository<Order, Guid>>();
await repo.AddAsync(new Order(...), ct);
// The inner unit of work commits on success and rolls back on failure
}, options: null, cancellationToken: ct);
ExecuteRequiresNewAsync requires a live outer unit of work.
Standalone Execution
IStandaloneUnitOfWorkExecutor executes an operation without any ambient unit of work, in its own DI scope with a root writable unit of work. It rejects an existing ambient unit of work to keep its contract unambiguous:
var executor = provider.GetRequiredService<IStandaloneUnitOfWorkExecutor>();
await executor.ExecuteAsync(async (isolatedProvider, ct) =>
{
var repo = isolatedProvider.GetRequiredService<IRepository<Order, Guid>>();
await repo.AddAsync(new Order(...), ct);
});
Savepoints
Root units of work expose savepoint management for partial rollback:
var name = await uow.CreateSavepointAsync("checkpoint");
await uow.RollbackToSavepointAsync(name);
await uow.ReleaseSavepointAsync(name);
Multi-Resource Semantics
Resources are committed in registration order. If a resource fails, already committed resources remain committed, later resources are rolled back, and a PartialUnitOfWorkCommitException carries the complete per-resource outcome together with the original failures. Best-effort semantics: use a single provider per unit of work unless you accept partial commit.
Migration Guide
The following APIs were removed or changed. Replace them as shown:
| Removed / Changed API | Replacement |
|---|---|
IRepository.AddAndReturnAsync(...) |
IRepository.AddAsync(...) followed by IUnitOfWork.FlushAsync() where a generated key is required |
IRepository.SaveChangesAsync() |
IUnitOfWork.CommitAsync() on the ambient unit of work (or FlushAsync() to write without committing) |
IRepository.ClearChangeTrackingAsync() |
Remove the instance from tracking state; the unit of work owns the change tracker |
IUnitOfWorkManager.BeginAsync(options, requiresNew: true) |
IUnitOfWorkManager.ExecuteRequiresNewAsync(callback, ...) |
PersistenceStrategy |
Removed. Every writable unit of work uses explicit transactions; read-only units of work are the only non-transactional mode |
UnitOfWorkOptions.Timeout |
Removed. It previously had no runtime effect |
IDbContextWrapper |
IUnitOfWorkResource (provider integration contract) |
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.Core (>= 11.0.0-preview.12)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on MiCake:
| Package | Downloads |
|---|---|
|
MiCake.EntityFrameworkCore
EF Core integration utilities for MiCake. |
|
|
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 | 77 | 8/8/2026 |
| 11.0.0-preview.2608081123 | 67 | 8/8/2026 |
| 11.0.0-preview.12 | 61 | 8/8/2026 |
| 10.0.0 | 150 | 5/11/2026 |
| 10.0.0-preview.11 | 132 | 3/16/2026 |
| 10.0.0-preview.10 | 91 | 2/23/2026 |
| 10.0.0-preview.9 | 111 | 2/9/2026 |
| 10.0.0-preview.8 | 93 | 1/21/2026 |
| 10.0.0-preview.7 | 83 | 1/20/2026 |
| 10.0.0-preview.5 | 96 | 1/15/2026 |
| 1.0.0-CI-20251227-143701 | 162 | 12/27/2025 |
| 1.0.0-CI-20251227-131439 | 120 | 12/27/2025 |
| 1.0.0-CI-20251203-144406 | 701 | 12/3/2025 |
| 1.0.0-CI-20251202-144550 | 700 | 12/2/2025 |
| 1.0.0-CI-20251128-083448 | 178 | 11/28/2025 |
| 1.0.0-CI-20251123-045010 | 173 | 11/23/2025 |
| 0.9.0-CI-20251107-105430 | 192 | 11/7/2025 |
| 0.9.0-CI-20251030-064729 | 232 | 10/30/2025 |
| 0.9.0-CI-20251019-130615 | 242 | 10/19/2025 |
| 0.9.0-CI-20251009-024518 | 226 | 10/9/2025 |