title: Simple injector webapi authorization attribute
body: <p>I'm trying to create a custom authorization-attribute for my WebApi project. </p>
  
  <p>In this attribute I would like to inject an IAuthModule object. I have no clue how I could implement this. I've found some solutions on the web but I have not been successful with any of them. </p>
  
  <p>This is what I have so far: </p>
  
  <pre class="lang-c# prettyprint-override"><code>public void Configuration(IAppBuilder app)
  {
      // WebApi config
      HttpConfiguration config = new HttpConfiguration();
  
      // SimpleInjector
      var container = new SimpleInjector.Container();
  
      container.Register&lt;IAuthModule, CoreAuthModule&gt;();
  
      container.RegisterWebApiFilterProvider(config);
      container.RegisterWebApiControllers(config);
  
      container.Verify();
  
      config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
  
      // Setup Oauth
      ConfigureOAuth(app, container.GetInstance&lt;IAuthModule&gt;());
  
      WebApiConfig.Register(config);
  
      app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
      app.UseWebApi(config);
  }
  </code></pre>
  
  <p>and the attribute:</p>
  
  <pre><code>public class CustomAuthorizationAttribute : AuthorizeAttribute
  {
      // how can I inject something here?
      public IAuthModule AuthModule { get; set; }
  
      protected override bool IsAuthorized(HttpActionContext actionContext)
      {
          return false;
      }
  }
  </code></pre>