Class ServiceProviderServiceExtensions
- Namespace
- Microsoft.Extensions.DependencyInjection
- Assembly
- nanoFramework.DependencyInjection.dll
Extension methods for getting services from an IServiceProvider.
public static class ServiceProviderServiceExtensions
- Inheritance
-
ServiceProviderServiceExtensions
- Inherited Members
Methods
CreateScope(IServiceProvider)
Creates a new ServiceScope that can be used to resolve scoped services.
public static IServiceScope CreateScope(this IServiceProvider provider)
Parameters
provider
IServiceProviderThe IServiceProvider to create the scope from.
Returns
- IServiceScope
An ServiceScope that can be used to resolve scoped services.
Exceptions
- ArgumentNullException
provider
can't be null.
GetRequiredService(IServiceProvider, Type)
Get service of type serviceType
from the IServiceProvider.
public static object GetRequiredService(this IServiceProvider provider, Type serviceType)
Parameters
provider
IServiceProviderThe IServiceProvider to retrieve the service object from.
serviceType
TypeAn object that specifies the type of service object to get.
Returns
- object
A service object of type
serviceType
.
Exceptions
- InvalidOperationException
There is no service of type
serviceType
.- ArgumentNullException
provider
orserviceType
can't be null.
GetServices(IServiceProvider, Type)
Get an enumeration of services of type serviceType
from the IServiceProvider.
public static object[] GetServices(this IServiceProvider provider, Type serviceType)
Parameters
provider
IServiceProviderThe IServiceProvider to retrieve the services from.
serviceType
TypeAn object that specifies the type of service object to get.
Returns
- object[]
An array of services of type
serviceType
.
GetServices(IServiceProvider, Type[])
Get an enumeration of services of type serviceType
from the IServiceProvider.
public static object[] GetServices(this IServiceProvider provider, Type[] serviceType)
Parameters
provider
IServiceProviderThe IServiceProvider to retrieve the services from.
serviceType
Type[]An array of
serviceType
object that specifies the type of service object to get.
Returns
- object[]
An array of services of type
serviceType
.
Exceptions
- ArgumentNullException
'provider' or 'serviceType' can't be null.