title: How can autofac return service with constructor parameters?
body: <p>I am testing out Autofac container with these below:</p>
  
  <pre><code>var builder = new ContainerBuilder();
  
  builder.Register(t =&gt; new TreatmentCenterRepository())
    .As&lt;IRepository&lt;TreatmentCenter&gt;&gt;();
  
  builder.Register(t =&gt; new CreateTreatmentCenterCommandHandler(t.Resolve&lt;IRepository&lt;TreatmentCenter&gt;&gt;()))
    .As&lt;ICommandHandler&lt;CreateTreatmentCenterCommand&gt;&gt;();
  var container = builder.Build();
  var repo = container.Resolve&lt;IRepository&lt;TreatmentCenter&gt;&gt;();
  var handler = container.Resolve&lt;ICommandHandler&lt;TreatmentCenter&gt;&gt;();
  
  Console.WriteLine(repo);
  Console.WriteLine(handler);
  </code></pre>
  
  <p>The command handler implementation has one ctor with repository parameter.</p>
  
  <p>When I run this I get this exception:</p>
  
  <pre><code>Unhandled Exception: Autofac.Core.Registration.ComponentNotRegisteredException: The requested service 'Console
  Application2.ICommandHandler`1[[ConsoleApplication2.TreatmentCenter, ConsoleApplication2, Version=1.0.0.0, Cul
  ture=neutral, PublicKeyToken=null]]' has not been registered.
     at Autofac.ResolutionExtensions.Resolve(IComponentContext context, Service service, IEnumerable`1 parameter
  s)
     at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context, IEnumerable`1 parameters)
     at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context)
     at ConsoleApplication2.Program.Main(String[] args) in D:\Projects\Test Projects\ConsoleApplication2\Console
  Application2\Program.cs:line 30
  </code></pre>
  
  <p>Why is it barfing? I clearly registered that handler with the repository as ctor param.</p>
  
  <p>Thanks</p>