ServiceDescriptor.Singleton Method

Definition

Overloads

Singleton(Type, Func<IServiceProvider,Object>)

Creates an instance of ServiceDescriptor with the specified serviceType, implementationFactory, and the Singleton lifetime.

Singleton(Type, Object)

Creates an instance of ServiceDescriptor with the specified serviceType, implementationInstance, and the Singleton lifetime.

Singleton(Type, Type)

Creates an instance of ServiceDescriptor with the specified service and implementationType and the Singleton lifetime.

Singleton<TService,TImplementation>()

Creates an instance of ServiceDescriptor with the specified TService, TImplementation, and the Singleton lifetime.

Singleton<TService,TImplementation>(Func<IServiceProvider,TImplementation>)

Creates an instance of ServiceDescriptor with the specified TService, TImplementation, implementationFactory, and the Singleton lifetime.

Singleton<TService>(Func<IServiceProvider,TService>)

Creates an instance of ServiceDescriptor with the specified TService, implementationFactory, and the Singleton lifetime.

Singleton<TService>(TService)

Creates an instance of ServiceDescriptor with the specified TService, implementationInstance, and the Singleton lifetime.

Singleton(Type, Func<IServiceProvider,Object>)

Source:
ServiceDescriptor.cs
Source:
ServiceDescriptor.cs
Source:
ServiceDescriptor.cs

Creates an instance of ServiceDescriptor with the specified serviceType, implementationFactory, and the Singleton lifetime.

public static Microsoft.Extensions.DependencyInjection.ServiceDescriptor Singleton (Type serviceType, Func<IServiceProvider,object> implementationFactory);

Parameters

serviceType
Type

The type of the service.

implementationFactory
Func<IServiceProvider,Object>

A factory to create new instances of the service implementation.

Returns

A new instance of ServiceDescriptor.

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)

Singleton(Type, Object)

Source:
ServiceDescriptor.cs
Source:
ServiceDescriptor.cs
Source:
ServiceDescriptor.cs

Creates an instance of ServiceDescriptor with the specified serviceType, implementationInstance, and the Singleton lifetime.

public static Microsoft.Extensions.DependencyInjection.ServiceDescriptor Singleton (Type serviceType, object implementationInstance);

Parameters

serviceType
Type

The type of the service.

implementationInstance
Object

The instance of the implementation.

Returns

A new instance of ServiceDescriptor.

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)

Singleton(Type, Type)

Source:
ServiceDescriptor.cs
Source:
ServiceDescriptor.cs
Source:
ServiceDescriptor.cs

Creates an instance of ServiceDescriptor with the specified service and implementationType and the Singleton lifetime.

public static Microsoft.Extensions.DependencyInjection.ServiceDescriptor Singleton (Type service, Type implementationType);

Parameters

service
Type

The type of the service.

implementationType
Type

The type of the implementation.

Returns

A new instance of ServiceDescriptor.

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)

Singleton<TService,TImplementation>()

Source:
ServiceDescriptor.cs
Source:
ServiceDescriptor.cs
Source:
ServiceDescriptor.cs

Creates an instance of ServiceDescriptor with the specified TService, TImplementation, and the Singleton lifetime.

public static Microsoft.Extensions.DependencyInjection.ServiceDescriptor Singleton<TService,TImplementation> () where TService : class where TImplementation : class, TService;

Type Parameters

TService

The type of the service.

TImplementation

The type of the implementation.

Returns

A new instance of ServiceDescriptor.

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)

Singleton<TService,TImplementation>(Func<IServiceProvider,TImplementation>)

Source:
ServiceDescriptor.cs
Source:
ServiceDescriptor.cs
Source:
ServiceDescriptor.cs

Creates an instance of ServiceDescriptor with the specified TService, TImplementation, implementationFactory, and the Singleton lifetime.

public static Microsoft.Extensions.DependencyInjection.ServiceDescriptor Singleton<TService,TImplementation> (Func<IServiceProvider,TImplementation> implementationFactory) where TService : class where TImplementation : class, TService;

Type Parameters

TService

The type of the service.

TImplementation

The type of the implementation.

Parameters

implementationFactory
Func<IServiceProvider,TImplementation>

A factory to create new instances of the service implementation.

Returns

A new instance of ServiceDescriptor.

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)

Singleton<TService>(Func<IServiceProvider,TService>)

Source:
ServiceDescriptor.cs
Source:
ServiceDescriptor.cs
Source:
ServiceDescriptor.cs

Creates an instance of ServiceDescriptor with the specified TService, implementationFactory, and the Singleton lifetime.

public static Microsoft.Extensions.DependencyInjection.ServiceDescriptor Singleton<TService> (Func<IServiceProvider,TService> implementationFactory) where TService : class;

Type Parameters

TService

The type of the service.

Parameters

implementationFactory
Func<IServiceProvider,TService>

A factory to create new instances of the service implementation.

Returns

A new instance of ServiceDescriptor.

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)

Singleton<TService>(TService)

Source:
ServiceDescriptor.cs
Source:
ServiceDescriptor.cs
Source:
ServiceDescriptor.cs

Creates an instance of ServiceDescriptor with the specified TService, implementationInstance, and the Singleton lifetime.

public static Microsoft.Extensions.DependencyInjection.ServiceDescriptor Singleton<TService> (TService implementationInstance) where TService : class;

Type Parameters

TService

The type of the service.

Parameters

implementationInstance
TService

The instance of the implementation.

Returns

A new instance of ServiceDescriptor.

Applies to

.NET 9 (package-provided) e altre versioni
Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)