title: Asp.Net Web Api and Autofac with Custom Authorisation attribute issue (property injection)
body: <p>I am using Autofac to inject all my project dependencies which is working great. Now I have added a Custom Authorization attribute (I don't need very complex functionality like OWIN and Identity stuff). The custom authorization attribute has dependency to data layer and therefore I am trying to inject it as a property injection. However the property is always Null. The code is below:</p>
  
  <pre><code> public class CustomAuthorizationFilterAttribute : AuthorizeAttribute,  IAutofacAuthorizationFilter
  {
      public IAuthorisationHelper AuthorisationHelper { get; set; }
  
      public override void OnAuthorization(HttpActionContext actionContext)
      {
          **... removed for brevity**
  
              **// TODO: this should be injected by autofac and is always null??**
              if (AuthorisationHelper.IsValidUser(username, password, out roleOfUser))
              {
                  var principal =
                      new GenericPrincipal((new GenericIdentity(username)),
                          (new[] { roleOfUser }));
  
                  Thread.CurrentPrincipal = principal;
                  return;
              }
  
          ... removed for brevity
  
      }
  }
  </code></pre>
  
  <p>Code that injects the AuthorizationHelper:</p>
  
  <pre><code>public static IContainer Container()
      {
          var builder = new ContainerBuilder();
          var assemblies = new List&lt;Assembly&gt;();
  
          assemblies.Add(Assembly.Load("Kids.Math.Interfaces"));
          assemblies.Add(Assembly.Load("Kids.Math.Data"));
          assemblies.Add(Assembly.Load("Kids.Math.Business"));
          assemblies.Add(Assembly.Load("Kids.Math.ImportExport"));
          assemblies.Add(Assembly.Load("Kids.Math.Common"));
          assemblies.Add(Assembly.Load("Kids.Math.Api"));
  
          builder.RegisterAssemblyTypes(assemblies.ToArray()).
              AsImplementedInterfaces();
  
          builder.RegisterType(typeof(MathContext)).As(typeof (DbContext)).InstancePerRequest();
  
          // Register web API controllers.
          builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
  
          // TODO: this is not working, also this should be generic to register it for all controllers
          // inject the authorisation filter
          builder.RegisterType&lt;AuthorisationHelper&gt;().As&lt;IAuthorisationHelper&gt;();
          builder.Register(c =&gt; new CustomAuthorizationFilterAttribute()).PropertiesAutowired()
              .AsWebApiAuthorizationFilterFor&lt;QuestionsImportController&gt;()
              .InstancePerRequest();
  
          // Set the dependency resolver to be Autofac.
          var container = builder.Build();
          return container;
      }
  </code></pre>
  
  <p>Attribute is registered in FilterConfig as 
      filters.Add(new CustomAuthorizationFilterAttribute());</p>
  
  <p>All the wiring up works but AuthorisationHelper is always null.</p>
  
  <p>Any comments will be appreciated.</p>