Class TransactionalCommandBehaviorServiceCollectionExtensions
Registration for the TransactionalCommandBehavior<TMessage, TResponse> pipeline behavior,
independent of any persistence adapter. Any adapter that registers an Trellis.IUnitOfWork (the
shipped EF Core adapter does this in AddTrellisUnitOfWork<TContext>()) can call
AddTransactionalCommandBehavior(IServiceCollection) to install the standard commit pipeline.
public static class TransactionalCommandBehaviorServiceCollectionExtensions
- Inheritance
-
TransactionalCommandBehaviorServiceCollectionExtensions
- Inherited Members
Methods
AddTransactionalCommandBehavior(IServiceCollection)
Inserts the open-generic TransactionalCommandBehavior<TMessage, TResponse> after the last Mediator.IPipelineBehavior<TMessage, TResponse> registration so it runs innermost (closest to the handler). If no behaviors are registered yet, appends at the end.
public static IServiceCollection AddTransactionalCommandBehavior(this IServiceCollection services)
Parameters
servicesIServiceCollectionThe service collection.
Returns
- IServiceCollection
The service collection for chaining.
Remarks
Idempotent for the open-generic case: a second call is a no-op when the open-generic
TransactionalCommandBehavior<,> is already registered.
Throws InvalidOperationException when a closed-generic
TransactionalCommandBehavior<TMessage,TResponse> is already registered. The
open generic added here would resolve alongside the closed registration on matching
commands and cause TransactionalCommandBehavior<TMessage, TResponse> to run
twice (two commits per command). The actionable resolution is to remove the closed
registration (so this method installs the open generic that covers every command), or to
skip this method and keep the explicit closed registrations. Detection covers
ImplementationType and
ImplementationInstance; factory-registered closed
transactional behaviors (via ImplementationFactory) are
not detectable without invoking the factory and are not caught here — consumers using
factory registrations should skip this method and own behavior wiring.