Skip to content

AspNetCore Command Transactions

SteffenBlake edited this page Sep 28, 2026 · 1 revision

Command transactions in ASP.NET Core

Register the command unit-of-work bundle around command routes, then supply transactional resources through Providers.

Enable command transactions

Register [PartieSystemBundle] on a route or an enclosing group:

[BrigadeGroup("/api/v1")]
[AspNetSystemBundle]
[PartieSystemBundle]
[ExpoSystemBundle]
public static partial class ApiRoutes
{
    ...
}

The core bundle contains UnitOfWorkPartie. Commands receive the resulting UnitOfWork as the first handler argument. Queries do not receive a unit of work through this command contract.

Putting Expo after the core bundle makes validation run inside the command boundary. The outer HTTP bundle maps the result after transaction handling has completed.

Consume transactional database resources

A Mise database bundle supplies command transactions and a writer that uses them. Register it inside the system bundles' scope:

[BrigadeGroup("/courses")]
[MisePostgreSqlBundle("CourseDatabase")]
private static partial class Courses
{
    [CourseUpdateHandlerRoute.Put("/{courseId}")]
    public static partial void Update();
}

The command handler requests the writer through its context:

public sealed record CourseUpdateContext([Provide] DbWriter Writer);

Write through context.Writer and return your command result. Let UnitOfWorkPartie choose commit or rollback when the downstream pipeline returns. See Database access with Mise for a complete writer example.

See Unit of work for outcomes and resource enlistment.

Clone this wiki locally