次の方法で共有


NamedServiceProviderExtensions.GetRequiredService<TService> Method

Definition

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

public:
generic <typename TService>
 where TService : class[System::Runtime::CompilerServices::Extension]
 static TService GetRequiredService(Microsoft::Extensions::DependencyInjection::INamedServiceProvider<TService> ^ provider, System::String ^ name);
public static TService GetRequiredService<TService>(this Microsoft.Extensions.DependencyInjection.INamedServiceProvider<TService> provider, string name) where TService : class;
static member GetRequiredService : Microsoft.Extensions.DependencyInjection.INamedServiceProvider<'Service (requires 'Service : null)> * string -> 'Service (requires 'Service : null)
<Extension()>
Public Function GetRequiredService(Of TService As Class) (provider As INamedServiceProvider(Of TService), name As String) As TService

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