Open jhuerta opened 9 months ago
@jhuerta I encountered a similar issue with wanting to inject user infomation into the db interceptor and could not do it with the IdentityService but my way around this was having the ICurrentUserService still in the Application layer but I placed the implementation in the Web API project and grabbed the current logged in user claims from the HTTP context. The below implementation allowed me to inject ICurrentUserService in the inceptor without any problems.
public interface ICurrentUserService
{
string? UserId { get; }
string? UserName { get; }
}
public class CurrentUserService : ICurrentUserService
{
private readonly IHttpContextAccessor _httpContextAccessor;
public CurrentUserService(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
public string? UserId => _httpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.NameIdentifier);
public string? UserName => _httpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.Name);
}
Discussed in https://github.com/jasontaylordev/CleanArchitecture/discussions/993