ServiceProviderServiceExtensions.GetRequiredService Method

Definition

Overloads

GetRequiredService(IServiceProvider, Type)

Get service of type serviceType from the IServiceProvider.

GetRequiredService<T>(IServiceProvider)

Get service of type T from the IServiceProvider.

GetRequiredService(IServiceProvider, Type)

Source:
ServiceProviderServiceExtensions.cs
Source:
ServiceProviderServiceExtensions.cs
Source:
ServiceProviderServiceExtensions.cs

Get service of type serviceType from the IServiceProvider.

public static object GetRequiredService (this IServiceProvider provider, Type serviceType);

Parameters

provider
IServiceProvider

The IServiceProvider to retrieve the service object from.

serviceType
Type

An object that specifies the type of service object to get.

Returns

A service object of type serviceType.

Exceptions

provider has already been disposed.

There is no service of type serviceType.

Applies to

.NET 9 (package-provided) et autres versions
Produit Versions
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)

GetRequiredService<T>(IServiceProvider)

Source:
ServiceProviderServiceExtensions.cs
Source:
ServiceProviderServiceExtensions.cs
Source:
ServiceProviderServiceExtensions.cs

Get service of type T from the IServiceProvider.

public static T GetRequiredService<T> (this IServiceProvider provider);

Type Parameters

T

The type of service object to get.

Parameters

provider
IServiceProvider

The IServiceProvider to retrieve the service object from.

Returns

T

A service object of type T.

Exceptions

provider has already been disposed.

There is no service of type T.

Applies to

.NET 9 (package-provided) et autres versions
Produit Versions
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)