ServiceProviderExtensions.GetRequiredService<TService> Method

Definition

Gets the required service of type TService from the IServiceProvider.

public static TService GetRequiredService<TService>(this IServiceProvider provider);
static member GetRequiredService : IServiceProvider -> 'Service
<Extension()>
Public Function GetRequiredService(Of TService) (provider As IServiceProvider) As TService

Type Parameters

TService

The type of the service.

Parameters

provider
IServiceProvider

The service provider.

Returns

TService

The required service of type TService.

Exceptions

Thrown when the provider is null.

Thrown when the required service is not found.

Applies to