ServiceCollectionDescriptorExtensions.TryAdd Method

Definition

Overloads

TryAdd(IServiceCollection, ServiceDescriptor)

Adds the specified descriptor to the collection if the service type hasn't already been registered.

TryAdd(IServiceCollection, IEnumerable<ServiceDescriptor>)

Adds the specified descriptors to the collection if the service type hasn't already been registered.

TryAdd(IServiceCollection, ServiceDescriptor)

Source:
ServiceCollectionDescriptorExtensions.cs
Source:
ServiceCollectionDescriptorExtensions.cs
Source:
ServiceCollectionDescriptorExtensions.cs

Adds the specified descriptor to the collection if the service type hasn't already been registered.

C#
public static void TryAdd(this Microsoft.Extensions.DependencyInjection.IServiceCollection collection, Microsoft.Extensions.DependencyInjection.ServiceDescriptor descriptor);

Parameters

descriptor
ServiceDescriptor

The ServiceDescriptor to add.

Applies to

.NET 10 (package-provided) и други версии
Продукт Версии
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)

TryAdd(IServiceCollection, IEnumerable<ServiceDescriptor>)

Source:
ServiceCollectionDescriptorExtensions.cs
Source:
ServiceCollectionDescriptorExtensions.cs
Source:
ServiceCollectionDescriptorExtensions.cs

Adds the specified descriptors to the collection if the service type hasn't already been registered.

C#
public static void TryAdd(this Microsoft.Extensions.DependencyInjection.IServiceCollection collection, System.Collections.Generic.IEnumerable<Microsoft.Extensions.DependencyInjection.ServiceDescriptor> descriptors);

Parameters

descriptors
IEnumerable<ServiceDescriptor>

The ServiceDescriptors to add.

Applies to

.NET 10 (package-provided) и други версии
Продукт Версии
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)