title: Can Autofac inject dependencies into layout view files?
body: <p>I'm trying to inject a dependency into the shared layout view page to avoid having to do it in every view that uses the layout.</p>
  
  <p>I've followed the <a href="http://code.google.com/p/autofac/wiki/Mvc3Integration#View_Page_Injection">guidance</a> in the wiki for injecting dependencies into views, but the property is always null.</p>
  
  <p>Can Autofac inject properties into a custom view page that is a layout file?</p>
  
  <p>Here's my setup.
  CustomViewPage</p>
  
  <pre><code>namespace MyApp
  {
      using System.Web.Mvc;
  
      public abstract class CustomViewPage : WebViewPage
      {
          public IHelper Helper { get; set; }
      }
  }
  </code></pre>
  
  <p>~/Views/Shared/_Layout.cshtml</p>
  
  <pre><code>@inherits MyApp.CustomViewPage
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  ...
  @if(this.Helper.HasFoo()){@Html.ActionLink("Bar")}
  </code></pre>
  
  <p>Global Registration...</p>
  
  <pre><code>builder.RegisterType&lt;Helper&gt;().AsImplementedInterfaces();
  builder.RegisterModelBinderProvider();
  builder.RegisterFilterProvider();
  builder.RegisterModule(new AutofacWebTypesModule());
  builder.RegisterSource(new ViewRegistrationSource());
  var container = builder.Build();
  DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
  </code></pre>
  
  <p>The "child" views that use the layout do NOT derive from the CustomViewPage.</p>