MiCake.AspNetCore
11.0.0-preview.12
Prefix Reserved
See the version list below for details.
dotnet add package MiCake.AspNetCore --version 11.0.0-preview.12
NuGet\Install-Package MiCake.AspNetCore -Version 11.0.0-preview.12
<PackageReference Include="MiCake.AspNetCore" Version="11.0.0-preview.12" />
<PackageVersion Include="MiCake.AspNetCore" Version="11.0.0-preview.12" />
<PackageReference Include="MiCake.AspNetCore" />
paket add MiCake.AspNetCore --version 11.0.0-preview.12
#r "nuget: MiCake.AspNetCore, 11.0.0-preview.12"
#:package MiCake.AspNetCore@11.0.0-preview.12
#addin nuget:?package=MiCake.AspNetCore&version=11.0.0-preview.12&prerelease
#tool nuget:?package=MiCake.AspNetCore&version=11.0.0-preview.12&prerelease
MiCake.AspNetCore
ASP.NET Core integration for the MiCake DDD toolkit.
Overview
MiCake.AspNetCore provides seamless integration with ASP.NET Core:
- Unit of Work Filter - Automatic transaction management per request
- Exception Handling - Global exception handling with custom responses
- Response Wrapper - Unified API response format
- API Logging - Request/response logging with sensitive data masking
- Data Wrapper - Automatic response wrapping
Installation
dotnet add package MiCake.AspNetCore
Quick Start
// In Program.cs
builder.Services
.AddMiCake<MyDbContext, AppModule>()
.Build();
var app = builder.Build();
app.StartMiCake();
Unit of Work per Request
A UnitOfWorkFilter runs last on every controller action. It begins a unit of work before the action, commits it after a successful action, and rolls it back on action failure or request cancellation. The unit of work is always disposed asynchronously, including on commit or rollback failure.
Operation Modes
| Mode | How to enable | Behavior |
|---|---|---|
| Automatic (default) | EnableAutoUnitOfWork = true |
Every action gets a writable unit of work that commits on success and rolls back on failure |
| Explicit read-only | [UnitOfWork(IsReadOnly = true)] on action or controller |
Read-only unit of work; every attempted write fails before a command executes; no commit is performed |
| Explicit writable | [UnitOfWork(IsReadOnly = false)] |
Writable unit of work regardless of action-name inference |
| Opt-out | [DisableUnitOfWork] on action or controller |
No unit of work is created for the decorated action(s) |
| Global off | EnableAutoUnitOfWork = false |
No automatic unit of work unless [UnitOfWork] is applied |
[ApiController]
[Route("api/books")]
public class BooksController : ControllerBase
{
// Explicit read-only intent: writes fail before SQL execution
[HttpGet("{id}")]
[UnitOfWork(IsReadOnly = true)]
public async Task<ActionResult<Book>> GetBook(Guid id) { ... }
// Writable: the request unit of work commits tracked changes on success
[HttpPost]
public async Task<ActionResult<Guid>> AddBook(AddBookDto dto) { ... }
}
Attribute and Configuration Priority
Per request, the filter resolves the effective policy in this order:
[DisableUnitOfWork]on the action, controller, or endpoint metadata — skips UoW management entirely. This wins over every other configuration, so a controller-level[DisableUnitOfWork]also overrides an action-level[UnitOfWork].[UnitOfWork]on the action (highest), controller, or endpoint metadata — enables UoW and applies itsIsReadOnly/IsolationLevel, even whenEnableAutoUnitOfWorkisfalse.- Global configuration:
EnableAutoUnitOfWork(defaulttrue), thenEnableReadOnlyActionNameInferencewhen the action name matches a keyword.
Read-Only Action-Name Inference (Opt-In)
For compatibility with the previous naming convention, set EnableReadOnlyActionNameInference = true:
options.AspNetConfig = asp =>
{
asp.UnitOfWork.EnableReadOnlyActionNameInference = true;
asp.UnitOfWork.ReadOnlyActionKeywords = ["Find", "Get", "Query", "Search"];
};
When enabled, actions whose names start with a configured keyword are treated as read-only. Explicit [UnitOfWork(IsReadOnly = ...)] metadata always overrides the inference. The inference is disabled by default: declare read-only intent explicitly.
Request Failure Semantics
- Action failure or request cancellation → the unit of work rolls back.
- Commit failure → the unit of work rolls back and the original exception propagates; a rollback failure surfaces as an
AggregateExceptioncarrying both causes. - The unit of work is disposed asynchronously in all paths, so pooled DbContexts are returned promptly.
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)
- MiCake.EntityFrameworkCore (>= 11.0.0-preview.12)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.0.0-preview.2608081400 | 59 | 8/8/2026 |
| 11.0.0-preview.2608081123 | 60 | 8/8/2026 |
| 11.0.0-preview.12 | 55 | 8/8/2026 |
| 10.0.0 | 124 | 5/11/2026 |
| 10.0.0-preview.11 | 121 | 3/16/2026 |
| 10.0.0-preview.10 | 83 | 2/23/2026 |
| 10.0.0-preview.9 | 92 | 2/9/2026 |
| 10.0.0-preview.8 | 83 | 1/21/2026 |
| 10.0.0-preview.7 | 74 | 1/20/2026 |
| 10.0.0-preview.5 | 94 | 1/15/2026 |
| 1.0.0-CI-20251227-143701 | 132 | 12/27/2025 |
| 1.0.0-CI-20251227-131439 | 108 | 12/27/2025 |
| 1.0.0-CI-20251203-144406 | 677 | 12/3/2025 |
| 1.0.0-CI-20251202-144550 | 681 | 12/2/2025 |
| 1.0.0-CI-20251128-083448 | 165 | 11/28/2025 |
| 1.0.0-CI-20251123-045010 | 166 | 11/23/2025 |
| 0.9.0-CI-20251107-105430 | 170 | 11/7/2025 |
| 0.9.0-CI-20251030-064729 | 203 | 10/30/2025 |
| 0.9.0-CI-20251019-130615 | 223 | 10/19/2025 |
| 0.9.0-CI-20251009-024518 | 194 | 10/9/2025 |