Class KeyedServiceRegistrationExtensions
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
-
objectKeyedServiceRegistrationExtensions
Remarks
Added in v22, should still be considered work in progress.
Methods
AddKeyedScopedWithMarker<TService, TImplementation>(IServiceCollection, string)
⚠️ Do not use it, or anything with
Sys or Internal namespaces in your code, as future changes could break your code.
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
servicesIServiceCollectionkeystring
Returns
Type Parameters
TServiceTImplementation
AddKeyedSingletonWithMarker<TService, TImplementation>(IServiceCollection, string)
⚠️ Do not use it, or anything with
Sys or Internal namespaces in your code, as future changes could break your code.
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
servicesIServiceCollectionkeystring
Returns
Type Parameters
TServiceTImplementation
AddKeyedTransientWithMarker<TService, TImplementation>(IServiceCollection, string)
⚠️ Do not use it, or anything with
Sys or Internal namespaces in your code, as future changes could break your code.
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
servicesIServiceCollectionkeystring
Returns
Type Parameters
TServiceTImplementation
TryAddKeyedScopedWithMarker<TService, TImplementation>(IServiceCollection, string)
⚠️ Do not use it, or anything with
Sys or Internal namespaces in your code, as future changes could break your code.
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
servicesIServiceCollectionkeystring
Returns
Type Parameters
TServiceTImplementation
TryAddKeyedSingletonWithMarker<TService, TImplementation>(IServiceCollection, string)
⚠️ Do not use it, or anything with
Sys or Internal namespaces in your code, as future changes could break your code.
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
servicesIServiceCollectionkeystring
Returns
Type Parameters
TServiceTImplementation
TryAddKeyedTransientWithMarker<TService, TImplementation>(IServiceCollection, string)
⚠️ Do not use it, or anything with
Sys or Internal namespaces in your code, as future changes could break your code.
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
servicesIServiceCollectionkeystring
Returns
Type Parameters
TServiceTImplementation