Class ServiceCollectionServiceExtensions
Extensions for IServiceCollection.
Inherited Members
Namespace: nanoFramework.DependencyInjection
Assembly: nanoFramework.DependencyInjection.dll
Syntax
public static class ServiceCollectionServiceExtensions
Methods
AddScoped(IServiceCollection, Type)
Adds a scoped service of the type specified in serviceType
to the
specified IServiceCollection.
Declaration
public static IServiceCollection AddScoped(this IServiceCollection services, Type serviceType)
Parameters
Type | Name | Description |
---|---|---|
IServiceCollection | services | The IServiceCollection to add the service to. |
Type | serviceType | The type of the service to register and the implementation to use. |
Returns
Type | Description |
---|---|
IServiceCollection | A reference to this instance after the operation has completed. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
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.
Declaration
public static IServiceCollection AddScoped(this IServiceCollection services, Type serviceType, Type implementationType)
Parameters
Type | Name | Description |
---|---|---|
IServiceCollection | services | The IServiceCollection to add the service to. |
Type | serviceType | The type of the service to register. |
Type | implementationType | The implementation type of the service. |
Returns
Type | Description |
---|---|
IServiceCollection | A reference to this instance after the operation has completed. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
See Also
AddSingleton(IServiceCollection, Type)
Adds a singleton service of the type specified in serviceType
to the
specified IServiceCollection.
Declaration
public static IServiceCollection AddSingleton(this IServiceCollection services, Type serviceType)
Parameters
Type | Name | Description |
---|---|---|
IServiceCollection | services | The IServiceCollection to add the service to. |
Type | serviceType | The type of the service to register and the implementation to use. |
Returns
Type | Description |
---|---|
IServiceCollection | A reference to this instance after the operation has completed. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
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.
Declaration
public static IServiceCollection AddSingleton(this IServiceCollection services, Type serviceType, object implementationInstance)
Parameters
Type | Name | Description |
---|---|---|
IServiceCollection | services | The IServiceCollection to add the service to. |
Type | serviceType | The type of the service to register. |
object | implementationInstance | The instance of the service. |
Returns
Type | Description |
---|---|
IServiceCollection | A reference to this instance after the operation has completed. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
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.
Declaration
public static IServiceCollection AddSingleton(this IServiceCollection services, Type serviceType, Type implementationType)
Parameters
Type | Name | Description |
---|---|---|
IServiceCollection | services | The IServiceCollection to add the service to. |
Type | serviceType | The type of the service to register. |
Type | implementationType | The implementation type of the service. |
Returns
Type | Description |
---|---|
IServiceCollection | A reference to this instance after the operation has completed. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
See Also
AddTransient(IServiceCollection, Type)
Adds a transient service of the type specified in serviceType
to the
specified IServiceCollection.
Declaration
public static IServiceCollection AddTransient(this IServiceCollection services, Type serviceType)
Parameters
Type | Name | Description |
---|---|---|
IServiceCollection | services | The IServiceCollection to add the service to. |
Type | serviceType | The type of the service to register and the implementation to use. |
Returns
Type | Description |
---|---|
IServiceCollection | A reference to this instance after the operation has completed. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
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.
Declaration
public static IServiceCollection AddTransient(this IServiceCollection services, Type serviceType, Type implementationType)
Parameters
Type | Name | Description |
---|---|---|
IServiceCollection | services | The IServiceCollection to add the service to. |
Type | serviceType | The type of the service to register. |
Type | implementationType | The implementation type of the service. |
Returns
Type | Description |
---|---|
IServiceCollection | A reference to this instance after the operation has completed. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
See Also
RemoveAll(IServiceCollection, Type)
Removes all services of type serviceType
in IServiceCollection.
Declaration
public static IServiceCollection RemoveAll(this IServiceCollection collection, Type serviceType)
Parameters
Type | Name | Description |
---|---|---|
IServiceCollection | collection | The IServiceCollection. |
Type | serviceType | The service type to remove. |
Returns
Type | Description |
---|---|
IServiceCollection | The IServiceCollection for chaining. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Replace(IServiceCollection, ServiceDescriptor)
Removes the first service in IServiceCollection with the same service type
as descriptor
and adds descriptor
to the collection.
Declaration
public static IServiceCollection Replace(this IServiceCollection collection, ServiceDescriptor descriptor)
Parameters
Type | Name | Description |
---|---|---|
IServiceCollection | collection | The IServiceCollection. |
ServiceDescriptor | descriptor | The ServiceDescriptor to replace with. |
Returns
Type | Description |
---|---|
IServiceCollection | The IServiceCollection for chaining. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
TryAdd(IServiceCollection, ServiceDescriptor)
Adds the specified descriptor
to the collection
if the
service type hasn't already been registered.
Declaration
public static void TryAdd(this IServiceCollection collection, ServiceDescriptor descriptor)
Parameters
Type | Name | Description |
---|---|---|
IServiceCollection | collection | The IServiceCollection. |
ServiceDescriptor | descriptor | The ServiceDescriptor to add. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
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..
.
Declaration
public static void TryAddEnumerable(this IServiceCollection services, IEnumerable descriptors)
Parameters
Type | Name | Description |
---|---|---|
IServiceCollection | services | The IServiceCollection. |
IEnumerable | descriptors | The 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
Type | Condition |
---|---|
ArgumentNullException |
|
TryAddEnumerable(IServiceCollection, ServiceDescriptor)
Adds a ServiceDescriptor if an existing descriptor with the same
ServiceType and an implementation that does not already exist
in services..
.
Declaration
public static void TryAddEnumerable(this IServiceCollection services, ServiceDescriptor descriptor)
Parameters
Type | Name | Description |
---|---|---|
IServiceCollection | services | The IServiceCollection. |
ServiceDescriptor | descriptor | The 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
Type | Condition |
---|---|
ArgumentException | Implementation type cannot be 'implementationType' because it is indistinguishable from other services registered for 'descriptor.ServiceType'. |
ArgumentNullException |
|