Class ServiceCollectionServiceExtensions
- Namespace
- Microsoft.Extensions.DependencyInjection
- Assembly
- nanoFramework.DependencyInjection.dll
Extensions for IServiceCollection.
public static class ServiceCollectionServiceExtensions
- Inheritance
-
ServiceCollectionServiceExtensions
- Inherited Members
Methods
AddScoped(IServiceCollection, Type)
Adds a scoped service of the type specified in serviceType
to the
specified IServiceCollection.
public static IServiceCollection AddScoped(this IServiceCollection services, Type serviceType)
Parameters
services
IServiceCollectionThe IServiceCollection to add the service to.
serviceType
TypeThe type of the service to register and the implementation to use.
Returns
- IServiceCollection
A reference to this instance after the operation has completed.
Exceptions
- ArgumentNullException
services
can't be null.
- See Also
AddScoped(IServiceCollection, Type, ImplementationFactoryDelegate)
Adds a scoped service of the type specified in serviceType
with a
factory specified in implementationFactory
to the
specified IServiceCollection.
public static IServiceCollection AddScoped(this IServiceCollection services, Type serviceType, ImplementationFactoryDelegate implementationFactory)
Parameters
services
IServiceCollectionThe IServiceCollection to add the service to.
serviceType
TypeThe type of the service to register.
implementationFactory
ImplementationFactoryDelegateThe factory that creates the service.
Returns
- IServiceCollection
A reference to this instance after the operation has completed.
Exceptions
- ArgumentNullException
services
can't be null.- ArgumentNullException
serviceType
can't be null.- ArgumentNullException
implementationFactory
can't be null.
- See Also
AddScoped(IServiceCollection, Type, Type)
Adds a scoped service of the type specified in serviceType
with an
implementation of the type specified in implementationType
to the
specified IServiceCollection.
public static IServiceCollection AddScoped(this IServiceCollection services, Type serviceType, Type implementationType)
Parameters
services
IServiceCollectionThe IServiceCollection to add the service to.
serviceType
TypeThe type of the service to register.
implementationType
TypeThe implementation type of the service.
Returns
- IServiceCollection
A reference to this instance after the operation has completed.
Exceptions
- ArgumentNullException
services
can't be null.
- See Also
AddSingleton(IServiceCollection, Type)
Adds a singleton service of the type specified in serviceType
to the
specified IServiceCollection.
public static IServiceCollection AddSingleton(this IServiceCollection services, Type serviceType)
Parameters
services
IServiceCollectionThe IServiceCollection to add the service to.
serviceType
TypeThe type of the service to register and the implementation to use.
Returns
- IServiceCollection
A reference to this instance after the operation has completed.
Exceptions
- ArgumentNullException
services
can't be null.
- See Also
AddSingleton(IServiceCollection, Type, ImplementationFactoryDelegate)
Adds a singleton service of the type specified in serviceType
with a
factory specified in implementationFactory
to the
specified IServiceCollection.
public static IServiceCollection AddSingleton(this IServiceCollection services, Type serviceType, ImplementationFactoryDelegate implementationFactory)
Parameters
services
IServiceCollectionThe IServiceCollection to add the service to.
serviceType
TypeThe type of the service to register.
implementationFactory
ImplementationFactoryDelegateThe factory that creates the service.
Returns
- IServiceCollection
A reference to this instance after the operation has completed.
Exceptions
- ArgumentNullException
services
can't be null.- ArgumentNullException
serviceType
can't be null.- ArgumentNullException
implementationFactory
can't be null.
- See Also
AddSingleton(IServiceCollection, Type, object)
Adds a singleton service of the type specified in serviceType
with an
instance specified in implementationInstance
to the
specified IServiceCollection.
public static IServiceCollection AddSingleton(this IServiceCollection services, Type serviceType, object implementationInstance)
Parameters
services
IServiceCollectionThe IServiceCollection to add the service to.
serviceType
TypeThe type of the service to register.
implementationInstance
objectThe instance of the service.
Returns
- IServiceCollection
A reference to this instance after the operation has completed.
Exceptions
- ArgumentNullException
services
can't be null.
- See Also
AddSingleton(IServiceCollection, Type, Type)
Adds a singleton service of the type specified in serviceType
with an
implementation of the type specified in implementationType
to the
specified IServiceCollection.
public static IServiceCollection AddSingleton(this IServiceCollection services, Type serviceType, Type implementationType)
Parameters
services
IServiceCollectionThe IServiceCollection to add the service to.
serviceType
TypeThe type of the service to register.
implementationType
TypeThe implementation type of the service.
Returns
- IServiceCollection
A reference to this instance after the operation has completed.
Exceptions
- ArgumentNullException
services
can't be null.
- See Also
AddTransient(IServiceCollection, Type)
Adds a transient service of the type specified in serviceType
to the
specified IServiceCollection.
public static IServiceCollection AddTransient(this IServiceCollection services, Type serviceType)
Parameters
services
IServiceCollectionThe IServiceCollection to add the service to.
serviceType
TypeThe type of the service to register and the implementation to use.
Returns
- IServiceCollection
A reference to this instance after the operation has completed.
Exceptions
- ArgumentNullException
services
can't be null.
- See Also
AddTransient(IServiceCollection, Type, ImplementationFactoryDelegate)
Adds a transient service of the type specified in serviceType
with a
factory specified in implementationFactory
to the
specified IServiceCollection.
public static IServiceCollection AddTransient(this IServiceCollection services, Type serviceType, ImplementationFactoryDelegate implementationFactory)
Parameters
services
IServiceCollectionThe IServiceCollection to add the service to.
serviceType
TypeThe type of the service to register.
implementationFactory
ImplementationFactoryDelegateThe factory that creates the service.
Returns
- IServiceCollection
A reference to this instance after the operation has completed.
Exceptions
- ArgumentNullException
services
can't be null.- ArgumentNullException
serviceType
can't be null.- ArgumentNullException
implementationFactory
can't be null.
- See Also
AddTransient(IServiceCollection, Type, Type)
Adds a transient service of the type specified in serviceType
with an
implementation of the type specified in implementationType
to the
specified IServiceCollection.
public static IServiceCollection AddTransient(this IServiceCollection services, Type serviceType, Type implementationType)
Parameters
services
IServiceCollectionThe IServiceCollection to add the service to.
serviceType
TypeThe type of the service to register.
implementationType
TypeThe implementation type of the service.
Returns
- IServiceCollection
A reference to this instance after the operation has completed.
Exceptions
- ArgumentNullException
services
can't be null.
- See Also
RemoveAll(IServiceCollection, Type)
Removes all services of type serviceType
in IServiceCollection.
public static IServiceCollection RemoveAll(this IServiceCollection collection, Type serviceType)
Parameters
collection
IServiceCollectionThe IServiceCollection.
serviceType
TypeThe service type to remove.
Returns
- IServiceCollection
The IServiceCollection for chaining.
Exceptions
- ArgumentNullException
serviceType
can't be null.
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
collection
IServiceCollectionThe IServiceCollection.
descriptor
ServiceDescriptorThe ServiceDescriptor to replace with.
Returns
- IServiceCollection
The IServiceCollection for chaining.
Exceptions
- ArgumentNullException
collection
ordescriptor
can't be null.
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
collection
IServiceCollectionThe IServiceCollection.
descriptor
ServiceDescriptorThe ServiceDescriptor to add.
Exceptions
- ArgumentNullException
collection
ordescriptor
can't be null.
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
services
IServiceCollectionThe IServiceCollection.
descriptor
ServiceDescriptorThe 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(ServiceDescriptor) is not idempotent and can add duplicate ServiceDescriptor instances if called twice. Using TryAddEnumerable(IServiceCollection, ServiceDescriptor) will prevent registration of multiple implementation types.
Exceptions
- ArgumentException
Implementation type cannot be 'implementationType' because it is indistinguishable from other services registered for 'descriptor.ServiceType'.
- ArgumentNullException
services
ordescriptor
can't be null.
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
services
IServiceCollectionThe IServiceCollection.
descriptors
IEnumerableThe ServiceDescriptors.
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(ServiceDescriptor) is not idempotent and can add duplicate ServiceDescriptor instances if called twice. Using TryAddEnumerable(IServiceCollection, ServiceDescriptor) will prevent registration of multiple implementation types.
Exceptions
- ArgumentNullException
services
ordescriptors
can't be null.