title: Dependency Injection with Ninject and Filter attribute for asp.net mvc
body: <p>I'm writing a custom Authorization Filter for asp.net mvc 3. I need to inject a userservice into the class but I have no idea how to do this.</p>
  
  <pre><code>public class AuthorizeAttribute : FilterAttribute, IAuthorizationFilter
  {
      private IUserService userService;
      private string[] roles;
  
      public AuthorizeAttribute(params string[] roles)
      {
          this.roles = roles;
      }
  
      public void OnAuthorization(AuthorizationContext filterContext)
      {
          throw new NotImplementedException();
      }
  }
  </code></pre>
  
  <p>I'm using ninject for dependency injection. I do not want to use a Factory or service locator pattern.</p>
  
  <p>My bindings look like this in the global.acsx:</p>
  
  <pre><code>    internal class SiteModule : NinjectModule
      {
          public override void Load()
          {
              Bind&lt;IUserService&gt;().To&lt;UserService&gt;();
          }
      }
  </code></pre>