using Microsoft.AspNetCore.Mvc; namespace SequenceAuth.Example.Controllers; [ApiController] [Route("[controller]/[action]")] public abstract class ApiControllerBase : ControllerBase { protected Guid UserId { get { var options = HttpContext.RequestServices.GetRequiredService>().Value; return Guid.Parse(HttpContext.Items[options.UserIdItemKey]?.ToString() ?? throw new UnauthorizedAccessException()); } } }