Skip to main content
Version: 4.1

ServiceProvider

Namespace: Wisej.Services

Assembly: Wisej.Framework (4.1.0.0)

Manages services for Wisej.NET's DI implementation.

public class ServiceProvider : IServiceProvider

Methods

Instance member AddOrReplaceService<TService>(lifetime)

Registers or replaces a scoped service. Since 4.0.0

ParameterTypeDescription
TServiceThe service to add.
lifetime optionalServiceLifetimeScope of the service. Default is Shared.

Returns: ServiceProvider.

Throws:

Instance member AddOrReplaceService(serviceType, lifetime)

Registers or replaces a scoped service. Since 4.0.0

ParameterTypeDescription
serviceTypeTypeThe type of the service to add.
lifetime optionalServiceLifetimeScope of the service. Default is Shared.

Returns: ServiceProvider.

This non-generic method supports the registration of generic services:


![
Application.Services.AddService(typeof(DBConnection<>));
...
var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
var dbEmployees = Application.Services.GetService<DBConnection<Employee>>);

Throws:

Instance member AddOrReplaceService<TService, TImplementation>(lifetime)

Registers or replaces a scoped service. Since 4.0.0

ParameterTypeDescription
TServiceThe type of the service to add.
TImplementationThe type of the implementation to use.
lifetime optionalServiceLifetimeScope of the service. Default is Shared.

Returns: ServiceProvider.

Throws:

Instance member AddOrReplaceService(serviceType, implementationType, lifetime)

Registers a scoped service. Since 4.0.0

ParameterTypeDescription
serviceTypeTypeThe type of the service to add.
implementationTypeTypeThe type of the implementation to use.
lifetime optionalServiceLifetimeScope of the service. Default is Shared.

Returns: ServiceProvider.

This non-generic method supports the registration of generic services:


![
Application.Services.AddService(typeof(DBConnection<>));
...
var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
var dbEmployees = Application.Services.GetService<DBConnection<Employee>>);

Throws:

Instance member AddOrReplaceService<TService>(implementationTypeName, lifetime)

Registers or replaces a scoped service. Since 4.0.0

ParameterTypeDescription
TServiceThe type of the service to add.
implementationTypeNameStringThe name of the type of the implementation; can be a fully qualified assembly + type name.
lifetime optionalServiceLifetimeScope of the service. Default is Shared.

Returns: ServiceProvider.

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:

Instance member AddOrReplaceService(serviceType, implementationTypeName, lifetime)

Registers or replaces a scoped service. Since 4.0.0

ParameterTypeDescription
serviceTypeTypeThe type of the service to add.
implementationTypeNameStringThe name of the type of the implementation; can be a fully qualified assembly + type name.
lifetime optionalServiceLifetimeScope of the service. Default is Shared.

Returns: ServiceProvider.

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.

This non-generic method supports the registration of generic services:


![
Application.Services.AddService(typeof(DBConnection<>));
...
var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
var dbEmployees = Application.Services.GetService<DBConnection<Employee>>);

Throws:

Instance member AddOrReplaceService<TService>(serviceImplementation, lifetime)

Registers or replaces a scoped service. Since 4.0.0

ParameterTypeDescription
TServiceThe service to add.
serviceImplementationObjectImplementation for the TService .
lifetime optionalServiceLifetimeScope of the service. Default is Shared.

Returns: ServiceProvider.

Throws:

Instance member AddOrReplaceService(serviceType, serviceImplementation, lifetime)

Registers or replaces a scoped service. Since 4.0.0

ParameterTypeDescription
serviceTypeTypeThe service to add.
serviceImplementationObjectImplementation for the serviceType .
lifetime optionalServiceLifetimeScope of the service. Default is Shared.

Returns: ServiceProvider.

This non-generic method supports the registration of generic services:


![
Application.Services.AddService(typeof(DBConnection<>));
...
var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
var dbEmployees = Application.Services.GetService<DBConnection<Employee>>);

Throws:

Instance member AddOrReplaceService<TService>(implementationFactory, lifetime)

Registers or replaces a scoped service. Since 4.0.0

ParameterTypeDescription
TServiceThe type of the service to add.
implementationFactoryFunc<Type, Object>Method for creating the TService instance.
lifetime optionalServiceLifetimeScope of the service. Default is Shared.

Returns: ServiceProvider.

Throws:

Instance member AddOrReplaceService(serviceType, implementationFactory, lifetime)

Registers or replaces a scoped service. Since 4.0.0

ParameterTypeDescription
serviceTypeTypeThe type of the service to add.
implementationFactoryFunc<Type, Object>Method for creating the serviceType instance.
lifetime optionalServiceLifetimeScope of the service. Default is Shared.

Returns: ServiceProvider.

This non-generic method supports the registration of generic services:


![
Application.Services.AddService(typeof(DBConnection<>));
...
var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
var dbEmployees = Application.Services.GetService<DBConnection<Employee>>);

Throws:

Instance member AddService<TService>(lifetime)

Registers a scoped service.

ParameterTypeDescription
TServiceThe service to add.
lifetime optionalServiceLifetimeScope of the service. Default is Shared.

Returns: ServiceProvider.

Throws:

Instance member AddService(serviceType, lifetime)

Registers a scoped service. Since 3.5.4

ParameterTypeDescription
serviceTypeTypeThe type of the service to add.
lifetime optionalServiceLifetimeScope of the service. Default is Shared.

Returns: ServiceProvider.

This non-generic method supports the registration of generic services:


![
Application.Services.AddService(typeof(DBConnection<>));
...
var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
var dbEmployees = Application.Services.GetService<DBConnection<Employee>>);

Throws:

Instance member AddService<TService, TImplementation>(lifetime)

Registers a scoped service.

ParameterTypeDescription
TServiceThe type of the service to add.
TImplementationThe type of the implementation to use.
lifetime optionalServiceLifetimeScope of the service. Default is Shared.

Returns: ServiceProvider.

Throws:

Instance member AddService(serviceType, implementationType, lifetime)

Registers a scoped service. Since 3.5.4

ParameterTypeDescription
serviceTypeTypeThe type of the service to add.
implementationTypeTypeThe type of the implementation to use.
lifetime optionalServiceLifetimeScope of the service. Default is Shared.

Returns: ServiceProvider.

This non-generic method supports the registration of generic services:


![
Application.Services.AddService(typeof(DBConnection<>));
...
var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
var dbEmployees = Application.Services.GetService<DBConnection<Employee>>);

Throws:

Instance member AddService<TService>(implementationTypeName, lifetime)

Registers a scoped service.

ParameterTypeDescription
TServiceThe type of the service to add.
implementationTypeNameStringThe name of the type of the implementation; can be a fully qualified assembly + type name.
lifetime optionalServiceLifetimeScope of the service. Default is Shared.

Returns: ServiceProvider.

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:

Instance member AddService(serviceType, implementationTypeName, lifetime)

Registers a scoped service. Since 3.5.4

ParameterTypeDescription
serviceTypeTypeThe type of the service to add.
implementationTypeNameStringThe name of the type of the implementation; can be a fully qualified assembly + type name.
lifetime optionalServiceLifetimeScope of the service. Default is Shared.

Returns: ServiceProvider.

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.

This non-generic method supports the registration of generic services:


![
Application.Services.AddService(typeof(DBConnection<>));
...
var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
var dbEmployees = Application.Services.GetService<DBConnection<Employee>>);

Throws:

Instance member AddService<TService>(serviceImplementation, lifetime)

Registers a scoped service.

ParameterTypeDescription
TServiceThe service to add.
serviceImplementationObjectImplementation for the TService .
lifetime optionalServiceLifetimeScope of the service. Default is Shared.

Returns: ServiceProvider.

Throws:

Instance member AddService(serviceType, serviceImplementation, lifetime)

Registers a scoped service. Since 3.5.4

ParameterTypeDescription
serviceTypeTypeThe service to add.
serviceImplementationObjectImplementation for the serviceType .
lifetime optionalServiceLifetimeScope of the service. Default is Shared.

Returns: ServiceProvider.

This non-generic method supports the registration of generic services:


![
Application.Services.AddService(typeof(DBConnection<>));
...
var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
var dbEmployees = Application.Services.GetService<DBConnection<Employee>>);

Throws:

Instance member AddService<TService>(implementationFactory, lifetime)

Registers a scoped service.

ParameterTypeDescription
TServiceThe type of the service to add.
implementationFactoryFunc<Type, Object>Method for creating the TService instance.
lifetime optionalServiceLifetimeScope of the service. Default is Shared.

Returns: ServiceProvider.

Throws:

Instance member AddService(serviceType, implementationFactory, lifetime)

Registers a scoped service. Since 3.5.4

ParameterTypeDescription
serviceTypeTypeThe type of the service to add.
implementationFactoryFunc<Type, Object>Method for creating the serviceType instance.
lifetime optionalServiceLifetimeScope of the service. Default is Shared.

Returns: ServiceProvider.

This non-generic method supports the registration of generic services:


![
Application.Services.AddService(typeof(DBConnection<>));
...
var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
var dbEmployees = Application.Services.GetService<DBConnection<Employee>>);

Throws:

Instance member GetService<T>()

Returns the requested service.

ParameterTypeDescription
TType of the service to retrieve.

Returns: T. An instance of T or null if the service is not found.

Instance member GetService(serviceType)

Returns the requested service.

ParameterTypeDescription
serviceTypeTypeType of the service to add.

Returns: Object. An instance of serviceType or null if the service is not found.

Throws:

Instance member HasService<T>()

Checks if a service of type T is already registered. Since 3.5.12

ParameterTypeDescription
TService type to check.

Returns: Boolean. true if the service is registered.

Instance member HasService(serviceType)

Checks if a service of type serviceType is already registered. Since 3.5.12

ParameterTypeDescription
serviceTypeTypeService type to check.

Returns: Boolean. true if the service is registered.

Instance member Inject(target)

Injects the services into the properties marked with the InjectAttribute attributed on the specified target object.

ParameterTypeDescription
targetObjectTarget object to inject dependencies into.

Throws:

Instance member RemoveService<TService>()

Removes the specified service type from the service container.

ParameterTypeDescription
TServiceThe service to remove.

Returns: ServiceProvider.

Instance member RemoveService(serviceType)

Removes the specified service type from the service container.

ParameterTypeDescription
serviceTypeTypeType of the service to remove.

Returns: ServiceProvider.

Throws: