Using ASP.NET 5 I've implemented an Authorization Policy that I'd like to apply to all controllers within a namespace, but NOT to all controllers in the project. Is there a way to do this other than add the attribute [Authorize(Policy="MyPolicy")] to each controller individually? I'd like to avoid the risk that another dev adds a new controller to the namespace but forgets to apply the policy.
It looks like this when doing it manually:
[ApiController]
[Authorize(Policy="MyPolicy")]
[Route("api/DoStuff")]
public class MyController : ControllerBase
{
[HttpGet("foo")]
public GetFoo()
{
}
}