I have a .NET core project and am trying to create a custom policy using AuthorizationOptions as shown in the documentation located here:
ASP.NET.Core Authorization - De
You can use also the GetRequiredService method:
public class ExampleRequirement : AuthorizationHandler, IAuthorizationRequirement
{
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, ExampleRequirement requirement)
{
UserManager UserManager = ((ActionContext)context.Resource).HttpContext.RequestServices.GetRequiredService>();
// you can work with the users ...
return Task.CompletedTask;
}
}