Table of Contents

Class KeyedServiceRegistrationExtensions

Namespace
ToSic.Sys.DI
Assembly
ToSic.Sys.Core.dll

Helper for better managing keyed services in dependency injection. This allows for adding a marker to the service registration, which can be used later to retrieve the key associated with the service.

[InternalApi_DoNotUse_MayChangeWithoutNotice]
public static class KeyedServiceRegistrationExtensions
Inheritance
object
KeyedServiceRegistrationExtensions

Remarks

Added in v22, should still be considered work in progress.

Methods

AddKeyedScopedWithMarker<TService, TImplementation>(IServiceCollection, string)

Add keyed scoped like classic Dependency injection, but with a marker to allow for later retrieval of the key.

[InternalApi_DoNotUse_MayChangeWithoutNotice]
public static IServiceCollection AddKeyedScopedWithMarker<TService, TImplementation>(this IServiceCollection services, string key) where TService : class where TImplementation : class, TService

Parameters

services IServiceCollection
key string

Returns

IServiceCollection

Type Parameters

TService
TImplementation

AddKeyedSingletonWithMarker<TService, TImplementation>(IServiceCollection, string)

Add keyed singleton like classic Dependency injection, but with a marker to allow for later retrieval of the key.

[InternalApi_DoNotUse_MayChangeWithoutNotice]
public static IServiceCollection AddKeyedSingletonWithMarker<TService, TImplementation>(this IServiceCollection services, string key) where TService : class where TImplementation : class, TService

Parameters

services IServiceCollection
key string

Returns

IServiceCollection

Type Parameters

TService
TImplementation

AddKeyedTransientWithMarker<TService, TImplementation>(IServiceCollection, string)

Add keyed transient like classic Dependency injection, but with a marker to allow for later retrieval of the key.

[InternalApi_DoNotUse_MayChangeWithoutNotice]
public static IServiceCollection AddKeyedTransientWithMarker<TService, TImplementation>(this IServiceCollection services, string key) where TService : class where TImplementation : class, TService

Parameters

services IServiceCollection
key string

Returns

IServiceCollection

Type Parameters

TService
TImplementation

TryAddKeyedScopedWithMarker<TService, TImplementation>(IServiceCollection, string)

Try to add keyed scoped like classic Dependency injection, but with a marker to allow for later retrieval of the key.

[InternalApi_DoNotUse_MayChangeWithoutNotice]
public static IServiceCollection TryAddKeyedScopedWithMarker<TService, TImplementation>(this IServiceCollection services, string key) where TService : class where TImplementation : class, TService

Parameters

services IServiceCollection
key string

Returns

IServiceCollection

Type Parameters

TService
TImplementation

TryAddKeyedSingletonWithMarker<TService, TImplementation>(IServiceCollection, string)

Try to add keyed singleton like classic Dependency injection, but with a marker to allow for later retrieval of the key.

[InternalApi_DoNotUse_MayChangeWithoutNotice]
public static IServiceCollection TryAddKeyedSingletonWithMarker<TService, TImplementation>(this IServiceCollection services, string key) where TService : class where TImplementation : class, TService

Parameters

services IServiceCollection
key string

Returns

IServiceCollection

Type Parameters

TService
TImplementation

TryAddKeyedTransientWithMarker<TService, TImplementation>(IServiceCollection, string)

Try to add keyed transient like classic Dependency injection, but with a marker to allow for later retrieval of the key.

[InternalApi_DoNotUse_MayChangeWithoutNotice]
public static IServiceCollection TryAddKeyedTransientWithMarker<TService, TImplementation>(this IServiceCollection services, string key) where TService : class where TImplementation : class, TService

Parameters

services IServiceCollection
key string

Returns

IServiceCollection

Type Parameters

TService
TImplementation