Class IServiceProviderExtensions
Extension methods for IServiceProvider.
public static class IServiceProviderExtensions
- Inheritance
-
IServiceProviderExtensions
- Inherited Members
Methods
GetLogger<TCategoryName>(IServiceProvider)
Get a logger where the category name is derived from the specified TCategoryName type name.
public static ILogger<TCategoryName> GetLogger<TCategoryName>(this IServiceProvider serviceProvider)
Parameters
serviceProviderIServiceProviderThe service provider.
Returns
- ILogger<TCategoryName>
The logger.
Type Parameters
TCategoryNameThe type who's name is used for the logger category name.
Remarks
This will always return a logger. If serviceProvider does not provide one, a NullLogger<T> will be returned.
Exceptions
- ArgumentNullException
serviceProvideris null.
GetRequiredService<T>(IServiceProvider)
Gets the service object of the specified type, throwing an exception if there is no service of that type.
public static T GetRequiredService<T>(this IServiceProvider serviceProvider)
Parameters
serviceProviderIServiceProviderThe service provider.
Returns
- T
A service object of type
T.
Type Parameters
TThe type of service object to get.
Exceptions
- ArgumentNullException
serviceProvideris null.- InvalidOperationException
Required service of type
Tis not available.
GetService<T>(IServiceProvider)
Gets the service object of the specified type.
public static T GetService<T>(this IServiceProvider serviceProvider)
Parameters
serviceProviderIServiceProviderThe service provider.
Returns
- T
A service object of type
T, or null if there is no service object of typeT.
Type Parameters
TThe type of service object to get.
Exceptions
- ArgumentNullException
serviceProvideris null.