Part of DKNet.EfCore.AuditLogs. Implement ICurrentUserProvider and register it as in the Quick Start. For example, replace DemoUser with:
public sealed class DemoUser : ICurrentUserProvider
{
public string? GetCurrentUser() => "service-import";
}
AddCurrentUserProvider<TDbContext, TProvider>() registers the provider scoped and unkeyed: the first provider registration wins application-wide. The call attaches the audit hook even without a publisher and only adds default audit options when none exist.
| Save state | Behavior with a non-empty user |
|---|---|
| Added | When CreatedBy is blank, fill it and set CreatedOn to UTC now. When CreatedBy is already set, leave both unchanged. |
| Modified | Fill UpdatedBy/UpdatedOn unless either was explicitly changed in this tracked change set. |
| Deleted | Leave audit identity fields unchanged. |
A missing provider or null/empty user skips user stamping. No arguments or configuration section are read by this registration.
See ownership and the audit-field split. With a non-empty user, EfCoreAuditHook owns the audit fields and DataOwnerHook owns OwnedBy; otherwise ownership supplies the fallback. The choice comes from provider values rather than registration order.
CreatedBy wins on creation, and a changed modifier or modification timestamp wins on update.