ServiceCollectionDescriptorExtensions.TryAddScoped Method

Definition

Overloads

TryAddScoped(IServiceCollection, Type)

Adds the specified service as a Scoped service to the collection if the service type hasn't already been registered.

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

Adds the specified service as a Scoped service using the factory specified in implementationFactory to the collection if the service type hasn't already been registered.

TryAddScoped(IServiceCollection, Type, Type)

Adds the specified service as a Scoped service with the implementationType implementation to the collection if the service type hasn't already been registered.

TryAddScoped<TService,TImplementation>(IServiceCollection)

Adds the specified TService as a Scoped service implementation type specified in TImplementation to the collection if the service type hasn't already been registered.

TryAddScoped<TService>(IServiceCollection)

Adds the specified TService as a Scoped service to the collection if the service type hasn't already been registered.

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

Adds the specified TService as a Scoped service using the factory specified in implementationFactory to the services if the service type hasn't already been registered.

TryAddScoped(IServiceCollection, Type)

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

Adds the specified service as a Scoped service to the collection if the service type hasn't already been registered.

C#
public static void TryAddScoped(this Microsoft.Extensions.DependencyInjection.IServiceCollection collection, Type service);

Parameters

service
Type

The type of the service to register.

Applies to

.NET 10 (package-provided) und andere Versionen
Produkt Versionen
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)

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

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

Adds the specified service as a Scoped service using the factory specified in implementationFactory to the collection if the service type hasn't already been registered.

C#
public static void TryAddScoped(this Microsoft.Extensions.DependencyInjection.IServiceCollection collection, Type service, Func<IServiceProvider,object> implementationFactory);

Parameters

service
Type

The type of the service to register.

implementationFactory
Func<IServiceProvider,Object>

The factory that creates the service.

Applies to

.NET 10 (package-provided) und andere Versionen
Produkt Versionen
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)

TryAddScoped(IServiceCollection, Type, Type)

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

Adds the specified service as a Scoped service with the implementationType implementation to the collection if the service type hasn't already been registered.

C#
public static void TryAddScoped(this Microsoft.Extensions.DependencyInjection.IServiceCollection collection, Type service, Type implementationType);

Parameters

service
Type

The type of the service to register.

implementationType
Type

The implementation type of the service.

Applies to

.NET 10 (package-provided) und andere Versionen
Produkt Versionen
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)

TryAddScoped<TService,TImplementation>(IServiceCollection)

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

Adds the specified TService as a Scoped service implementation type specified in TImplementation to the collection if the service type hasn't already been registered.

C#
public static void TryAddScoped<TService,TImplementation>(this Microsoft.Extensions.DependencyInjection.IServiceCollection collection) where TService : class where TImplementation : class, TService;

Type Parameters

TService

The type of the service to add.

TImplementation

The type of the implementation to use.

Parameters

Applies to

.NET 10 (package-provided) und andere Versionen
Produkt Versionen
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)

TryAddScoped<TService>(IServiceCollection)

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

Adds the specified TService as a Scoped service to the collection if the service type hasn't already been registered.

C#
public static void TryAddScoped<TService>(this Microsoft.Extensions.DependencyInjection.IServiceCollection collection) where TService : class;

Type Parameters

TService

The type of the service to add.

Parameters

Applies to

.NET 10 (package-provided) und andere Versionen
Produkt Versionen
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)

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

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

Adds the specified TService as a Scoped service using the factory specified in implementationFactory to the services if the service type hasn't already been registered.

C#
public static void TryAddScoped<TService>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Func<IServiceProvider,TService> implementationFactory) where TService : class;

Type Parameters

TService

The type of the service to add.

Parameters

implementationFactory
Func<IServiceProvider,TService>

The factory that creates the service.

Applies to

.NET 10 (package-provided) und andere Versionen
Produkt Versionen
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)