title: Castle Windsor, dependency injections return null
body: <p>Probably my idea is wrong from the beginning.</p>
  
  <p>I have an MVC5 project, and I'm tring to implement a repository layer between my website and EF (for semplicity, it's a learning project).</p>
  
  <p>I have an EF Code First Context, and a Repository class:</p>
  
  <pre><code>public interface IRepository&lt;TDbContext&gt; : IDisposable where TDbContext : class, new()
  
  public class Repository&lt;TContext&gt; : IRepository&lt;TContext&gt;, IDisposable where TContext : DbContext, new()
  </code></pre>
  
  <p>Then I have a second layer where I implement additional functions:</p>
  
  <pre><code>public interface ILog&lt;TLogContext&gt; : IRepository&lt;TLogContext&gt; where TLogContext : class, new()
  
  public class Logger&lt;TContext&gt; : Repository&lt;TContext&gt;, ILog&lt;TContext&gt; where TContext : LogContext, new()
  </code></pre>
  
  <p>The porpouse is to use the generic repository for all my contexts, and to create separate contexts and separate "second layers" for different areas/scopes inside my website (Logging, Account Management, etc), so I can use, if I want, different DB implementations.</p>
  
  <p>And this is the Windsor implementation:</p>
  
  <p><code>Installer.cs</code>:</p>
  
  <pre><code>public class Installer : IWindsorInstaller
  {
      public void Install(IWindsorContainer container, IConfigurationStore store)
      {
          // Controller
          container.Register(
              Classes.FromThisAssembly().BasedOn&lt;IController&gt;().LifestyleTransient());
  
          // EF, Business
          container.Register(
              Component.For&lt;IRepository&lt;LogContext&gt;&gt;()
                       .ImplementedBy&lt;Repository&lt;LogContext&gt;&gt;()
                       .LifestylePerWebRequest()
          );
  
          container.Register(
              Component.For&lt;ILog&lt;LogContext&gt;&gt;()
                       .ImplementedBy&lt;Logger&lt;LogContext&gt;&gt;()
                       .LifestylePerWebRequest()
          );
      }
  }
  </code></pre>
  
  <p><code>ControllerFactory.cs</code>:</p>
  
  <pre><code>public class ControllerFactory : DefaultControllerFactory
  {
      private readonly IKernel kernel;
  
      public ControllerFactory(IKernel kernel)
      {
          this.kernel = kernel;
      }
  
      public override void ReleaseController(IController controller)
      {
          kernel.ReleaseComponent(controller);
      }
  
      protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
      {
          if (controllerType == null)
          {
              throw new HttpException(404, string.Format("The controller for path '{0}' could not be found.", requestContext.HttpContext.Request.Path));
          }
  
          return (IController)kernel.Resolve(controllerType);
      }
  }
  </code></pre>
  
  <p>And in <code>Global.asax</code>:</p>
  
  <pre><code>protected void Application_Start()
      {
          AreaRegistration.RegisterAllAreas();
          FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
          RouteConfig.RegisterRoutes(RouteTable.Routes);
  
          // Windsor
          container = new WindsorContainer().Install(FromAssembly.This());
  
          // ContainerFactory loading
          ControllerBuilder.Current.SetControllerFactory(new ControllerFactory(container.Kernel));
      }
  </code></pre>
  
  <p><code>BaseController.cs</code>:</p>
  
  <pre><code>public class BaseController : Controller
  {
      // Services
      internal ILog&lt;LogContext&gt; Logger { get; set; }
  
      public void Test()
      {
          var allEvents = Logger.All&lt;Event&gt;();
      }
  }
  </code></pre>
  
  <p>And... <code>Logger</code> is null. Why?</p>