title: A .NET Unit Test without a parameterless constructor, to facilitate dependency injection
body: <p>I'm trying to have the unit tests not rely on calling <em>container.Resolve&lt;T&gt;()</em> for their dependencies.</p>
  
  <p>I'm currently using <strong>AutoFac</strong> 2.2.4, and tried <strong>xUnit.NET</strong> and <strong>NUnit</strong>, but both have <strong>this issue</strong>:</p>
  
  <blockquote>
    <p>No parameterless constructor defined for this object</p>
  </blockquote>
  
  <p>How do I get past this issue? Is it a particular unit testing framework that will support this, or just how said framework is configured?</p>
  
  <p>Should I not be doing this? Or can I set up the test class to work with the constructor that has it's only dependency?</p>
  
  <p>Here's some of the code:</p>
  
  <pre><code>public class ProductTests : BaseTest
  {
      readonly private IProductRepository _repo;
  
      public ProductTests(IProductRepository r)
      {
          _repo = r;
      }
  
      //working unit tests here with default constructor
  } 
  </code></pre>
  
  <p>Did I choose to initialise the container wrongly in the base class constructor?</p>
  
  <pre><code>public abstract class BaseTest
  {
      protected BaseTest()
      {
          var builder = new ContainerBuilder();
          builder.RegisterType&lt;ProductRepository&gt;().As&lt;IProductRepository&gt;();
          builder.Build();
      }
  }
  </code></pre>