title: Dependency Injection with XUnit and ASP.NET Core 1.0
body: <p>I am trying to figure out how I can use dependency injection with XUnit. My goal is to be able to inject my ProductRepository into my test class.</p>
  
  <p>Here is the code I am trying:</p>
  
  <pre><code>public class DatabaseFixture : IDisposable
  {
      private readonly TestServer _server;
  
      public DatabaseFixture()
      {
          _server = new TestServer(TestServer.CreateBuilder().UseStartup&lt;Startup&gt;());
      }
  
      public void Dispose()
      {
          // ... clean up test data from the database ...
      }
  }
  
  public class MyTests : IClassFixture&lt;DatabaseFixture&gt;
  {
      DatabaseFixture _fixture;
      public ICustomerRepository _repository { get; set; }
  
      public MyTests(DatabaseFixture fixture, ICustomerRepository repository)
      {
          _fixture = fixture;
          _repository = repository;
      }
  }
  </code></pre>
  
  <p><strong>Here is the error:</strong>
  The following constructor parameters did not have matching fixture data (ICustomerRepository repository)</p>
  
  <p>This leads me to believe that XUnit doens't support dependency injection, only if it is a Fixture.</p>
  
  <p>Can someone give me a way of getting an instance of ProductRepository in my test class using XUnit? I believe I am correctly starting up a test server so Startup.cs runs and configures the DI.</p>