ServiceCollectionServiceExtensions.AddSingleton Method

Definition

Overloads

AddSingleton(IServiceCollection, Type, Object)

Adds a singleton service of the type specified in serviceType with an instance specified in implementationInstance to the specified IServiceCollection.

AddSingleton(IServiceCollection, Type, Type)

Adds a singleton service of the type specified in serviceType with an implementation of the type specified in implementationType to the specified IServiceCollection.

AddSingleton(IServiceCollection, Type)

Adds a singleton service of the type specified in serviceType to the specified IServiceCollection.

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

Adds a singleton service of the type specified in serviceType with a factory specified in implementationFactory to the specified IServiceCollection.

AddSingleton<TService,TImplementation>(IServiceCollection)

Adds a singleton service of the type specified in TService with an implementation type specified in TImplementation to the specified IServiceCollection.

AddSingleton<TService,TImplementation>(IServiceCollection, Func<IServiceProvider,TImplementation>)

Adds a singleton service of the type specified in TService with an implementation type specified in TImplementation using the factory specified in implementationFactory to the specified IServiceCollection.

AddSingleton<TService>(IServiceCollection)

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

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

Adds a singleton service of the type specified in TService with a factory specified in implementationFactory to the specified IServiceCollection.

AddSingleton<TService>(IServiceCollection, TService)

Adds a singleton service of the type specified in TService with an instance specified in implementationInstance to the specified IServiceCollection.

AddSingleton(IServiceCollection, Type, Object)

Source:
ServiceCollectionServiceExtensions.cs
Source:
ServiceCollectionServiceExtensions.cs
Source:
ServiceCollectionServiceExtensions.cs

Adds a singleton service of the type specified in serviceType with an instance specified in implementationInstance to the specified IServiceCollection.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddSingleton(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Type serviceType, object implementationInstance);

Parameters

services
IServiceCollection

The IServiceCollection to add the service to.

serviceType
Type

The type of the service to register.

implementationInstance
Object

The instance of the service.

Returns

A reference to this instance after the operation has completed.

See also

Applies to

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

AddSingleton(IServiceCollection, Type, Type)

Source:
ServiceCollectionServiceExtensions.cs
Source:
ServiceCollectionServiceExtensions.cs
Source:
ServiceCollectionServiceExtensions.cs

Adds a singleton service of the type specified in serviceType with an implementation of the type specified in implementationType to the specified IServiceCollection.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddSingleton(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Type serviceType, Type implementationType);

Parameters

services
IServiceCollection

The IServiceCollection to add the service to.

serviceType
Type

The type of the service to register.

implementationType
Type

The implementation type of the service.

Returns

A reference to this instance after the operation has completed.

See also

Applies to

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

AddSingleton(IServiceCollection, Type)

Source:
ServiceCollectionServiceExtensions.cs
Source:
ServiceCollectionServiceExtensions.cs
Source:
ServiceCollectionServiceExtensions.cs

Adds a singleton service of the type specified in serviceType to the specified IServiceCollection.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddSingleton(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Type serviceType);

Parameters

services
IServiceCollection

The IServiceCollection to add the service to.

serviceType
Type

The type of the service to register and the implementation to use.

Returns

A reference to this instance after the operation has completed.

See also

Applies to

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

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

Source:
ServiceCollectionServiceExtensions.cs
Source:
ServiceCollectionServiceExtensions.cs
Source:
ServiceCollectionServiceExtensions.cs

Adds a singleton service of the type specified in serviceType with a factory specified in implementationFactory to the specified IServiceCollection.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddSingleton(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Type serviceType, Func<IServiceProvider,object> implementationFactory);

Parameters

services
IServiceCollection

The IServiceCollection to add the service to.

serviceType
Type

The type of the service to register.

implementationFactory
Func<IServiceProvider,Object>

The factory that creates the service.

Returns

A reference to this instance after the operation has completed.

See also

Applies to

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

AddSingleton<TService,TImplementation>(IServiceCollection)

Source:
ServiceCollectionServiceExtensions.cs
Source:
ServiceCollectionServiceExtensions.cs
Source:
ServiceCollectionServiceExtensions.cs

Adds a singleton service of the type specified in TService with an implementation type specified in TImplementation to the specified IServiceCollection.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddSingleton<TService,TImplementation>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) 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

services
IServiceCollection

The IServiceCollection to add the service to.

Returns

A reference to this instance after the operation has completed.

See also

Applies to

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

AddSingleton<TService,TImplementation>(IServiceCollection, Func<IServiceProvider,TImplementation>)

Source:
ServiceCollectionServiceExtensions.cs
Source:
ServiceCollectionServiceExtensions.cs
Source:
ServiceCollectionServiceExtensions.cs

Adds a singleton service of the type specified in TService with an implementation type specified in TImplementation using the factory specified in implementationFactory to the specified IServiceCollection.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddSingleton<TService,TImplementation>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Func<IServiceProvider,TImplementation> implementationFactory) 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

services
IServiceCollection

The IServiceCollection to add the service to.

implementationFactory
Func<IServiceProvider,TImplementation>

The factory that creates the service.

Returns

A reference to this instance after the operation has completed.

See also

Applies to

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

AddSingleton<TService>(IServiceCollection)

Source:
ServiceCollectionServiceExtensions.cs
Source:
ServiceCollectionServiceExtensions.cs
Source:
ServiceCollectionServiceExtensions.cs

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

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddSingleton<TService>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) where TService : class;

Type Parameters

TService

The type of the service to add.

Parameters

services
IServiceCollection

The IServiceCollection to add the service to.

Returns

A reference to this instance after the operation has completed.

See also

Applies to

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

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

Source:
ServiceCollectionServiceExtensions.cs
Source:
ServiceCollectionServiceExtensions.cs
Source:
ServiceCollectionServiceExtensions.cs

Adds a singleton service of the type specified in TService with a factory specified in implementationFactory to the specified IServiceCollection.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddSingleton<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

services
IServiceCollection

The IServiceCollection to add the service to.

implementationFactory
Func<IServiceProvider,TService>

The factory that creates the service.

Returns

A reference to this instance after the operation has completed.

See also

Applies to

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

AddSingleton<TService>(IServiceCollection, TService)

Source:
ServiceCollectionServiceExtensions.cs
Source:
ServiceCollectionServiceExtensions.cs
Source:
ServiceCollectionServiceExtensions.cs

Adds a singleton service of the type specified in TService with an instance specified in implementationInstance to the specified IServiceCollection.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddSingleton<TService>(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, TService implementationInstance) where TService : class;

Type Parameters

TService

Parameters

services
IServiceCollection

The IServiceCollection to add the service to.

implementationInstance
TService

The instance of the service.

Returns

A reference to this instance after the operation has completed.

See also

Applies to

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