Table of Contents

Class UnitOfWorkServiceCollectionExtensions

Namespace
Trellis.EntityFrameworkCore
Assembly
Trellis.EntityFrameworkCore.dll

Extension methods for registering Trellis.IUnitOfWork and the TransactionalCommandBehavior<TMessage, TResponse> pipeline behavior.

public static class UnitOfWorkServiceCollectionExtensions
Inheritance
UnitOfWorkServiceCollectionExtensions
Inherited Members

Methods

AddTrellisUnitOfWorkWithoutBehavior<TContext>(IServiceCollection)

Registers EfUnitOfWork<TContext> as the Trellis.IUnitOfWork implementation without registering the pipeline behavior. Use this when you want manual commit control (e.g., background jobs) or when the Mediator pipeline is not in use.

public static IServiceCollection AddTrellisUnitOfWorkWithoutBehavior<TContext>(this IServiceCollection services) where TContext : DbContext

Parameters

services IServiceCollection

The service collection.

Returns

IServiceCollection

The service collection for chaining.

Type Parameters

TContext

The concrete DbContext type.

AddTrellisUnitOfWork<TContext>(IServiceCollection)

Registers EfUnitOfWork<TContext> as the Trellis.IUnitOfWork implementation and adds the TransactionalCommandBehavior<TMessage, TResponse> pipeline behavior so that command handlers automatically commit on success.

The behavior is inserted innermost (closest to the handler). Ordering is independent versus AddTrellisBehaviors() and domain-event dispatch registration, so commit failures remain visible to outer behaviors (logging, tracing, exception handling).

public static IServiceCollection AddTrellisUnitOfWork<TContext>(this IServiceCollection services) where TContext : DbContext

Parameters

services IServiceCollection

The service collection.

Returns

IServiceCollection

The service collection for chaining.

Type Parameters

TContext

The concrete DbContext type.

Examples

services.AddDbContext<AppDbContext>(...);
services.AddTrellisBehaviors();
services.AddTrellisUnitOfWork<AppDbContext>(); // commit behavior goes innermost