I am creating the following attribute class in an ASP.NET Core 6 Web API.
I need to make a database call from this class and want to get dbContext which is already registered with dependency container.
How do I inject the dbcontext into my customAuthorization class ?
[AttributeUsage(AttributeTargets.Class)]
public class CustomAuthorization : Attribute, IAuthorizationFilter
{
private readonly IServiceProvider _serviceProvider;
public CustomAuthorization(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
public void OnAuthorization(AuthorizationFilterContext filterContext)
{
...................
}
}
[CustomAuthorization()]
public class OrganizationController : CustomControllerBaseClass
{
// .......
}