ServiceCollectionDescriptorExtensions.TryAddEnumerable 方法

定義

多載

TryAddEnumerable(IServiceCollection, ServiceDescriptor)

如果現有描述項具有相同的 ServiceType,以及尚未存在於 services 中的實作,則新增 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>)

如果現有描述項具有相同的 ServiceType,以及尚未存在於 services 中的實作,則新增特定的 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)

如果現有描述項具有相同的 ServiceType,以及尚未存在於 services 中的實作,則新增 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.

適用於

TryAddEnumerable(IServiceCollection, IEnumerable<ServiceDescriptor>)

如果現有描述項具有相同的 ServiceType,以及尚未存在於 services 中的實作,則新增特定的 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.

適用於