NamedServiceProviderExtensions.GetRequiredService<TService> Method

Definition

Get service of type TService from the INamedServiceProvider<TService>.

C#
public static TService GetRequiredService<TService>(this Microsoft.Extensions.DependencyInjection.INamedServiceProvider<TService> provider, string name) where TService : class;

Type Parameters

TService

The type of service object to get.

Parameters

provider
INamedServiceProvider<TService>

The INamedServiceProvider<TService> to retrieve the service object from.

name
String

The name of the service.

Returns

TService

A service object of type TService.

Exceptions

There is no service of type TService with the name.

Remarks

This method returns the latest TService registered under the name.

Applies to

Proizvod Verzije
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)