Table of Contents

Interface IUnitOfWork

Namespace
Trellis.EntityFrameworkCore
Assembly
Trellis.EntityFrameworkCore.dll

Abstraction over the commit boundary for staged changes. Repositories stage changes; calling CommitAsync(CancellationToken) persists them.

In the standard Trellis pipeline, commit is handled automatically by TransactionalCommandBehavior<TMessage, TResponse> after a successful handler. Inject IUnitOfWork directly only in non-pipeline scenarios (background jobs, integration tests, etc.).

public interface IUnitOfWork
Extension Methods

Methods

CommitAsync(CancellationToken)

Persists all staged changes to the database. Returns Result<TValue> with Unit to surface concurrency, duplicate-key, and foreign-key errors as Error instead of exceptions.

Task<Result<Unit>> CommitAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to observe while waiting for the task to complete.

Returns

Task<Result<Unit>>

A Result<TValue> with Unit representing success or failure.