Skip to content

ServiceCollectionExtensions Methods

Extension methods for configuring dependency injection.

AddFromExisting(IServiceCollection, Type, Type)

staticextension
View source
public static void AddFromExisting(this IServiceCollection services, Type service, Type implementation)
Registers an existing registration of implementation as a provider of service type service.

Parameters

servicesIServiceCollection
The service collection.
serviceType
The service type being provided.
implementationType
The implementation of service.

AddFromExisting(IServiceCollection)

staticextension
View source
public static void AddFromExisting<TService, TImplementation>(this IServiceCollection services)
Registers an existing registration of TImplementation as a provider of service type TService.

Parameters

servicesIServiceCollection
The service collection.

TryAddFromExisting(IServiceCollection)

staticextension
View source
public static void TryAddFromExisting<TService, TImplementation>(this IServiceCollection services)
Registers an existing registration of TImplementation as a provider of TService if there are no existing TService implementations.

Parameters

servicesIServiceCollection
The service collection.