ServiceCollectionDescriptorExtensions
Extension methods for adding and removing services to an IServiceCollection.
public static IServiceCollection Add(this IServiceCollection collection, ServiceDescriptor descriptor)
Adds the specified descriptor to the collection.
public static IServiceCollection Add(this IServiceCollection collection, IEnumerable<ServiceDescriptor> descriptors)
Adds a sequence of ServiceDescriptor to the collection.
Removes all services of type T in IServiceCollection.
Removes all services of type serviceType in IServiceCollection.
public static IServiceCollection Replace(this IServiceCollection collection, ServiceDescriptor descriptor)
Removes the first service in IServiceCollection with the same service type
as descriptor and adds descriptor to the collection.
Adds the specified descriptor to the collection if the
service type hasn't already been registered.
public static void TryAdd(this IServiceCollection collection, IEnumerable<ServiceDescriptor> descriptors)
Adds the specified descriptors to the collection if the
service type hasn't already been registered.
Adds a ServiceDescriptor if an existing descriptor with the same
ServiceType and an implementation that does not already exist in services.
public static void TryAddEnumerable(this IServiceCollection services, IEnumerable<ServiceDescriptor> descriptors)
Adds the specified ServiceDescriptors if an existing descriptor with the same
ServiceType and an implementation that does not already exist
in services.
Adds the specified service as a Scoped service
to the collection if the service type hasn't already been registered.
public static void TryAddScoped(this IServiceCollection collection, Type service, Type implementationType)
Adds the specified service as a Scoped service
with the implementationType implementation
to the collection if the service type hasn't already been registered.
public static void TryAddScoped(this IServiceCollection collection, Type service, Func<IServiceProvider, object> implementationFactory)
Adds the specified service as a Scoped service
using the factory specified in implementationFactory
to the collection if the service type hasn't already been registered.
Adds the specified TService as a Scoped service
to the collection if the service type hasn't already been registered.
public static void TryAddScoped<TService, TImplementation>(this IServiceCollection collection) where TImplementation : TService
Adds the specified TService as a Scoped service
implementation type specified in TImplementation
to the collection if the service type hasn't already been registered.
public static void TryAddScoped<TService>(this IServiceCollection services, Func<IServiceProvider, TService> implementationFactory)
Adds the specified TService as a Scoped service
using the factory specified in implementationFactory
to the services if the service type hasn't already been registered.
Adds the specified service as a Singleton service
to the collection if the service type hasn't already been registered.
public static void TryAddSingleton(this IServiceCollection collection, Type service, Type implementationType)
Adds the specified service as a Singleton service
with the implementationType implementation
to the collection if the service type hasn't already been registered.
public static void TryAddSingleton(this IServiceCollection collection, Type service, Func<IServiceProvider, object> implementationFactory)
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.
Adds the specified TService as a Singleton service
to the collection if the service type hasn't already been registered.
public static void TryAddSingleton<TService, TImplementation>(this IServiceCollection collection) where TImplementation : TService
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.
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.
public static void TryAddSingleton<TService>(this IServiceCollection services, Func<IServiceProvider, TService> implementationFactory)
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.
Adds the specified service as a Transient service
to the collection if the service type hasn't already been registered.
public static void TryAddTransient(this IServiceCollection collection, Type service, Type implementationType)
Adds the specified service as a Transient service
with the implementationType implementation
to the collection if the service type hasn't already been registered.
public static void TryAddTransient(this IServiceCollection collection, Type service, Func<IServiceProvider, object> implementationFactory)
Adds the specified service as a Transient service
using the factory specified in implementationFactory
to the collection if the service type hasn't already been registered.
Adds the specified TService as a Transient service
to the collection if the service type hasn't already been registered.
public static void TryAddTransient<TService, TImplementation>(this IServiceCollection collection) where TImplementation : TService
Adds the specified TService as a Transient service
implementation type specified in TImplementation
to the collection if the service type hasn't already been registered.
public static void TryAddTransient<TService>(this IServiceCollection services, Func<IServiceProvider, TService> implementationFactory)
Adds the specified TService as a Transient service
using the factory specified in implementationFactory
to the services if the service type hasn't already been registered.