ServiceCollectionDescriptorExtensions.TryAddEnumerable 方法

定义

重载

TryAddEnumerable(IServiceCollection, ServiceDescriptor)

如果现有描述符具有相同 ServiceTypeservices 中尚不存在的实现,则添加 ServiceDescriptorAdds a ServiceDescriptor if an existing descriptor with the same ServiceType and an implementation that does not already exist in services.

TryAddEnumerable(IServiceCollection, IEnumerable<ServiceDescriptor>)

如果现有描述符具有相同 ServiceTypeservices 中尚不存在的实现,则添加指定的 ServiceDescriptorAdds the specified ServiceDescriptors if an existing descriptor with the same ServiceType and an implementation that does not already exist in services.

TryAddEnumerable(IServiceCollection, ServiceDescriptor)

如果现有描述符具有相同 ServiceTypeservices 中尚不存在的实现,则添加 ServiceDescriptorAdds a ServiceDescriptor if an existing descriptor with the same ServiceType and an implementation that does not already exist in services.

public:
[System::Runtime::CompilerServices::Extension]
 static void TryAddEnumerable(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, Microsoft::Extensions::DependencyInjection::ServiceDescriptor ^ descriptor);
public static void TryAddEnumerable (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Microsoft.Extensions.DependencyInjection.ServiceDescriptor descriptor);
static member TryAddEnumerable : Microsoft.Extensions.DependencyInjection.IServiceCollection * Microsoft.Extensions.DependencyInjection.ServiceDescriptor -> unit
<Extension()>
Public Sub TryAddEnumerable (services As IServiceCollection, descriptor As ServiceDescriptor)

参数

注解

TryAddEnumerable(IServiceCollection, ServiceDescriptor)注册支持同一服务类型的多个注册的服务类型的服务实现时使用。Use TryAddEnumerable(IServiceCollection, ServiceDescriptor) when registering a service implementation of a service type that supports multiple registrations of the same service type. 使用不 Add(IServiceCollection, ServiceDescriptor) 是幂等的,如果调用了两次,则可以添加重复的 ServiceDescriptor 实例。Using Add(IServiceCollection, ServiceDescriptor) is not idempotent and can add duplicate ServiceDescriptor instances if called twice. 使用 TryAddEnumerable(IServiceCollection, ServiceDescriptor) 将阻止注册多个实现类型。Using TryAddEnumerable(IServiceCollection, ServiceDescriptor) will prevent registration of multiple implementation types.

适用于

产品 Introduced

TryAddEnumerable(IServiceCollection, IEnumerable<ServiceDescriptor>)

如果现有描述符具有相同 ServiceTypeservices 中尚不存在的实现,则添加指定的 ServiceDescriptorAdds the specified ServiceDescriptors if an existing descriptor with the same ServiceType and an implementation that does not already exist in services.

public:
[System::Runtime::CompilerServices::Extension]
 static void TryAddEnumerable(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, System::Collections::Generic::IEnumerable<Microsoft::Extensions::DependencyInjection::ServiceDescriptor ^> ^ descriptors);
public static void TryAddEnumerable (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Collections.Generic.IEnumerable<Microsoft.Extensions.DependencyInjection.ServiceDescriptor> descriptors);
static member TryAddEnumerable : Microsoft.Extensions.DependencyInjection.IServiceCollection * seq<Microsoft.Extensions.DependencyInjection.ServiceDescriptor> -> unit
<Extension()>
Public Sub TryAddEnumerable (services As IServiceCollection, descriptors As IEnumerable(Of ServiceDescriptor))

参数

注解

TryAddEnumerable(IServiceCollection, ServiceDescriptor)注册支持同一服务类型的多个注册的服务类型的服务实现时使用。Use TryAddEnumerable(IServiceCollection, ServiceDescriptor) when registering a service implementation of a service type that supports multiple registrations of the same service type. 使用不 Add(IServiceCollection, ServiceDescriptor) 是幂等的,如果调用了两次,则可以添加重复的 ServiceDescriptor 实例。Using Add(IServiceCollection, ServiceDescriptor) is not idempotent and can add duplicate ServiceDescriptor instances if called twice. 使用 TryAddEnumerable(IServiceCollection, ServiceDescriptor) 将阻止注册多个实现类型。Using TryAddEnumerable(IServiceCollection, ServiceDescriptor) will prevent registration of multiple implementation types.

适用于

产品 Introduced