ServiceCollectionDescriptorExtensions.TryAddTransient 方法

定义

重载

TryAddTransient(IServiceCollection, Type)

如果服务类型尚未注册,则将指定的 service 作为 Transient 服务添加到 collection 中。Adds the specified service as a Transient service to the collection if the service type hasn't already been registered.

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

如果服务类型尚未注册,则使用 implementationFactory 中指定的中心将指定的 service 作为 Transient 服务添加到 collection 中。Adds the specified service as a Transient service using the factory specified in implementationFactory to the collection if the service type hasn't already been registered.

TryAddTransient(IServiceCollection, Type, Type)

如果服务类型尚未注册,则使用 implementationType 实现将指定的 service 作为 Transient 服务添加到 collection 中。Adds the specified service as a Transient service with the implementationType implementation to the collection if the service type hasn't already been registered.

TryAddTransient<TService,TImplementation>(IServiceCollection)

如果服务类型尚未注册,则将指定的 TService 作为 TImplementation 中指定的 Transient 服务实现类型添加到 collection 中。Adds the specified TService as a Transient service implementation type specified in TImplementation to the collection if the service type hasn't already been registered.

TryAddTransient<TService>(IServiceCollection)

如果服务类型尚未注册,则将指定的 TService 作为 Transient 服务添加到 collection 中。Adds the specified TService as a Transient service to the collection if the service type hasn't already been registered.

TryAddTransient<TService>(IServiceCollection, Func<IServiceProvider,TService>)

如果服务类型尚未注册,则使用 implementationFactory 中指定的中心将指定的 TService 作为 Transient 服务添加到 services 中。Adds the specified TService as a Transient service using the factory specified in implementationFactory to the services if the service type hasn't already been registered.

TryAddTransient(IServiceCollection, Type)

如果服务类型尚未注册,则将指定的 service 作为 Transient 服务添加到 collection 中。Adds the specified service as a Transient service to the collection if the service type hasn't already been registered.

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

参数

service
Type

要注册的服务类型。The type of the service to register.

适用于

产品 Introduced

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

如果服务类型尚未注册,则使用 implementationFactory 中指定的中心将指定的 service 作为 Transient 服务添加到 collection 中。Adds the specified service as a Transient service using the factory specified in implementationFactory to the collection if the service type hasn't already been registered.

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

参数

service
Type

要注册的服务类型。The type of the service to register.

implementationFactory
Func<IServiceProvider,Object>

用于创建服务的工厂。The factory that creates the service.

适用于

产品 Introduced

TryAddTransient(IServiceCollection, Type, Type)

如果服务类型尚未注册,则使用 implementationType 实现将指定的 service 作为 Transient 服务添加到 collection 中。Adds the specified service as a Transient service with the implementationType implementation to the collection if the service type hasn't already been registered.

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

参数

service
Type

要注册的服务类型。The type of the service to register.

implementationType
Type

服务的实现类型。The implementation type of the service.

适用于

产品 Introduced

TryAddTransient<TService,TImplementation>(IServiceCollection)

如果服务类型尚未注册,则将指定的 TService 作为 TImplementation 中指定的 Transient 服务实现类型添加到 collection 中。Adds the specified TService as a Transient service implementation type specified in TImplementation to the collection if the service type hasn't already been registered.

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

类型参数

TService

要添加的服务类型。The type of the service to add.

TImplementation

要使用的实现的类型。The type of the implementation to use.

参数

适用于

产品 Introduced

TryAddTransient<TService>(IServiceCollection)

如果服务类型尚未注册,则将指定的 TService 作为 Transient 服务添加到 collection 中。Adds the specified TService as a Transient service to the collection if the service type hasn't already been registered.

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

类型参数

TService

要添加的服务类型。The type of the service to add.

参数

适用于

产品 Introduced

TryAddTransient<TService>(IServiceCollection, Func<IServiceProvider,TService>)

如果服务类型尚未注册,则使用 implementationFactory 中指定的中心将指定的 TService 作为 Transient 服务添加到 services 中。Adds the specified TService as a Transient service using the factory specified in implementationFactory to the services if the service type hasn't already been registered.

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

类型参数

TService

要添加的服务类型。The type of the service to add.

参数

implementationFactory
Func<IServiceProvider,TService>

用于创建服务的工厂。The factory that creates the service.

适用于

产品 Introduced