NamedServiceCollectionExtensions.AddNamedSingleton Method

Definition

Overloads

AddNamedSingleton<TService,TImplementation>(IServiceCollection, String)

Adds a singleton named service of the type specific in TService to the specified IServiceCollection.

AddNamedSingleton<TService>(IServiceCollection, String)

Adds a singleton named service of the type specific in TService to the specified IServiceCollection.

AddNamedSingleton<TService>(IServiceCollection, String, Func<IServiceProvider,TService>)

Adds a singleton named service of the type specific in TService to the specified IServiceCollection.

AddNamedSingleton<TService,TImplementation>(IServiceCollection, String)

Adds a singleton named service of the type specific in TService to the specified IServiceCollection.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddNamedSingleton<TService,TImplementation>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, string name) where TService : class where TImplementation : TService;

Type Parameters

TService

The type of the service to add.

TImplementation

The type of the implementation to use.

Parameters

serviceCollection
IServiceCollection

The IServiceCollection to add the service to.

name
String

The name of the service.

Returns

A reference to this instance after the operation has completed.

Applies to

.NET 10 (package-provided) dan versi lain
Produk Versi
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)

AddNamedSingleton<TService>(IServiceCollection, String)

Adds a singleton named service of the type specific in TService to the specified IServiceCollection.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddNamedSingleton<TService>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, string name) where TService : class;

Type Parameters

TService

The type of the service to add.

Parameters

serviceCollection
IServiceCollection

The IServiceCollection to add the service to.

name
String

The name of the service.

Returns

A reference to this instance after the operation has completed.

Applies to

.NET 10 (package-provided) dan versi lain
Produk Versi
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)

AddNamedSingleton<TService>(IServiceCollection, String, Func<IServiceProvider,TService>)

Adds a singleton named service of the type specific in TService to the specified IServiceCollection.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddNamedSingleton<TService>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, string name, Func<IServiceProvider,TService> implementationFactory) where TService : class;

Type Parameters

TService

The type of the service to add.

Parameters

serviceCollection
IServiceCollection

The IServiceCollection to add the service to.

name
String

The name of the service.

implementationFactory
Func<IServiceProvider,TService>

The factory that creates the service.

Returns

A reference to this instance after the operation has completed.

Applies to

.NET 10 (package-provided) dan versi lain
Produk Versi
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)