共用方式為


ServiceCollectionDescriptorExtensions.TryAddKeyedSingleton 方法

定義

多載

TryAddKeyedSingleton(IServiceCollection, Type, Object)

如果尚未註冊服務類型,則將指定的 service 作為 Singleton 服務新增至 collection

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

如果尚未註冊服務類型,則使用 implementationFactory 中指定的 Factory,將指定的 service 作為 Singleton 服務新增至 collection

TryAddKeyedSingleton(IServiceCollection, Type, Object, Type)

如果尚未註冊服務類型,則將所指定 service 作為具有 implementationTypeSingleton 服務新增至 collection

TryAddKeyedSingleton<TService,TImplementation>(IServiceCollection, Object)

如果尚未註冊服務類型,則將指定 TService 作為 TImplementation 中指定的 Singleton 服務實作類型新增至 collection

TryAddKeyedSingleton<TService>(IServiceCollection, Object)

如果尚未註冊服務類型,則將指定的 TService 作為 Singleton 服務新增至 collection

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

如果尚未註冊服務類型,則使用 implementationFactory 中指定的 Factory,將指定的 TService 作為 Singleton 服務新增至 services

TryAddKeyedSingleton<TService>(IServiceCollection, Object, TService)

如果尚未註冊服務類型,則使用 instance 中指定的執行個體,將指定的 TService 作為 Singleton 服務新增至 collection

TryAddKeyedSingleton(IServiceCollection, Type, Object)

來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs

如果尚未註冊服務類型,則將指定的 service 作為 Singleton 服務新增至 collection

public:
[System::Runtime::CompilerServices::Extension]
 static void TryAddKeyedSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ collection, Type ^ service, System::Object ^ serviceKey);
public static void TryAddKeyedSingleton (this Microsoft.Extensions.DependencyInjection.IServiceCollection collection, Type service, object? serviceKey);
static member TryAddKeyedSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Type * obj -> unit
<Extension()>
Public Sub TryAddKeyedSingleton (collection As IServiceCollection, service As Type, serviceKey As Object)

參數

service
Type

要註冊的服務類型。

serviceKey
Object

服務金鑰。

適用於

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

來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs

如果尚未註冊服務類型,則使用 implementationFactory 中指定的 Factory,將指定的 service 作為 Singleton 服務新增至 collection

public:
[System::Runtime::CompilerServices::Extension]
 static void TryAddKeyedSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ collection, Type ^ service, System::Object ^ serviceKey, Func<IServiceProvider ^, System::Object ^, System::Object ^> ^ implementationFactory);
public static void TryAddKeyedSingleton (this Microsoft.Extensions.DependencyInjection.IServiceCollection collection, Type service, object? serviceKey, Func<IServiceProvider,object?,object> implementationFactory);
static member TryAddKeyedSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Type * obj * Func<IServiceProvider, obj, obj> -> unit
<Extension()>
Public Sub TryAddKeyedSingleton (collection As IServiceCollection, service As Type, serviceKey As Object, implementationFactory As Func(Of IServiceProvider, Object, Object))

參數

service
Type

要註冊的服務類型。

serviceKey
Object

服務金鑰。

implementationFactory
Func<IServiceProvider,Object,Object>

建立服務的 Factory。

適用於

TryAddKeyedSingleton(IServiceCollection, Type, Object, Type)

來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs

如果尚未註冊服務類型,則將所指定 service 作為具有 implementationTypeSingleton 服務新增至 collection

public:
[System::Runtime::CompilerServices::Extension]
 static void TryAddKeyedSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ collection, Type ^ service, System::Object ^ serviceKey, Type ^ implementationType);
public static void TryAddKeyedSingleton (this Microsoft.Extensions.DependencyInjection.IServiceCollection collection, Type service, object? serviceKey, Type implementationType);
static member TryAddKeyedSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Type * obj * Type -> unit
<Extension()>
Public Sub TryAddKeyedSingleton (collection As IServiceCollection, service As Type, serviceKey As Object, implementationType As Type)

參數

service
Type

要註冊的服務類型。

serviceKey
Object

服務金鑰。

implementationType
Type

服務的實作類型。

適用於

TryAddKeyedSingleton<TService,TImplementation>(IServiceCollection, Object)

來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs

如果尚未註冊服務類型,則將指定 TService 作為 TImplementation 中指定的 Singleton 服務實作類型新增至 collection

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

類型參數

TService

要新增的服務類型。

TImplementation

要使用的實作類型。

參數

serviceKey
Object

服務金鑰。

適用於

TryAddKeyedSingleton<TService>(IServiceCollection, Object)

來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs

如果尚未註冊服務類型,則將指定的 TService 作為 Singleton 服務新增至 collection

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

類型參數

TService

要新增的服務類型。

參數

serviceKey
Object

服務金鑰。

適用於

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

來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs

如果尚未註冊服務類型,則使用 implementationFactory 中指定的 Factory,將指定的 TService 作為 Singleton 服務新增至 services

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

類型參數

TService

要新增的服務類型。

參數

serviceKey
Object

服務金鑰。

implementationFactory
Func<IServiceProvider,Object,TService>

建立服務的 Factory。

適用於

TryAddKeyedSingleton<TService>(IServiceCollection, Object, TService)

來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs
來源:
ServiceCollectionDescriptorExtensions.Keyed.cs

如果尚未註冊服務類型,則使用 instance 中指定的執行個體,將指定的 TService 作為 Singleton 服務新增至 collection

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

類型參數

TService

要新增的服務類型。

參數

serviceKey
Object

服務金鑰。

instance
TService

要新增的服務執行個體。

適用於