title: How to resolve dependency in Web API constructor in .net core
body: <p>I am new to .net core and dependency injection concept. I want to inject service interface in Web API constructor, Service interface and implementation is in different project. Please find below layers of my application,</p>
  
  <p><a href="https://i.stack.imgur.com/rga9v.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rga9v.png" alt="Application Layers"></a></p>
  
  <p>In startup.cs, I already add below line,</p>
  
  
  
  <pre class="lang-cs prettyprint-override"><code>public void ConfigureServices(IServiceCollection services)
  {
      // Add framework services.
      services.AddMvc();
  
      services.AddSingleton&lt;IEntriesService, EntriesService&gt;();
  }
  </code></pre>
  
  <p>My controller,</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class EntriesController : Controller
  {
      IEntriesService entryService;
      public EntriesController(IEntriesService _entryService)
      {
          entryService = _entryService;
      }
  
      // GET: api/values
      [HttpGet]
      public IEnumerable&lt;string&gt; Get()
      {
          return new string[] { "value1", "value2" };
      }
  }
  </code></pre>
  
  <p>Problem is, When I execute my API application, It is not hitting to my constructor and shows me blank page as below,</p>
  
  <p><a href="https://i.stack.imgur.com/InGsb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/InGsb.png" alt="Error page"></a></p>
  
  <p>Without adding constructor, Application is working fine.</p>
  
  <p>My IEntriesService,</p>
  
  <pre class="lang-cs prettyprint-override"><code>public interface IEntriesService
  {
      RepeatEntries Get(int Id);
  }
  </code></pre>
  
  <p>My EntriesService,</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class EntriesService : IEntriesService
  {
      IUnitOfWork _unitOfWork;
      public EntriesService(IUnitOfWork unitOfWork)
      {
          _unitOfWork = unitOfWork;
      }
  
      public bool Add(RepeatEntries entity)
      {
          _unitOfWork.EntryRepository.Add(entity);
          return true;
      }
  }
  </code></pre>
  
  <p>My IUnitOfWork,</p>
  
  <pre class="lang-cs prettyprint-override"><code>public interface IUnitOfWork : IDisposable
  {
      IEntriesRepository EntryRepository { get; }
      void Complete();
  }
  </code></pre>
  
  <p>My UnitOfWork,</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class UnitOfWork : IUnitOfWork
  {
      private readonly IEntriesRepository _entryRepository;
      public UnitOfWork(IEntriesRepository entryRepository)
      {
          _entryRepository = entryRepository;
      }
  
      public IEntriesRepository EntryRepository
      {
          get
          {
              return _entryRepository;
          }
      }
  
      void IUnitOfWork.Complete()
      {
          throw new NotImplementedException();
      }
  
      #region IDisposable Support
      private bool disposedValue = false; // To detect redundant calls
  
  
  
      protected virtual void Dispose(bool disposing)
      {
          if (!disposedValue)
          {
              if (disposing)
              {
                  // TODO: dispose managed state (managed objects).
              }
  
              // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
              // TODO: set large fields to null.
  
              disposedValue = true;
          }
      }
  
      // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources.
      // ~UnitOfWork() {
      //   // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
      //   Dispose(false);
      // }
  
      // This code added to correctly implement the disposable pattern.
      void IDisposable.Dispose()
      {
          // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
          Dispose(true);
          // TODO: uncomment the following line if the finalizer is overridden above.
          // GC.SuppressFinalize(this);
      }
      #endregion
  }
  </code></pre>
  
  <p>What else I need to add to make it work? Is it possible or I need to change my approach?</p>