Table of Contents

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

condition bool

The domain condition observed.

message string

Human-readable description of what was observed.

eventType AuditEventType

Classification of the audit event.

cancellationToken CancellationToken

A 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

resourceId string

The resource identifier.

resourceType string

The resource type name.

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

message string

Human-readable description.

eventType AuditEventType

Classification of the audit event.

outcome AuditOutcome

The outcome to record.

cancellationToken CancellationToken

A 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

key string

The metadata key.

value string

The metadata value.

Returns

IAuditContext

This context for fluent chaining.