I am attempting to set up DI on ActionFilters in ASP.NET WebAPI using Ninject. I followed the instructions here: https://github.com/ninject/Ninject.Web.WebApi/wiki/Dependency-injection-for-filters
I create my ActionFilter like so:
public class ApiAuthorizeFilter : AbstractActionFilter
{
private readonly IValidateApiTokenService _validateApiTokenService;
public ApiAuthorizeFilter(IValidateApiTokenService validateApiTokenService)
{
_validateApiTokenService = validateApiTokenService;
}
public override bool AllowMultiple => true;
public override void OnActionExecuting(HttpActionContext actionContext)
{
}
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
}
}
I configured like so:
kernel.BindHttpFilter<ApiAuthorizeFilter>(FilterScope.Controller);
My understanding based on the info at the above link is that the ActionFilter should then run for all Actions in all WebAPI controllers. However, I've set breakpoints at both overridden methods in the filter and it never gets hit. I have set a breakpoint at the configuration and can confirm that it is being executed.
What am I missing? I need this ActionFilter to run on all Actions in every ApiController in my project.