您好,我正在尝试使用注入实现全局过滤器。过滤器看起来像这样。
public class WikiFilter : IActionFilter
{
private IWikiService service;
public WikiFilter(IWikiService service)
{
this.service = service;
}
public void OnActionExecuting(ActionExecutingContext filterContext)
{
!!!Code here!!
}
public void OnActionExecuted(ActionExecutedContext filterContext)
{
throw new NotImplementedException();
}
}
我已经在我的 global.asax 中以以下方式附加了带有注入的过滤器。
public class MvcApplication : System.Web.HttpApplication,
IAuthenticationApplication<User>
{
protected void Application_Start()
{
Ninject();
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
RegisterGlobalFilters(GlobalFilters.Filters);
}
private void Ninject()
{
// Create Ninject DI kernel
IKernel kernel = new StandardKernel();
kernel.Bind<DataContext>().ToSelf().InRequestScope();
kernel.Bind<IWikiRepository>().To<WikiRepository>();
kernel.Bind<IWikiService>().To<WikiService>();
// Global filters
kernel.BindFilter<WikiFilter>(FilterScope.Global, 0);
DependencyResolver.SetResolver
(new NinjectDependencyResolver(kernel));
}
}
但是由于某种原因,当应用程序运行时过滤器从未被触发,我没有正确实现它吗?