I use standart NinjectMVC3 Bootstrapper installed in the App_Start folder.
My application class looks like:
public class MvcApplication : HttpApplication
{
static void RegisterRoutes(RouteCollection routes)
{
// ... routes here ...
}
public void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
// empty
}
}
I have only following bidding rules registed in NinjectMVC3:
Bind<IAccountsRepository>().To<AccountsRepository>();
this.BindFilter<GlobalAuthFilter>(FilterScope.Global, 0);
And my global filter:
public class GlobalAuthFilter : IAuthorizationFilter
{
readonly IAccountsRepository _accountsRepository;
public GlobalAuthFilter(IAccountsRepository accountsRepository)
{
_accountsRepository = accountsRepository;
}
public void OnAuthorization(AuthorizationContext context)
{
// Code here never reached. Why? What's wrong?
}
}
There are any controllers in my application. And I want to invoke OnAuthorization for every action calls for every controllers.
But my code dosn't work. Thanks.