共用方式為


ServiceCollectionServiceExtensions.AddKeyedSingleton 方法

定義

多載

AddKeyedSingleton(IServiceCollection, Type, Object, Type)

serviceType 中指定類型的單一服務,以及在 implementationType 中指定類型的實作,新增至指定的 IServiceCollection

AddKeyedSingleton(IServiceCollection, Type, Object, Object)

serviceType 中指定類型的單一服務,以及 implementationInstance 中指定的執行個體,新增至指定的 IServiceCollection

AddKeyedSingleton(IServiceCollection, Type, Object)

serviceType 中指定類型的單一服務,新增至指定的 IServiceCollection

AddKeyedSingleton(IServiceCollection, Type, Object, Func<IServiceProvider,Object,Object>)

serviceType 中指定類型的單一服務,以及 implementationFactory 中指定的 Factory,新增至指定的 IServiceCollection

AddKeyedSingleton<TService,TImplementation>(IServiceCollection, Object)

TService 中指定類型的單一服務,以及在 TImplementation 中指定的實作類型,新增至指定的 IServiceCollection

AddKeyedSingleton<TService,TImplementation>(IServiceCollection, Object, Func<IServiceProvider,Object,TImplementation>)

使用 implementationFactory 中指定的 Factory,將 TService 中指定類型的單一服務,以及 TImplementation 中指定的實作類型,新增至指定的 IServiceCollection

AddKeyedSingleton<TService>(IServiceCollection, Object)

TService 中指定類型的單一服務,新增至指定的 IServiceCollection

AddKeyedSingleton<TService>(IServiceCollection, Object, Func<IServiceProvider,Object,TService>)

TService 中指定類型的單一服務,以及 implementationFactory 中指定的 Factory,新增至指定的 IServiceCollection

AddKeyedSingleton<TService>(IServiceCollection, Object, TService)

TService 中指定類型的單一服務,以及 implementationInstance 中指定的執行個體,新增至指定的 IServiceCollection

AddKeyedSingleton(IServiceCollection, Type, Object, Type)

來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs

serviceType 中指定類型的單一服務,以及在 implementationType 中指定類型的實作,新增至指定的 IServiceCollection

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddKeyedSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, Type ^ serviceType, System::Object ^ serviceKey, Type ^ implementationType);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddKeyedSingleton (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Type serviceType, object? serviceKey, Type implementationType);
static member AddKeyedSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Type * obj * Type -> Microsoft.Extensions.DependencyInjection.IServiceCollection
<Extension()>
Public Function AddKeyedSingleton (services As IServiceCollection, serviceType As Type, serviceKey As Object, implementationType As Type) As IServiceCollection

參數

services
IServiceCollection

要新增服務的 IServiceCollection

serviceType
Type

要註冊的服務類型。

serviceKey
Object

服務的 ServiceKey

implementationType
Type

服務的實作類型。

傳回

完成作業之後,這個執行個體的參考。

另請參閱

適用於

AddKeyedSingleton(IServiceCollection, Type, Object, Object)

來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs

serviceType 中指定類型的單一服務,以及 implementationInstance 中指定的執行個體,新增至指定的 IServiceCollection

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddKeyedSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, Type ^ serviceType, System::Object ^ serviceKey, System::Object ^ implementationInstance);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddKeyedSingleton (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Type serviceType, object? serviceKey, object implementationInstance);
static member AddKeyedSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Type * obj * obj -> Microsoft.Extensions.DependencyInjection.IServiceCollection
<Extension()>
Public Function AddKeyedSingleton (services As IServiceCollection, serviceType As Type, serviceKey As Object, implementationInstance As Object) As IServiceCollection

參數

services
IServiceCollection

要新增服務的 IServiceCollection

serviceType
Type

要註冊的服務類型。

serviceKey
Object

服務的 ServiceKey

implementationInstance
Object

服務的執行個體。

傳回

完成作業之後,這個執行個體的參考。

另請參閱

適用於

AddKeyedSingleton(IServiceCollection, Type, Object)

來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs

serviceType 中指定類型的單一服務,新增至指定的 IServiceCollection

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddKeyedSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, Type ^ serviceType, System::Object ^ serviceKey);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddKeyedSingleton (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Type serviceType, object? serviceKey);
static member AddKeyedSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Type * obj -> Microsoft.Extensions.DependencyInjection.IServiceCollection
<Extension()>
Public Function AddKeyedSingleton (services As IServiceCollection, serviceType As Type, serviceKey As Object) As IServiceCollection

參數

services
IServiceCollection

要新增服務的 IServiceCollection

serviceType
Type

要註冊的服務類型,以及要使用的實作。

serviceKey
Object

服務的 ServiceKey

傳回

完成作業之後,這個執行個體的參考。

另請參閱

適用於

AddKeyedSingleton(IServiceCollection, Type, Object, Func<IServiceProvider,Object,Object>)

來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs

serviceType 中指定類型的單一服務,以及 implementationFactory 中指定的 Factory,新增至指定的 IServiceCollection

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddKeyedSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, Type ^ serviceType, System::Object ^ serviceKey, Func<IServiceProvider ^, System::Object ^, System::Object ^> ^ implementationFactory);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddKeyedSingleton (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Type serviceType, object? serviceKey, Func<IServiceProvider,object?,object> implementationFactory);
static member AddKeyedSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Type * obj * Func<IServiceProvider, obj, obj> -> Microsoft.Extensions.DependencyInjection.IServiceCollection
<Extension()>
Public Function AddKeyedSingleton (services As IServiceCollection, serviceType As Type, serviceKey As Object, implementationFactory As Func(Of IServiceProvider, Object, Object)) As IServiceCollection

參數

services
IServiceCollection

要新增服務的 IServiceCollection

serviceType
Type

要註冊的服務類型。

serviceKey
Object

服務的 ServiceKey

implementationFactory
Func<IServiceProvider,Object,Object>

建立服務的 Factory。

傳回

完成作業之後,這個執行個體的參考。

另請參閱

適用於

AddKeyedSingleton<TService,TImplementation>(IServiceCollection, Object)

來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs

TService 中指定類型的單一服務,以及在 TImplementation 中指定的實作類型,新增至指定的 IServiceCollection

public:
generic <typename TService, typename TImplementation>
 where TService : class where TImplementation : class, TService[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddKeyedSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, System::Object ^ serviceKey);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddKeyedSingleton<TService,TImplementation> (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, object? serviceKey) where TService : class where TImplementation : class, TService;
static member AddKeyedSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * obj -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Service : null)
<Extension()>
Public Function AddKeyedSingleton(Of TService As Class, TImplementation As Class) (services As IServiceCollection, serviceKey As Object) As IServiceCollection

類型參數

TService

要新增的服務類型。

TImplementation

要使用的實作類型。

參數

services
IServiceCollection

要新增服務的 IServiceCollection

serviceKey
Object

服務的 ServiceKey

傳回

完成作業之後,這個執行個體的參考。

另請參閱

適用於

AddKeyedSingleton<TService,TImplementation>(IServiceCollection, Object, Func<IServiceProvider,Object,TImplementation>)

來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs

使用 implementationFactory 中指定的 Factory,將 TService 中指定類型的單一服務,以及 TImplementation 中指定的實作類型,新增至指定的 IServiceCollection

public:
generic <typename TService, typename TImplementation>
 where TService : class where TImplementation : class, TService[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddKeyedSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, System::Object ^ serviceKey, Func<IServiceProvider ^, System::Object ^, TImplementation> ^ implementationFactory);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddKeyedSingleton<TService,TImplementation> (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, object? serviceKey, Func<IServiceProvider,object?,TImplementation> implementationFactory) where TService : class where TImplementation : class, TService;
static member AddKeyedSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * obj * Func<IServiceProvider, obj, #'Service> -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Service : null)
<Extension()>
Public Function AddKeyedSingleton(Of TService As Class, TImplementation As Class) (services As IServiceCollection, serviceKey As Object, implementationFactory As Func(Of IServiceProvider, Object, TImplementation)) As IServiceCollection

類型參數

TService

要新增的服務類型。

TImplementation

要使用的實作類型。

參數

services
IServiceCollection

要新增服務的 IServiceCollection

serviceKey
Object

服務的 ServiceKey

implementationFactory
Func<IServiceProvider,Object,TImplementation>

建立服務的 Factory。

傳回

完成作業之後,這個執行個體的參考。

另請參閱

適用於

AddKeyedSingleton<TService>(IServiceCollection, Object)

來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs

TService 中指定類型的單一服務,新增至指定的 IServiceCollection

public:
generic <typename TService>
 where TService : class[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddKeyedSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, System::Object ^ serviceKey);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddKeyedSingleton<TService> (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, object? serviceKey) where TService : class;
static member AddKeyedSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * obj -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Service : null)
<Extension()>
Public Function AddKeyedSingleton(Of TService As Class) (services As IServiceCollection, serviceKey As Object) As IServiceCollection

類型參數

TService

要新增的服務類型。

參數

services
IServiceCollection

要新增服務的 IServiceCollection

serviceKey
Object

服務的 ServiceKey

傳回

完成作業之後,這個執行個體的參考。

另請參閱

適用於

AddKeyedSingleton<TService>(IServiceCollection, Object, Func<IServiceProvider,Object,TService>)

來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs

TService 中指定類型的單一服務,以及 implementationFactory 中指定的 Factory,新增至指定的 IServiceCollection

public:
generic <typename TService>
 where TService : class[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddKeyedSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, System::Object ^ serviceKey, Func<IServiceProvider ^, System::Object ^, TService> ^ implementationFactory);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddKeyedSingleton<TService> (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, object? serviceKey, Func<IServiceProvider,object?,TService> implementationFactory) where TService : class;
static member AddKeyedSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * obj * Func<IServiceProvider, obj, 'Service (requires 'Service : null)> -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Service : null)
<Extension()>
Public Function AddKeyedSingleton(Of TService As Class) (services As IServiceCollection, serviceKey As Object, implementationFactory As Func(Of IServiceProvider, Object, TService)) As IServiceCollection

類型參數

TService

要新增的服務類型。

參數

services
IServiceCollection

要新增服務的 IServiceCollection

serviceKey
Object

服務的 ServiceKey

implementationFactory
Func<IServiceProvider,Object,TService>

建立服務的 Factory。

傳回

完成作業之後,這個執行個體的參考。

另請參閱

適用於

AddKeyedSingleton<TService>(IServiceCollection, Object, TService)

來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs
來源:
ServiceCollectionServiceExtensions.Keyed.cs

TService 中指定類型的單一服務,以及 implementationInstance 中指定的執行個體,新增至指定的 IServiceCollection

public:
generic <typename TService>
 where TService : class[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddKeyedSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, System::Object ^ serviceKey, TService implementationInstance);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddKeyedSingleton<TService> (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, object? serviceKey, TService implementationInstance) where TService : class;
static member AddKeyedSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * obj * 'Service -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Service : null)
<Extension()>
Public Function AddKeyedSingleton(Of TService As Class) (services As IServiceCollection, serviceKey As Object, implementationInstance As TService) As IServiceCollection

類型參數

TService

參數

services
IServiceCollection

要新增服務的 IServiceCollection

serviceKey
Object

服務的 ServiceKey

implementationInstance
TService

服務的執行個體。

傳回

完成作業之後,這個執行個體的參考。

另請參閱

適用於