In my asp.net core web API, i want to access variable in my controller. The variable will set while GetAllStudents method running. StudentController and StudentRepository is in same solution but different project. How can i access from StudentRepository.cs to variable in StudentController.cs? There is some solution for MVC, but i can't find for web API. So, question is not duplicate.
StudentController.cs :
int requestedUserId;
[HttpGet("GetAllStudents")]
public async Task<ServiceResult>GetAllStudents()
{
requestedUserId= context.HttpContext.Request.Headers["Authorization"];
return await (studentService.GetAllStudents(requestedUserId));
}
StudentService.cs :
public async Task<ServiceResult> GetAllStudents()
{
return await unitOfWork.studentRepo.GetAllStudents();
}
StudentRepository.cs :
public async Task<List<Student>> GetAllStudents()
{
?????var requestedUserId= StudentController.requestedUserId;?????
LogOperation(requestedUserId);
return context.Students.ToList();
}