ServiceCollectionDescriptorExtensions.TryAddKeyedSingleton 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重载
TryAddKeyedSingleton(IServiceCollection, Type, Object)
如果服务类型尚未注册,则将指定的 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)
参数
- collection
- IServiceCollection
- service
- Type
要注册的服务类型。
- serviceKey
- Object
服务密钥。
适用于
TryAddKeyedSingleton(IServiceCollection, Type, Object, Func<IServiceProvider,Object,Object>)
如果服务类型尚未注册,则使用 implementationFactory
中指定的中心将指定的 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))
参数
- collection
- IServiceCollection
- service
- Type
要注册的服务类型。
- serviceKey
- Object
服务密钥。
- implementationFactory
- Func<IServiceProvider,Object,Object>
用于创建服务的工厂。
适用于
TryAddKeyedSingleton(IServiceCollection, Type, Object, Type)
如果服务类型尚未注册,则使用 implementationType
实现将指定的 service
作为 Singleton 服务添加到 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)
参数
- collection
- IServiceCollection
- service
- Type
要注册的服务类型。
- serviceKey
- Object
服务密钥。
- implementationType
- Type
服务的实现类型。
适用于
TryAddKeyedSingleton<TService,TImplementation>(IServiceCollection, Object)
如果服务类型尚未注册,则将指定的 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
要使用的实现的类型。
参数
- collection
- IServiceCollection
- serviceKey
- Object
服务密钥。
适用于
TryAddKeyedSingleton<TService>(IServiceCollection, Object)
如果服务类型尚未注册,则将指定的 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
要添加的服务类型。
参数
- collection
- IServiceCollection
- serviceKey
- Object
服务密钥。
适用于
TryAddKeyedSingleton<TService>(IServiceCollection, Object, Func<IServiceProvider,Object,TService>)
如果服务类型尚未注册,则使用 implementationFactory
中指定的中心将指定的 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
要添加的服务类型。
参数
- services
- IServiceCollection
- serviceKey
- Object
服务密钥。
- implementationFactory
- Func<IServiceProvider,Object,TService>
用于创建服务的工厂。
适用于
TryAddKeyedSingleton<TService>(IServiceCollection, Object, TService)
如果服务类型尚未注册,则将指定的 TService
作为包含 instance
中指定的实例的 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
要添加的服务类型。
参数
- collection
- IServiceCollection
- serviceKey
- Object
服务密钥。
- instance
- TService
要添加的服务的实例。