title: Configuring 'deep' dependencies with Unity IoC
body: <p>Let's say I have the following classes and interfaces in my MVC 2 project:</p>
  
  <p>Repositories:</p>
  
  <p>IRepository1, IRepository2, IRepository3</p>
  
  <pre><code>public class ConcreteRepository1 : IRepository1
  {
       public ConcreteRepository1()
       {
           ...
       }
       ...
  }
  
  public class ConcreteRepository2 : IRepository2
  {
       public ConcreteRepository2()
       {
           ...
       }
       ...
  }
  
  public class ConcreteRepository3 : IRepository3
  {
       public ConcreteRepository3()
       {
           ...
       }
       ...
  }
  </code></pre>
  
  <p>Service classes:</p>
  
  <pre><code>public class Service1
  {
      private IRepository1 repo1;
      private IRepository2 repo2;
  
      public Service1(IRepository1 repo1, IRepository2 repo2)
      {
          this.repo1 = repo1;
          this.repo2 = repo2;
      }
      ...
  }
  </code></pre>
  
  <p>Controllers:</p>
  
  <pre><code>public class Controller1 : Controller
  {
      private Service1 srv1;
      private Service2 srv2;
  
      public Controller1(Service1 srv1, Service2 srv2)
      {
          this.srv1 = srv1;
          this.srv2 = srv2;
      }
      ...
  }
  </code></pre>
  
  <p>I have custom ControllerFactory and I know how to tie concrete repositories to interfaces:</p>
  
  <pre><code>IUnityContainer container = new UnityContainer();
  container.RegisterType&lt;IRepository1, ConcreteRepository1&gt;(new TransientLifetimeManager(), new InjectionConstructor());
  container.RegisterType&lt;IRepository2, ConcreteRepository2&gt;(new TransientLifetimeManager(), new InjectionConstructor());
  container.RegisterType&lt;IRepository3, ConcreteRepository3&gt;(new TransientLifetimeManager(), new InjectionConstructor());
  </code></pre>
  
  <p>The question is how should I register services' instances and controllers' types inside my custom ControllerFactory to make unity container resolve the whole hierarchy Controller->Service->Repository and avoid calling Resolve inside controllers or services?</p>
  
  <p>Thanks.</p>