0

I'm currently using Ninject2 to bind the various services and repositories in my MVC app. That part seems to be working just fine. Now I'd like to also bind my own class to IAuthorizationFilter and all actions that have the attribute set.

I've created a class that inherits from AuthorizationFilter and Implements IAuthorizationFilter.

I've also add this to my binding module:

Bind(Of IAuthorizationFilter).To(Of MyAuthFilter)

The last time I checked, the Ninject Mvc bits had support for also binding the 4 types of action filters.

Has anyone else done this? Whenever I run the site, the url that invokes the action marked Authorize just redirect to the login page, and never hits the breakpoint in my filter class.

If I were using a custom attribute, it would work, but changing all of the Authorize attributes defeats the purpose of using Ninject every time I want to swap one out of course.

4

1 回答 1

1

用 Ninject 注册 MVC 过滤器是不够的;您还必须告诉 MVC 何时执行它们。这就是为什么您仍然需要自定义属性。Ninject.Web.Mvc 中的注入支持是允许将依赖项注入到过滤器中。

于 2009-09-04T13:32:58.293 回答