ServiceProviderExtensions.GetService<TService>(IServiceProvider) Method

Definition

Gets the service of type TService from the IServiceProvider.

public static TService? GetService<TService>(this IServiceProvider provider) where TService : class;
static member GetService : IServiceProvider -> 'Service (requires 'Service : null)
<Extension()>
Public Function GetService(Of TService As Class) (provider As IServiceProvider) As TService

Type Parameters

TService

The type of the service.

Parameters

provider
IServiceProvider

The service provider.

Returns

TService

The service of type TService or null if not found.

Exceptions

Thrown when the provider is null.

Applies to