ServiceCollectionDescriptorExtensions.TryAddKeyedSingleton Method

Definition

Overloads

TryAddKeyedSingleton(IServiceCollection, Type, Object)

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

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

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

TryAddKeyedSingleton(IServiceCollection, Type, Object, Type)

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

TryAddKeyedSingleton<TService,TImplementation>(IServiceCollection, Object)

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

TryAddKeyedSingleton<TService>(IServiceCollection, Object)

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

TryAddKeyedSingleton<TService>(IServiceCollection, Object, Func<IServiceProvider,Object,TService>)

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

TryAddKeyedSingleton<TService>(IServiceCollection, Object, TService)

Adds the specified TService as a Singleton service with an instance specified in instance to the collection if the service type hasn't already been registered.

TryAddKeyedSingleton(IServiceCollection, Type, Object)

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

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

C#
public static void TryAddKeyedSingleton(this Microsoft.Extensions.DependencyInjection.IServiceCollection collection, Type service, object? serviceKey);

Parameters

service
Type

The type of the service to register.

serviceKey
Object

The service key.

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)

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

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

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

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

Parameters

service
Type

The type of the service to register.

serviceKey
Object

The service key.

implementationFactory
Func<IServiceProvider,Object,Object>

The factory that creates the service.

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)

TryAddKeyedSingleton(IServiceCollection, Type, Object, Type)

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

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

C#
public static void TryAddKeyedSingleton(this Microsoft.Extensions.DependencyInjection.IServiceCollection collection, Type service, object? serviceKey, Type implementationType);

Parameters

service
Type

The type of the service to register.

serviceKey
Object

The service key.

implementationType
Type

The implementation type of the service.

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)

TryAddKeyedSingleton<TService,TImplementation>(IServiceCollection, Object)

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

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

C#
public static void TryAddKeyedSingleton<TService,TImplementation>(this Microsoft.Extensions.DependencyInjection.IServiceCollection collection, object? serviceKey) 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

serviceKey
Object

The service key.

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)

TryAddKeyedSingleton<TService>(IServiceCollection, Object)

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

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

C#
public static void TryAddKeyedSingleton<TService>(this Microsoft.Extensions.DependencyInjection.IServiceCollection collection, object? serviceKey) where TService : class;

Type Parameters

TService

The type of the service to add.

Parameters

serviceKey
Object

The service key.

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)

TryAddKeyedSingleton<TService>(IServiceCollection, Object, Func<IServiceProvider,Object,TService>)

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

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

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

Type Parameters

TService

The type of the service to add.

Parameters

serviceKey
Object

The service key.

implementationFactory
Func<IServiceProvider,Object,TService>

The factory that creates the service.

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)

TryAddKeyedSingleton<TService>(IServiceCollection, Object, TService)

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

Adds the specified TService as a Singleton service with an instance specified in instance to the collection if the service type hasn't already been registered.

C#
public static void TryAddKeyedSingleton<TService>(this Microsoft.Extensions.DependencyInjection.IServiceCollection collection, object? serviceKey, TService instance) where TService : class;

Type Parameters

TService

The type of the service to add.

Parameters

serviceKey
Object

The service key.

instance
TService

The instance of the service to add.

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)