Table of Contents

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

dbContextFactory IDbContextFactory<ApplicationDbContext>

The factory for short-lived application database contexts.

evidenceAccessor GovernanceDecisionEvidenceAccessor

The request-scoped evidence holder.

loggerFactory ILoggerFactory

The logger factory used for the AsiBackbone EF Core store.

notificationPublisher GovernanceEvidenceNotificationPublisher

The isolated best-effort evidence notification publisher.

telemetryProjection GovernanceTelemetryProjection

The best-effort projection of persisted evidence onto telemetry.

httpContextAccessor IHttpContextAccessor

The 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

string

Methods

WriteAsync(IDecisionReceipt, CancellationToken)

Records a single decision receipt value.

public ValueTask WriteAsync(IDecisionReceipt receipt, CancellationToken cancellationToken = default)

Parameters

receipt IDecisionReceipt

The decision receipt to record.

cancellationToken CancellationToken

A token that can cancel the write.

Returns

ValueTask

A task that completes when the receipt has been recorded.