feat(udt-011): T400.30 — inject TimeProvider into Infrastructure critical services
AuditLogger, SecurityEventLogger: inject TimeProvider and use _timeProvider.GetUtcNow().UtcDateTime for occurredAt timestamps. JwtService: inject TimeProvider; use GetUtcNow() for token IssuedAt/Expires. DI: update JwtService factory to pass sp.GetRequiredService<TimeProvider>(). Repositories: remove ?? DateTime.UtcNow fallback in UpdateAsync since callers always provide FechaModificacion via domain mutators.
This commit is contained in:
@@ -12,15 +12,18 @@ public sealed class AuditLogger : IAuditLogger
|
||||
private readonly IAuditContext _context;
|
||||
private readonly IAuditEventRepository _repo;
|
||||
private readonly IOptions<AuditOptions> _options;
|
||||
private readonly TimeProvider _timeProvider;
|
||||
|
||||
public AuditLogger(
|
||||
IAuditContext context,
|
||||
IAuditEventRepository repo,
|
||||
IOptions<AuditOptions> options)
|
||||
IOptions<AuditOptions> options,
|
||||
TimeProvider timeProvider)
|
||||
{
|
||||
_context = context;
|
||||
_repo = repo;
|
||||
_options = options;
|
||||
_timeProvider = timeProvider;
|
||||
}
|
||||
|
||||
public async Task LogAsync(
|
||||
@@ -42,7 +45,7 @@ public sealed class AuditLogger : IAuditLogger
|
||||
: _context.CorrelationId;
|
||||
|
||||
await _repo.InsertAsync(
|
||||
occurredAt: DateTime.UtcNow,
|
||||
occurredAt: _timeProvider.GetUtcNow().UtcDateTime,
|
||||
actorUserId: _context.ActorUserId,
|
||||
actorRoleId: _context.ActorRoleId,
|
||||
action: action,
|
||||
|
||||
Reference in New Issue
Block a user