Class CommandAuditServiceCollectionExtensions
- Namespace
- Microsoft.Extensions.DependencyInjection
- Assembly
- Stratara.EventSourcing.Pipeline.CommandAudit.dll
Service-collection extensions for the Stratara command-audit pipeline behavior.
public static class CommandAuditServiceCollectionExtensions
- Inheritance
-
CommandAuditServiceCollectionExtensions
- Inherited Members
Methods
AddCommandAuditing(IServiceCollection)
Registers the CommandAuditBehavior pipeline behaviors for both
IRequest (void commands) and IRequest<TResult>
(commands with a result). The behaviors persist an audit row via
CreateCommandAuditRepository(ITransaction)
for every dispatched ICommandBase; non-command
requests (pure queries) pass through unaffected.
public static IServiceCollection AddCommandAuditing(this IServiceCollection services)
Parameters
servicesIServiceCollectionThe service collection to mutate.
Returns
- IServiceCollection
The same service collection, to enable chaining.
Examples
Writes one audit row per dispatched command; queries pass through untouched. Needs the write store, which is where the rows go:
services.AddWriteStore(configuration);
services.AddCommandAuditing();
Remarks
Call alongside the other framework registrations at app composition time, for example:
builder.Services
.AddMediator()
.AddCommandAuditing();
Both behaviors are registered as scoped so they share the request's IWriteUnitOfWork instance with the rest of the mediator pipeline. Calling this more than once installs each behavior once, so a dispatched command is audited exactly once.
Exceptions
- ArgumentNullException
servicesis null.