title: Resolving dependencies in Integration test in ASP.NET Core
body: <p>I have ASP.NET Core API. I have already gone through documentation <a href="https://docs.microsoft.com/en-us/aspnet/core/testing/integration-testing" rel="noreferrer">here</a> that shows how to do integration testing in asp.net core. The example sets up a test server and then invoke controller method.<br>
  However I want to test a particular class method directly (not a controller method)? For example:</p>
  
  <pre><code>  public class MyService : IMyService
    {
        private readonly DbContext _dbContext;
  
        public MyService(DbContext dbContext)
        {
            _dbContext = dbContext;
        }
  
        public void DoSomething()
        {
            //do something here
        }             
    }
  </code></pre>
  
  <p>When the test starts I want <code>startup.cs</code> to be called so all the dependencies will get register. (like dbcontext) but I am not sure in integration test how do I resolve <code>IMyService</code>?</p>
  
  <p>Note: The reason I want to test <code>DoSomething()</code> method directly because this method will not get invoked by any controller. I am using <code>Hangfire</code> inside this API for background processing. The Hangfire's background processing job will call <code>DoSomething()</code> method. So for integration test I want to avoid using Hangfire and just directly call <code>DoSomething()</code> method</p>