views:

158

answers:

1

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.

+1  A: 

It's not enough to register MVC filters with Ninject; you also have to tell MVC when to execute them. That's why you still need the custom attribute. The injection support in Ninject.Web.Mvc is to allow dependencies to be injected into filters.

Nate Kohari
Makes sense. After looking at the source a little more, I guess the goal is to have it inject into the loaded filters [Inject]able properties, not to load the filters against the interface themselves since they're an IList of IAuthenticationFilter...I think
claco