title: Why ServiceProvider is unable to create instance of controller in ASP.NET Core?
body: <p>I develop integration tests in .NET Core. Because controllers have multiple dependencies it's inconvenient to create their instances manually. Here's how I create ServiceProvider instance to be able to access .NET Core native DI container:</p>
  
  <pre><code>HostingEnvironment env = new HostingEnvironment();
  env.ContentRootPath = Directory.GetCurrentDirectory();
  env.EnvironmentName = "Development";
  
  Startup startup = new Startup(env);
  ServiceCollection sc = new ServiceCollection();
  startup.ConfigureServices(sc);
  ServiceProvider = sc.BuildServiceProvider();
  </code></pre>
  
  <p><code>Startup</code> class is taken from tested assembly.</p>
  
  <p>To my surprise service provider is unable to create instances of controllers. It can instantiate registered services, but not the controllers. Does anybody have any idea why it is so?</p>