I want to move this service to logic for using on everywhere, but i can't successful because it was coming from the controller.
I have two services. There read caches and I use them in the controller layer when authenticating.
my first logic is reading companyId in cache
public virtual int GetCompanyIdFromCache(int id)
{
_memCache.TryGetValue(id, out int companyId);
return companyId;
}
My second service is also on the controller. (helps me find the user's id)
[HttpGet]
[Route("GetCompanyId")]
public int GetCompanyPublicId()
{
if (User.Identity is ClaimsIdentity claimsIdentity)
{
var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
var companyId = _userService.GetCompanyIdFromCache(Convert.ToInt32(userId));
return companyId;
}
throw new ArgumentException("Can't be found Company");
}
I want to use this method everywhere, so i want to move the second service completely to logic layer but User field comes from ControllerBase (on HttpContext i guess) and I can't move it to logic
if (User.Identity is ClaimsIdentity claimsIdentity)
What should I do to refactor the logic layer?