title: Net Core: Dependency Injection in Integration Test
body: <p>How do I conduct the Dependency Injection in Integration Test?
  Calling the <code>departmentRepository</code> or <code>departmentAppService</code>, is giving me <code>null</code> and error below.</p>
  
  <pre><code>public class DepartmentAppServiceTest
  {
      public SharedServicesContext context;
      public IMapper mapper;
      public IRepository&lt;Department, int&gt; departmentRepository;
      public IDepartmentAppService departmentAppService;
  
      public DepartmentAppServiceTest()
      {
          ServiceCollection services = new ServiceCollection();
          services.AddTransient&lt;IRepository&lt;Department&gt;, BaseRepository&lt;Department&gt;&gt;();
          services.AddTransient&lt;IDepartmentAppService, DepartmentAppService&gt;();
  </code></pre>
  
  <p>debugging and setting breakpoints, both calling this repository or app service are null,</p>
  
  <p>new method</p>
  
  <pre><code> [Fact]
   var departmentDto = await departmentAppService.GetDepartmentById(2);
  </code></pre>
  
  <p>Constructors for App Service</p>
  
  <pre><code>DepartmentAppService(departmentRepository, mapper)
  DepartmentRepository(dbcontext)
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <blockquote>
    <p>Message: System.NullReferenceException : Object reference not set to
    an instance of an object.</p>
  </blockquote>