В моем основном веб-API asp.net я хочу получить доступ к переменной в моем контроллере. Переменная будет установлена во время работы метода GetAllStudents. StudentController и StudentRepository находятся в одном решении, но в другом проекте. Как я могу получить доступ из StudentRepository.cs к переменной в StudentController.cs? Есть какое-то решение для MVC, но я не могу найти для веб-API. Итак, вопрос не повторяется .
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();
}