Add current user service and use for catalog audit fields
Introduce ICurrentUserService and its implementation to access the current user's username. Inject this service into CreateCatalogHandler and UpdateCatalogHandler to set AddedWho and ChangedWho fields dynamically. Register the service and IHttpContextAccessor in DI, and enable authentication middleware. Update project and using statements accordingly.
This commit is contained in:
10
DbFirst.API/Services/CurrentUserService.cs
Normal file
10
DbFirst.API/Services/CurrentUserService.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using DbFirst.Application.Abstractions;
|
||||
|
||||
namespace DbFirst.API.Services
|
||||
{
|
||||
public class CurrentUserService(IHttpContextAccessor httpContextAccessor) : ICurrentUserService
|
||||
{
|
||||
public string UserName =>
|
||||
httpContextAccessor.HttpContext?.User.Identity?.Name ?? "unknown";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user