title: How to use dependency injection with an attribute?
body: <p>In an MVC project I'm creating I have the following <code>RequirePermissionAttribute</code> that gets put on any action that needs specific permissions (it's been simplified for this example):</p>
  
  <pre><code>public class RequirePermissionAttribute : ActionFilterAttribute, IAuthorizationFilter
  {
      public Operation Permissions { get; set; }
  
      public RequirePermissionAttribute() { }
  
      public RequirePermissionAttribute(Operation permissions)
      {
          this.Permissions = permissions;
      }
  
      public bool AuthorizeCore(HttpContextBase httpContext)
      {
          IAuthorizationService authServ = new ASPNETAuthorizationService();
          return authServ.Authorize(httpContext);
      }
  
      public void OnAuthorization(AuthorizationContext filterContext)
      {
          Enforce.ArgNotNull(filterContext);
  
          if (this.AuthorizeCore(filterContext.HttpContext))
          {
              // code snipped.
          }
          else
          {
              // code snipped.
          }
      }
  }
  </code></pre>
  
  <p>So the problem obviously with this is that my authorize attribute has a dependency on the <code>ASPNETAuthorizationService</code> that I created. I can't go the constructor way since attributes are compile-time checked.</p>
  
  <p>One thing to mention, I'm using my own little IoC that I made and it doesn't have support for property injection (yet). Of course, if I did go the property injection route, I'd have to add support for it (which I'd have to do some research on).</p>
  
  <p>What's the best way to inject something into an attribute class?</p>