Class ServiceCollectionDescriptorExtensions
- Namespace
- Microsoft.Extensions.DependencyInjection
- Assembly
- nanoFramework.DependencyInjection.dll
Extension methods for adding and removing services to an IServiceCollection.
public static class ServiceCollectionDescriptorExtensions
- Inheritance
-
ServiceCollectionDescriptorExtensions
- Inherited Members
Methods
Add(IServiceCollection, ServiceDescriptor)
Adds the specified descriptor to the collection.
public static IServiceCollection Add(this IServiceCollection collection, ServiceDescriptor descriptor)
Parameters
collectionIServiceCollectionThe IServiceCollection.
descriptorServiceDescriptorThe ServiceDescriptor to add.
Returns
- IServiceCollection
A reference to the current instance of IServiceCollection.
Add(IServiceCollection, IEnumerable)
Adds a sequence of ServiceDescriptor to the collection.
public static IServiceCollection Add(this IServiceCollection collection, IEnumerable descriptors)
Parameters
collectionIServiceCollectionThe IServiceCollection.
descriptorsIEnumerableThe ServiceDescriptors to add.
Returns
- IServiceCollection
A reference to the current instance of IServiceCollection.
RemoveAll(IServiceCollection, Type)
Removes all services of type serviceType in IServiceCollection.
public static IServiceCollection RemoveAll(this IServiceCollection collection, Type serviceType)
Parameters
collectionIServiceCollectionThe IServiceCollection.
serviceTypeTypeThe service type to remove.
Returns
- IServiceCollection
The IServiceCollection for chaining.
Replace(IServiceCollection, ServiceDescriptor)
Removes the first service in IServiceCollection with the same service type
as descriptor and adds descriptor to the collection.
public static IServiceCollection Replace(this IServiceCollection collection, ServiceDescriptor descriptor)
Parameters
collectionIServiceCollectionThe IServiceCollection.
descriptorServiceDescriptorThe ServiceDescriptor to replace with.
Returns
- IServiceCollection
The IServiceCollection for chaining.
TryAdd(IServiceCollection, ServiceDescriptor)
Adds the specified descriptor to the collection if the
service type hasn't already been registered.
public static void TryAdd(this IServiceCollection collection, ServiceDescriptor descriptor)
Parameters
collectionIServiceCollectionThe IServiceCollection.
descriptorServiceDescriptorThe ServiceDescriptor to add.
TryAdd(IServiceCollection, IEnumerable)
Adds the specified descriptors to the collection if the
service type hasn't already been registered.
public static void TryAdd(this IServiceCollection collection, IEnumerable descriptors)
Parameters
collectionIServiceCollectionThe IServiceCollection.
descriptorsIEnumerableThe ServiceDescriptors to add.
TryAddEnumerable(IServiceCollection, ServiceDescriptor)
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, ServiceDescriptor descriptor)
Parameters
servicesIServiceCollectionThe IServiceCollection.
descriptorServiceDescriptorThe ServiceDescriptor.
Remarks
Use TryAddEnumerable(IServiceCollection, ServiceDescriptor) when registering a service implementation of a service type that supports multiple registrations of the same service type. Using Add(IServiceCollection, ServiceDescriptor) is not idempotent and can add duplicate ServiceDescriptor instances if called twice. Using TryAddEnumerable(IServiceCollection, ServiceDescriptor) will prevent registration of multiple implementation types.
TryAddEnumerable(IServiceCollection, IEnumerable)
Adds the specified ServiceDescriptors 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 descriptors)
Parameters
servicesIServiceCollectionThe IServiceCollection.
descriptorsIEnumerableThe ServiceDescriptors.
Remarks
Use TryAddEnumerable(IServiceCollection, IEnumerable) when registering a service implementation of a service type that supports multiple registrations of the same service type. Using Add(IServiceCollection, IEnumerable) is not idempotent and can add duplicate ServiceDescriptor instances if called twice. Using TryAddEnumerable(IServiceCollection, IEnumerable) will prevent registration of multiple implementation types.
TryAddScoped(IServiceCollection, Type)
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)
Parameters
collectionIServiceCollectionThe IServiceCollection.
serviceTypeThe type of the service to register.
TryAddScoped(IServiceCollection, Type, Type)
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, Type implementationType)
Parameters
collectionIServiceCollectionThe IServiceCollection.
serviceTypeThe type of the service to register.
implementationTypeTypeThe implementation type of the service.
TryAddSingleton(IServiceCollection, Type)
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)
Parameters
collectionIServiceCollectionThe IServiceCollection.
serviceTypeThe type of the service to register.
TryAddSingleton(IServiceCollection, Type, Type)
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, Type implementationType)
Parameters
collectionIServiceCollectionThe IServiceCollection.
serviceTypeThe type of the service to register.
implementationTypeTypeThe implementation type of the service.
TryAddTransient(IServiceCollection, Type)
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)
Parameters
collectionIServiceCollectionThe IServiceCollection.
serviceTypeThe type of the service to register.
TryAddTransient(IServiceCollection, Type, Type)
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, Type implementationType)
Parameters
collectionIServiceCollectionThe IServiceCollection.
serviceTypeThe type of the service to register.
implementationTypeTypeThe implementation type of the service.