Interface IAuditContext
- Namespace
- Excalibur.Compliance
- Assembly
- Excalibur.Compliance.Abstractions.dll
Scoped audit context available within message handlers for emitting domain-aware audit observations.
public interface IAuditContext
Remarks
Inherits pipeline context (correlation, actor, tenant) automatically. Handlers only provide the condition, message, and severity — the framework supplies all contextual data.
Registered as scoped in DI and initialized by
AuditContextMiddleware before handler execution.
Methods
AssertAsync(bool, string, AuditEventType, CancellationToken)
Records an audit assertion if the condition is true. Does not record an audit event if condition is false.
Task<AuditEventId?> AssertAsync(bool condition, string message, AuditEventType eventType, CancellationToken cancellationToken)
Parameters
conditionboolThe domain condition observed.
messagestringHuman-readable description of what was observed.
eventTypeAuditEventTypeClassification of the audit event.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<AuditEventId?>
The audit event ID if recorded, null if condition was false.
ForResource(string, string)
Associates the audit context with a specific resource (e.g., aggregate ID).
IAuditContext ForResource(string resourceId, string resourceType)
Parameters
Returns
- IAuditContext
This context for fluent chaining.
ObserveAsync(string, AuditEventType, AuditOutcome, CancellationToken)
Unconditionally records a custom audit observation. Use for events that do not depend on a boolean condition.
Task<AuditEventId> ObserveAsync(string message, AuditEventType eventType, AuditOutcome outcome, CancellationToken cancellationToken)
Parameters
messagestringHuman-readable description.
eventTypeAuditEventTypeClassification of the audit event.
outcomeAuditOutcomeThe outcome to record.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<AuditEventId>
The audit event ID.
WithMetadata(string, string)
Sets additional metadata for subsequent assertions/observations in this scope.
IAuditContext WithMetadata(string key, string value)
Parameters
Returns
- IAuditContext
This context for fluent chaining.