Closed eymel closed 5 years ago
There is no implementation to get current user in AppService for now. You can get current user in API layer and pass it to AppService. Or, if you can implement this feature and send a PR, it is very welcome :)
I added required parts to get current user Id in app service. You can inject IHttpContextAccessor
and get user id or any data that you added to claims. For example:
public class RoleAppService : IRoleAppService
{
....
private readonly IHttpContextAccessor _httpContextAccessor;
public RoleAppService(...., IHttpContextAccessor httpContextAccessor)
{
....
_httpContextAccessor = httpContextAccessor;
}
public async Task<SomeResult> SomeMethod(SomeInput input)
{
var userId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
return SomeResult;
}
Hello, I want to save a new object in the database. But I can't catch CreatedById in Application Layer. Can you help me?