How do I validate the DI container in ASP.NET Core? : <p>In my <code>Startup</code> class I use the <code>ConfigureServices(IServiceCollection services)</code> method to set up my service container, using the built-in DI container from <code>Microsoft.Extensions.DependencyInjection</code>.</p>

<p>I want to validate the dependency graph in an unit test to check that all of the services can be constructed, so that I can fix any services missing during unit testing instead of having the app crash at runtime. In previous projects I've used Simple Injector, which has a <code>.Verify()</code> method for the container. But I haven't been able to find anything similar for ASP.NET Core.</p>

<p><strong>Is there any built-in (or at least recommended) way of verifying that the entire dependency graph can be constructed?</strong></p>

<p>(The dumbest way I can think of is something like this, but it will still fail because of the open generics that are injected by the framework itself):</p>

<pre><code>startup.ConfigureServices(serviceCollection);
var provider = serviceCollection.BuildServiceProvider();
foreach (var serviceDescriptor in serviceCollection)
{
    provider.GetService(serviceDescriptor.ServiceType);
}
</code></pre>
