title: Unity [dependency] injection and Inheritance
body: <p>My question is as follows:
  I have a base controller (ASP.Net MVC controller) called ApplicationController, and I want all my controller to inherit from it. this base controller has a ILogger property, marked with a [Dependency] attribute. (yes, I know I should use constructor injection, I'm just curious about this attribute).</p>
  
  <p>I created the container, registered types, changed the default factory, everything is fine. the problem is that when I try to use my Logger property in the derived controller, it's not resolved.</p>
  
  <p>what am I doing wrong? why doesn't the container resolves the base class dependencies when creating the derived controller?</p>
  
  <p>code samples:</p>
  
  <hr>
  
  <p>ApplicationController:</p>
  
  <pre><code>public class ApplicationController : Controller
  {
      [Dependency]
      protected ILogger _logger { get; set; }
  
  }
  </code></pre>
  
  <p>derived controller:</p>
  
  <pre><code>public class HomeController : ApplicationController
  {
      public HomeController()
      {
  
      }
      public ActionResult Index()
      {
          _logger.Log("Home controller constructor started.");
          ViewData["Message"] = "Welcome to ASP.NET MVC!";
  
          return View();
      }
  
      public ActionResult About()
      {
          return View();
      }
  }
  </code></pre>
  
  <p>Unity controller factory:</p>
  
  <pre><code>public class UnityControllerFactory : DefaultControllerFactory
  {
      private readonly IUnityContainer _container;
      public UnityControllerFactory(IUnityContainer container)
      {
          _container = container;
      }
  
      protected override IController GetControllerInstance(Type controllerType)
      {
          return _container.Resolve(controllerType) as IController;
      }
  }
  </code></pre>
  
  <p>Global.asax.cs sample:</p>
  
  <pre><code>protected void Application_Start()
      {
          _container = new UnityContainer();
          _container.RegisterType&lt;ILogger, Logger.Logger&gt;();
          UnityControllerFactory factory = new UnityControllerFactory(_container);
          ControllerBuilder.Current.SetControllerFactory(factory);
  
          RegisterRoutes(RouteTable.Routes);
      }
  </code></pre>
  
  <hr>
  
  <p>I'm quite new to Unity, so maybe I did something wrong.</p>
  
  <p>thanks,
  Ami.</p>