最佳答案
IServiceProvider
is an interface with single method:
object GetService(Type serviceType);
It's used to create instances of types registered in .NET Core native DI container.
An instance of IServiceProvider
itself can be obtained by calling a BuildServiceProvider
method of an IServiceCollection
. IServiceCollection
is a parameter of ConfigureServices
method in a Startup
class. It seems to be magically called with an instance of IServiceCollection
by the framework.
I want to create an instance of IServiceProvider
without having Setup
method at all. I need it to resolve dependencies in an integration test assembly. Is it possible to get it at all in this scenario?