Class LedgerDecisionReceiptSink
- Namespace
- ReferenceApplication.Web.Governance
- Assembly
- ReferenceApplication.Web.dll
Persists endpoint governance decision receipts to the AsiBackbone audit ledger in the host-owned database.
public sealed class LedgerDecisionReceiptSink : IDecisionReceiptSink
- Inheritance
-
LedgerDecisionReceiptSink
- Implements
-
IDecisionReceiptSink
- Inherited Members
Remarks
AsiBackbone's endpoint middleware writes a decision receipt to the registered AsiBackbone.Core.Audit.IDecisionReceiptSink
for every endpoint marked with [EmitGovernanceAudit], before the endpoint executes. This sink converts the
receipt into an AsiBackbone.Core.Audit.AuditLedgerRecord and appends it through AsiBackbone's
AsiBackbone.EntityFrameworkCore.Audit.EfCoreAuditLedgerStore.
Each append uses a short-lived ApplicationDbContext from the context factory, so persisting evidence can never save, or be rolled back with, unrelated changes tracked by the request's own context. A failed append throws GovernanceEvidencePersistenceException, so the governed operation fails closed.
Once the receipt is appended, the decision is projected onto telemetry through GovernanceTelemetryProjection. A rejected or failed append projects nothing, and a projection can never fail the governed operation.
Constructors
LedgerDecisionReceiptSink(IDbContextFactory<ApplicationDbContext>, GovernanceDecisionEvidenceAccessor, ILoggerFactory, GovernanceEvidenceNotificationPublisher, GovernanceTelemetryProjection, IHttpContextAccessor?)
Initializes a new instance of the LedgerDecisionReceiptSink class.
public LedgerDecisionReceiptSink(IDbContextFactory<ApplicationDbContext> dbContextFactory, GovernanceDecisionEvidenceAccessor evidenceAccessor, ILoggerFactory loggerFactory, GovernanceEvidenceNotificationPublisher notificationPublisher, GovernanceTelemetryProjection telemetryProjection, IHttpContextAccessor? httpContextAccessor = null)
Parameters
dbContextFactoryIDbContextFactory<ApplicationDbContext>The factory for short-lived application database contexts.
evidenceAccessorGovernanceDecisionEvidenceAccessorThe request-scoped evidence holder.
loggerFactoryILoggerFactoryThe logger factory used for the AsiBackbone EF Core store.
notificationPublisherGovernanceEvidenceNotificationPublisherThe isolated best-effort evidence notification publisher.
telemetryProjectionGovernanceTelemetryProjectionThe best-effort projection of persisted evidence onto telemetry.
httpContextAccessorIHttpContextAccessorThe current request, used only to link a validated acknowledgment retry.
Fields
AppendFailedReasonCode
The reason code used when the decision receipt cannot be appended to the audit ledger.
public const string AppendFailedReasonCode = "referenceapplication.governance.evidence.append_failed"
Field Value
Methods
WriteAsync(IDecisionReceipt, CancellationToken)
Records a single decision receipt value.
public ValueTask WriteAsync(IDecisionReceipt receipt, CancellationToken cancellationToken = default)
Parameters
receiptIDecisionReceiptThe decision receipt to record.
cancellationTokenCancellationTokenA token that can cancel the write.
Returns
- ValueTask
A task that completes when the receipt has been recorded.