ServiceProvider
Namespace: Wisej.Services
Assembly: Wisej.Framework (3.5.0.0)
Manages services for Wisej.NET's DI implementation.
- C#
- VB.NET
public class ServiceProvider : IServiceProvider
Public Class ServiceProvider
Inherits IServiceProvider
Methods
AddService<TService>(lifetime)
Registers a scoped service.
| Parameter | Type | Description |
|---|---|---|
| TService | The service to add. | |
| lifetime | ServiceLifetime | Scope of the service. Default is Shared. |
Throws:
- InvalidOperationException A service of type TService is already registered.
AddService(serviceType, lifetime)
Registers a scoped service. Since 3.5.4
| Parameter | Type | Description |
|---|---|---|
| serviceType | Type | The type of the service to add. |
| lifetime | ServiceLifetime | Scope of the service. Default is Shared. |
Throws:
- ArgumentNullException serviceType is null or empty.
- InvalidOperationException A service of type serviceType is already registered.
AddService<TService, TImplementation>(lifetime)
Registers a scoped service.
| Parameter | Type | Description |
|---|---|---|
| TService | The type of the service to add. | |
| TImplementation | The type of the implementation to use. | |
| lifetime | ServiceLifetime | Scope of the service. Default is Shared. |
Throws:
- InvalidOperationException A service of type TService is already registered.
AddService(serviceType, implementationType, lifetime)
Registers a scoped service. Since 3.5.4
| Parameter | Type | Description |
|---|---|---|
| serviceType | Type | The type of the service to add. |
| implementationType | Type | The type of the implementation to use. |
| lifetime | ServiceLifetime | Scope of the service. Default is Shared. |
Throws:
- ArgumentNullException serviceType is null or empty.
- ArgumentNullException implementationType is null or empty.
- InvalidOperationException A service of type serviceType is already registered.
AddService<TService>(implementationTypeName, lifetime)
Registers a scoped service.
| Parameter | Type | Description |
|---|---|---|
| TService | The type of the service to add. | |
| implementationTypeName | String | The name of the type of the implementation; can be a fully qualified assembly + type name. |
| lifetime | ServiceLifetime | Scope of the service. Default is Shared. |
Using this overload allows the application to register a service implementation that is loaded dynamically when requested. If implementationTypeName is a fully qualified type name, including the assembly name, the assembly and type are loaded on demand. Throws:
- ArgumentNullException implementationTypeName is null or empty.
- InvalidOperationException A service of type TService is already registered.
AddService(serviceType, implementationTypeName, lifetime)
Registers a scoped service. Since 3.5.4
| Parameter | Type | Description |
|---|---|---|
| serviceType | Type | The type of the service to add. |
| implementationTypeName | String | The name of the type of the implementation; can be a fully qualified assembly + type name. |
| lifetime | ServiceLifetime | Scope of the service. Default is Shared. |
Using this overload allows the application to register a service implementation that is loaded dynamically when requested. If implementationTypeName is a fully qualified type name, including the assembly name, the assembly and type are loaded on demand. Throws:
- ArgumentNullException serviceType is null or empty.
- ArgumentNullException implementationTypeName is null or empty.
- InvalidOperationException A service of type serviceType is already registered.
AddService<TService>(serviceImplementation, lifetime)
Registers a scoped service.
| Parameter | Type | Description |
|---|---|---|
| TService | The service to add. | |
| serviceImplementation | Object | Implementation for the TService . |
| lifetime | ServiceLifetime | Scope of the service. Default is Shared. |
Throws:
- ArgumentNullException serviceImplementation is null.
- InvalidCastException serviceImplementation cannot be assigned to TService .
- InvalidOperationException A service of type TService is already registered.
AddService(serviceType, serviceImplementation, lifetime)
Registers a scoped service. Since 3.5.4
| Parameter | Type | Description |
|---|---|---|
| serviceType | Type | The service to add. |
| serviceImplementation | Object | Implementation for the serviceType . |
| lifetime | ServiceLifetime | Scope of the service. Default is Shared. |
Throws:
- ArgumentNullException serviceType is null.
- ArgumentNullException serviceImplementation is null.
- InvalidCastException serviceImplementation cannot be assigned to serviceType .
- InvalidOperationException A service of type serviceType is already registered.
AddService<TService>(implementationFactory, lifetime)
Registers a scoped service.
| Parameter | Type | Description |
|---|---|---|
| TService | The type of the service to add. | |
| implementationFactory | Func<Type, Object> | Method for creating the TService instance. |
| lifetime | ServiceLifetime | Scope of the service. Default is Shared. |
Throws:
- NullReferenceException implementationFactory is null.
- InvalidOperationException A service of type TService is already registered.
AddService(serviceType, implementationFactory, lifetime)
Registers a scoped service. Since 3.5.4
| Parameter | Type | Description |
|---|---|---|
| serviceType | Type | The type of the service to add. |
| implementationFactory | Func<Type, Object> | Method for creating the serviceType instance. |
| lifetime | ServiceLifetime | Scope of the service. Default is Shared. |
Throws:
- NullReferenceException serviceType is null.
- NullReferenceException implementationFactory is null.
- InvalidOperationException A service of type serviceType is already registered.
GetService<T>()
Returns the requested service.
| Parameter | Type | Description |
|---|---|---|
| T | Type of the service to retrieve. |
Returns: T. An instance of T or null if the service is not found.
GetService(serviceType)
Returns the requested service.
| Parameter | Type | Description |
|---|---|---|
| serviceType | Type | Type of the service to add. |
Returns: Object. An instance of serviceType or null if the service is not found.
Throws:
- ArgumentNullException serviceType is null.
Inject(target)
Injects the services into the properties marked with the InjectAttribute attributed on the specified target object.
| Parameter | Type | Description |
|---|---|---|
| target | Object | Target object to inject dependencies into. |
Throws:
- ArgumentNullException target is null.
RemoveService(serviceType)
Removes the specified service type from the service container.
| Parameter | Type | Description |
|---|---|---|
| serviceType | Type | Type of the service to remove. |
Throws:
- ArgumentNullException serviceType is null.