title: Ninject Binding Attribute to Filter with Constructor Arguments
body: <p>I read as many answers as I could for this, but they seem to fall short of one detail.</p>
  
  <p>The trouble is when binding an action filter (with a service injected by controller) to a corresponding attribute, I've been unable to figure out how to pass parameter/property values from the attribute to its bound filter. Below is the code, and below that my intended fake-code:</p>
  
  <p><strong>Filter &amp; Attribute</strong></p>
  
  <pre><code>public class AuthorizationFilter : IAuthorizationFilter
  {
      private readonly IAuthorizationService _authorizationService;
      private readonly UserRoles _requiredRoles;   // Enum
  
      public AuthorizationFilter(IAuthorizationService authorizationService, UserRoles requiredRoles)
      {
          _authorizationService = authorizationService;
          _requiredRoles = requiredRoles;
      }
  
      public void OnAuthorization(AuthorizationContext filterContext)
      {
          if (filterContext.HttpContext.Session == null)
              HandleUnauthorizedRequest(filterContext);
          else {
              var authorized = _authorizationService.IsUserInRole((UserSessionInfoViewModel) filterContext.HttpContext.Session["user"], _requiredRoles);
              if (!authorized)
                  HandleUnauthorizedRequest(filterContext);
              // else TODO: deal with cache... 
          }
      }
  }
  
  public class RequireRolesAttribute : FilterAttribute
  {
      public readonly UserRoles RequiredRoles;
  
      public RequireRolesAttribute(UserRoles requiredRoles)
      {
          RequiredRoles = requiredRoles;
      }        
  }
  </code></pre>
  
  <p><strong>Filter/Attribute Bindings</strong></p>
  
  <pre><code>kernel.BindFilter&lt;AuthorizationFilter&gt;(FilterScope.Controller, 0)
        .WhenControllerHas&lt;RequireRolesAttribute&gt;();
  kernel.BindFilter&lt;AuthorizationFilter&gt;(FilterScope.Action, 0)
        .WhenActionMethodHas&lt;RequireRolesAttribute&gt;();
  </code></pre>
  
  <p>This should make sure any controller/action decorated with [RolesRequired] is bound to the filter. So far so good. Now I want to declare via the attribute the roles (much like the stock AuthorizeAttribute) and pass those values onto the filter that actually does the authorization. </p>
  
  <p><strong>Intended/Fake Code:</strong> </p>
  
  <pre><code>[RequireRoles(UserRoles.Author)]
  public ActionResult Index()
  {
      // blah
  }
  </code></pre>
  
  <p><strong>Specifically,</strong></p>
  
  <p>What does it take to inform the AuthorizationFilter of the roles? Can the filter/ninject access the arguments passed to the attribute's constructor? Can the filter/ninject pull them from the attributes public property?</p>
  
  <p>For reference, these articles were a huge help, but don't answer this one thing:</p>
  
  <p><a href="https://stackoverflow.com/questions/6193414/dependency-injection-with-ninject-and-filter-attribute-for-asp-net-mvc">Dependency Injection with Ninject and Filter attribute for asp.net mvc</a></p>
  
  <p><a href="https://stackoverflow.com/questions/5572257/custom-authorization-mvc-3-and-ninject-ioc/5572752#5572752">Custom Authorization MVC 3 and Ninject IoC</a></p>
  
  <p>B Z, Remo Gloor, others... how can I accomplish this?</p>