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
providerIServiceProviderThe IServiceProvider to create the scope from.
Returns
- IServiceScope
An ServiceScope that can be used to resolve scoped services.
Exceptions
- ArgumentNullException
providercan't be null.
GetRequiredService(IServiceProvider, Type)
Get service of type serviceType from the IServiceProvider.
public static object GetRequiredService(this IServiceProvider provider, Type serviceType)
Parameters
providerIServiceProviderThe IServiceProvider to retrieve the service object from.
serviceTypeTypeAn 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
providerorserviceTypecan'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
providerIServiceProviderThe IServiceProvider to retrieve the services from.
serviceTypeTypeAn 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
providerIServiceProviderThe IServiceProvider to retrieve the services from.
serviceTypeType[]An array of
serviceTypeobject 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.