Class UnitOfWorkServiceCollectionExtensions
- Namespace
- Trellis.EntityFrameworkCore
- Assembly
- Trellis.EntityFrameworkCore.dll
Extension methods for registering 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 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
servicesIServiceCollectionThe service collection.
Returns
- IServiceCollection
The service collection for chaining.
Type Parameters
TContextThe concrete DbContext type.
AddTrellisUnitOfWork<TContext>(IServiceCollection)
Registers EfUnitOfWork<TContext> as the IUnitOfWork implementation and adds the TransactionalCommandBehavior<TMessage, TResponse> pipeline behavior so that command handlers automatically commit on success.
The behavior is inserted after the last existing Mediator.IPipelineBehavior<TMessage, TResponse>
registration (innermost position, closest to the handler). For correct ordering, call this
method after AddTrellisBehaviors() and any other behavior registrations so that
commit failures are visible to outer behaviors (logging, tracing, exception handling).
public static IServiceCollection AddTrellisUnitOfWork<TContext>(this IServiceCollection services) where TContext : DbContext
Parameters
servicesIServiceCollectionThe service collection.
Returns
- IServiceCollection
The service collection for chaining.
Type Parameters
TContextThe concrete DbContext type.
Examples
services.AddDbContext<AppDbContext>(...);
services.AddTrellisBehaviors(); // register other behaviors first
services.AddTrellisUnitOfWork<AppDbContext>(); // commit behavior goes innermost