IAuditStore interface
Namespace: Tenantry.Pro.EfCore · Package: Tenantry.Pro.EfCore · API reference
Receives the entries audit logging (pro.AddAuditLogging()) records for the changes a context saves.
The default implementation logs entries to ILogger. To persist entries to a database, event stream, or external audit service instead, register your own implementation after calling pro.AddAuditLogging(), with any lifetime:
builder.Services.AddScoped<IAuditStore, MyDatabaseAuditStore>();The store is resolved for each call from the saving context's scope (under AddDbContext, the scope the context was created in), or from a scope created for that call: for a context with no scope of its own (pooled, from an IDbContextFactory, or created outside dependency injection), or whose scope has been disposed by the time the transaction it saved in commits. So it may be scoped and depend on scoped services such as a DbContext of its own. The saves it makes are not audited. Do not save through the context being audited.
public interface IAuditStoreMethods
SaveAsync(DbContext, IReadOnlyList<AuditEntry>, CancellationToken)
Persists or dispatches the supplied audit entries: once their changes are committed, by default, or inside the transaction they were saved in (AuditOptions.Timing).
Task SaveAsync(DbContext context, IReadOnlyList<AuditEntry> entries, CancellationToken cancellationToken = default)Parameters:
contextDbContext: The context that saved the changes. WithAuditTiming.InTransaction, itsDatabase.GetDbConnection()andDatabase.CurrentTransactionare the connection and transaction they were saved in. WithAuditTiming.AfterCommitthe changes are committed (unless they were saved in a transaction begun outside an audited context): do not save through it. When a transaction commits after the context was disposed, or after a pooled context went back to its pool, read nothing from it but its type.entriesIReadOnlyList<AuditEntry>: The entries for one save, or for one context's saves in one transaction. Never empty.cancellationTokenCancellationToken: A cancellation token: the save's, withAuditTiming.InTransaction. WithAuditTiming.AfterCommitit is never cancelled, so the entries of committed changes are not lost to a cancelled request.
Returns: Task
IAuditContextProvider interface
Says who made the changes a save records, and what ties them to the request or job that made them: the AuditEntry.Actortenantry-pro-efcore-auditentry.md, AuditEntry.CorrelationIdtenantry-pro-efcore-auditentry.md and AuditEntry.Datatenantry-pro-efcore-auditentry.md of each entry.
ITenantMigrationRunner<TKey> interface
Applies the migrations of every context added with pro.AddMigrations<TContext>, for every tenant, and reads which are applied.