Development · Native API migration preview · Coverage validation in progress Published release →

API Browser

Member group

TryAddKeyedSingleton

Declaring type: ServiceCollectionExtensions
Module: Neo.DependencyInjection
Assembly: Neo.DependencyInjection.Abstractions.dll

Overloads / Variants

TryAddKeyedSingleton

func TryAddKeyedSingleton<TService, TImplementation>(key: object?) -> Result<bool, ServiceError>

Extension from ServiceCollectionExtensions.TryAddKeyedSingleton

Adds only when the service type/key is absent. Registers a keyed singleton implementation of TService.

Parameters

Name Type Description
self ServiceCollection
key Object?

Return value

Result<Boolean, ServiceError>

TryAddKeyedSingleton

func TryAddKeyedSingleton<TService>(key: object?, factory: (ServiceProvider, object?) -> Result<TService, ServiceError>) -> Result<bool, ServiceError>

Extension from ServiceCollectionExtensions.TryAddKeyedSingleton

Adds only when the service type/key is absent. Registers a keyed typed factory; its returned service becomes provider-owned.

Parameters

Name Type Description
self ServiceCollection
key Object?
factory Function

Return value

Result<Boolean, ServiceError>

TryAddKeyedSingleton

func TryAddKeyedSingleton<TService>(key: object?, instance: TService) -> Result<bool, ServiceError>

Extension from ServiceCollectionExtensions.TryAddKeyedSingleton

Adds only when the service type/key is absent. Registers a caller-owned keyed value, including a bound function object.

Parameters

Name Type Description
self ServiceCollection
key Object?
instance TService

Return value

Result<Boolean, ServiceError>

TryAddKeyedSingleton

func TryAddKeyedSingleton<TService>(key: object?) -> Result<bool, ServiceError>

Extension from ServiceCollectionExtensions.TryAddKeyedSingleton

Adds only when the service type/key is absent. Registers TService as its own keyed singleton implementation.

Parameters

Name Type Description
self ServiceCollection
key Object?

Return value

Result<Boolean, ServiceError>