AutoActivationExtensions.TryAddActivatedSingleton 方法
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
TryAddActivatedSingleton(IServiceCollection, Type) |
尝试添加自动激活的单一实例服务。 |
TryAddActivatedSingleton(IServiceCollection, Type, Func<IServiceProvider,Object>) |
尝试添加自动激活的单一实例服务。 |
TryAddActivatedSingleton(IServiceCollection, Type, Type) |
尝试添加自动激活的单一实例服务。 |
TryAddActivatedSingleton<TService,TImplementation>(IServiceCollection) |
尝试添加自动激活的单一实例服务。 |
TryAddActivatedSingleton<TService>(IServiceCollection, Func<IServiceProvider,TService>) |
尝试添加自动激活的单一实例服务。 |
TryAddActivatedSingleton<TService>(IServiceCollection) |
尝试添加自动激活的单一实例服务。 |
- Source:
- AutoActivationExtensions.cs
尝试添加自动激活的单一实例服务。
public:
[System::Runtime::CompilerServices::Extension]
static void TryAddActivatedSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, Type ^ serviceType);
public static void TryAddActivatedSingleton (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Type serviceType);
static member TryAddActivatedSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Type -> unit
<Extension()>
Public Sub TryAddActivatedSingleton (services As IServiceCollection, serviceType As Type)
参数
- services
- IServiceCollection
要向其添加服务的服务集合。
- serviceType
- Type
要注册的服务类型。
适用于
.NET 9 (package-provided) 和其他版本
产品 | 版本 |
---|---|
.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) |
- Source:
- AutoActivationExtensions.cs
尝试添加自动激活的单一实例服务。
public:
[System::Runtime::CompilerServices::Extension]
static void TryAddActivatedSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, Type ^ serviceType, Func<IServiceProvider ^, System::Object ^> ^ implementationFactory);
public static void TryAddActivatedSingleton (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Type serviceType, Func<IServiceProvider,object> implementationFactory);
static member TryAddActivatedSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Type * Func<IServiceProvider, obj> -> unit
<Extension()>
Public Sub TryAddActivatedSingleton (services As IServiceCollection, serviceType As Type, implementationFactory As Func(Of IServiceProvider, Object))
参数
- services
- IServiceCollection
要向其添加服务的服务集合。
- serviceType
- Type
要注册的服务类型。
- implementationFactory
- Func<IServiceProvider,Object>
用于创建服务的工厂。
适用于
.NET 9 (package-provided) 和其他版本
产品 | 版本 |
---|---|
.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) |
- Source:
- AutoActivationExtensions.cs
尝试添加自动激活的单一实例服务。
public:
[System::Runtime::CompilerServices::Extension]
static void TryAddActivatedSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, Type ^ serviceType, Type ^ implementationType);
public static void TryAddActivatedSingleton (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Type serviceType, Type implementationType);
static member TryAddActivatedSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Type * Type -> unit
<Extension()>
Public Sub TryAddActivatedSingleton (services As IServiceCollection, serviceType As Type, implementationType As Type)
参数
- services
- IServiceCollection
要向其添加服务的服务集合。
- serviceType
- Type
要注册的服务类型。
- implementationType
- Type
服务的实现类型。
适用于
.NET 9 (package-provided) 和其他版本
产品 | 版本 |
---|---|
.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) |
- Source:
- AutoActivationExtensions.cs
尝试添加自动激活的单一实例服务。
public:
generic <typename TService, typename TImplementation>
where TService : class where TImplementation : class, TService[System::Runtime::CompilerServices::Extension]
static void TryAddActivatedSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services);
public static void TryAddActivatedSingleton<TService,TImplementation> (this Microsoft.Extensions.DependencyInjection.IServiceCollection services) where TService : class where TImplementation : class, TService;
static member TryAddActivatedSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection -> unit (requires 'Service : null)
<Extension()>
Public Sub TryAddActivatedSingleton(Of TService As Class, TImplementation As Class) (services As IServiceCollection)
类型参数
- TService
要添加的服务类型。
- TImplementation
要使用的实现的类型。
参数
- services
- IServiceCollection
要向其添加服务的服务集合。
适用于
.NET 9 (package-provided) 和其他版本
产品 | 版本 |
---|---|
.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) |
- Source:
- AutoActivationExtensions.cs
尝试添加自动激活的单一实例服务。
public:
generic <typename TService>
where TService : class[System::Runtime::CompilerServices::Extension]
static void TryAddActivatedSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, Func<IServiceProvider ^, TService> ^ implementationFactory);
public static void TryAddActivatedSingleton<TService> (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Func<IServiceProvider,TService> implementationFactory) where TService : class;
static member TryAddActivatedSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Func<IServiceProvider, 'Service (requires 'Service : null)> -> unit (requires 'Service : null)
<Extension()>
Public Sub TryAddActivatedSingleton(Of TService As Class) (services As IServiceCollection, implementationFactory As Func(Of IServiceProvider, TService))
类型参数
- TService
要添加的服务类型。
参数
- services
- IServiceCollection
要向其添加服务的服务集合。
- implementationFactory
- Func<IServiceProvider,TService>
用于创建服务的工厂。
适用于
.NET 9 (package-provided) 和其他版本
产品 | 版本 |
---|---|
.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) |
- Source:
- AutoActivationExtensions.cs
尝试添加自动激活的单一实例服务。
public:
generic <typename TService>
where TService : class[System::Runtime::CompilerServices::Extension]
static void TryAddActivatedSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services);
public static void TryAddActivatedSingleton<TService> (this Microsoft.Extensions.DependencyInjection.IServiceCollection services) where TService : class;
static member TryAddActivatedSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection -> unit (requires 'Service : null)
<Extension()>
Public Sub TryAddActivatedSingleton(Of TService As Class) (services As IServiceCollection)
类型参数
- TService
要添加的服务类型。
参数
- services
- IServiceCollection
要向其添加服务的服务集合。
适用于
.NET 9 (package-provided) 和其他版本
产品 | 版本 |
---|---|
.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) |