title: 'Autofac Circular Component Dependency Detected' Error
body: <p>I am new to IoC and am using Autofac in my current project.</p>
  
  <p>I have the following 2 classes:</p>
  
  <pre><code>public class UserService : IUserService
  {
      private readonly IUserRepository _repo;
      private readonly IMailService _mailService;
      public UserService(IUserRepository repo, IMailService mailService)
      {
          _repo = repo;
          _mailService = mailService;
      }
  }
  
  public class MailService : IMailService
  {
      private readonly IMailRepository _repo;
      private readonly IUserService _userService;
      public MailService(IMailRepository repo, IUserService userService)
      {
          _repo = repo;
          _userService = userService;
      }
  }
  </code></pre>
  
  <p>Initially, my UserService class didn't require an instance of the MailService class, but now it does, and it's since introducing this into the UserService Constructor that this circular dependency error has arisen, and being a newbie, I'm not sure how to resolve this.</p>
  
  <p>This is how my classes are currently registered in Autofac:</p>
  
  <pre><code>var builder = new ContainerBuilder();
  
  // controllers                      
  builder.RegisterControllers(Assembly.GetAssembly(typeof(UsersController)));
  
  // register other classes
  builder.RegisterType&lt;UserRepository&gt;().As&lt;IUserRepository&gt;();
  builder.RegisterType&lt;MailRepository&gt;().As&lt;IMailRepository&gt;();
  builder.RegisterType&lt;UserService&gt;().As&lt;IUserService&gt;();
  builder.RegisterType&lt;MailService&gt;().As&lt;IMailService&gt;();
  </code></pre>