ServiceProvider

Wisej.Services.ServiceProvider

Namespace: Wisej.Services

Assembly: Wisej.Framework (4.0.0.0)

Manages services for Wisej.NET's DI implementation.

public class ServiceProvider : IServiceProvider

Methods

AddOrReplaceService<TService>(lifetime)

Registers or replaces a scoped service. Since 4.0.0

Parameter
Type
Description

TService

The service to add.

lifetime

Scope of the service. Default is Shared.

Returns: ServiceProvider.

Throws:

AddOrReplaceService(serviceType, lifetime)

Registers or replaces a scoped service. Since 4.0.0

Parameter
Type
Description

serviceType

The type of the service to add.

lifetime

Scope 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:

AddOrReplaceService<TService, TImplementation>(lifetime)

Registers or replaces a scoped service. Since 4.0.0

Parameter
Type
Description

TService

The type of the service to add.

TImplementation

The type of the implementation to use.

lifetime

Scope of the service. Default is Shared.

Returns: ServiceProvider.

Throws:

AddOrReplaceService(serviceType, implementationType, lifetime)

Registers a scoped service. Since 4.0.0

Parameter
Type
Description

serviceType

The type of the service to add.

implementationType

The type of the implementation to use.

lifetime

Scope 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:

AddOrReplaceService<TService>(implementationTypeName, lifetime)

Registers or replaces a scoped service. Since 4.0.0

Parameter
Type
Description

TService

The type of the service to add.

implementationTypeName

The name of the type of the implementation; can be a fully qualified assembly + type name.

lifetime

Scope 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:

AddOrReplaceService(serviceType, implementationTypeName, lifetime)

Registers or replaces a scoped service. Since 4.0.0

Parameter
Type
Description

serviceType

The type of the service to add.

implementationTypeName

The name of the type of the implementation; can be a fully qualified assembly + type name.

lifetime

Scope 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:

AddOrReplaceService<TService>(serviceImplementation, lifetime)

Registers or replaces a scoped service. Since 4.0.0

Parameter
Type
Description

TService

The service to add.

serviceImplementation

Implementation for the TService .

lifetime

Scope of the service. Default is Shared.

Returns: ServiceProvider.

Throws:

AddOrReplaceService(serviceType, serviceImplementation, lifetime)

Registers or replaces a scoped service. Since 4.0.0

Parameter
Type
Description

serviceType

The service to add.

serviceImplementation

Implementation for the serviceType .

lifetime

Scope 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:

AddOrReplaceService<TService>(implementationFactory, lifetime)

Registers or replaces a scoped service. Since 4.0.0

Parameter
Type
Description

TService

The type of the service to add.

implementationFactory

Method for creating the TService instance.

lifetime

Scope of the service. Default is Shared.

Returns: ServiceProvider.

Throws:

AddOrReplaceService(serviceType, implementationFactory, lifetime)

Registers or replaces a scoped service. Since 4.0.0

Parameter
Type
Description

serviceType

The type of the service to add.

implementationFactory

Method for creating the serviceType instance.

lifetime

Scope 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:

AddService<TService>(lifetime)

Registers a scoped service.

Parameter
Type
Description

TService

The service to add.

lifetime

Scope of the service. Default is Shared.

Returns: ServiceProvider.

Throws:

AddService(serviceType, lifetime)

Registers a scoped service. Since 3.5.4

Parameter
Type
Description

serviceType

The type of the service to add.

lifetime

Scope 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:

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

Scope of the service. Default is Shared.

Returns: ServiceProvider.

Throws:

AddService(serviceType, implementationType, lifetime)

Registers a scoped service. Since 3.5.4

Parameter
Type
Description

serviceType

The type of the service to add.

implementationType

The type of the implementation to use.

lifetime

Scope 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:

AddService<TService>(implementationTypeName, lifetime)

Registers a scoped service.

Parameter
Type
Description

TService

The type of the service to add.

implementationTypeName

The name of the type of the implementation; can be a fully qualified assembly + type name.

lifetime

Scope 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:

AddService(serviceType, implementationTypeName, lifetime)

Registers a scoped service. Since 3.5.4

Parameter
Type
Description

serviceType

The type of the service to add.

implementationTypeName

The name of the type of the implementation; can be a fully qualified assembly + type name.

lifetime

Scope 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:

AddService<TService>(serviceImplementation, lifetime)

Registers a scoped service.

Parameter
Type
Description

TService

The service to add.

serviceImplementation

Implementation for the TService .

lifetime

Scope of the service. Default is Shared.

Returns: ServiceProvider.

Throws:

AddService(serviceType, serviceImplementation, lifetime)

Registers a scoped service. Since 3.5.4

Parameter
Type
Description

serviceType

The service to add.

serviceImplementation

Implementation for the serviceType .

lifetime

Scope 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:

AddService<TService>(implementationFactory, lifetime)

Registers a scoped service.

Parameter
Type
Description

TService

The type of the service to add.

implementationFactory

Method for creating the TService instance.

lifetime

Scope of the service. Default is Shared.

Returns: ServiceProvider.

Throws:

AddService(serviceType, implementationFactory, lifetime)

Registers a scoped service. Since 3.5.4

Parameter
Type
Description

serviceType

The type of the service to add.

implementationFactory

Method for creating the serviceType instance.

lifetime

Scope 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:

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 of the service to add.

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

Throws:

HasService<T>()

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

Parameter
Type
Description

T

Service type to check.

Returns: Boolean. true if the service is registered.

HasService(serviceType)

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

Parameter
Type
Description

serviceType

Service type to check.

Returns: Boolean. true if the service is registered.

Inject(target)

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

Parameter
Type
Description

target

Target object to inject dependencies into.

Throws:

RemoveService<TService>()

Removes the specified service type from the service container.

Parameter
Type
Description

TService

The service to remove.

Returns: ServiceProvider.

RemoveService(serviceType)

Removes the specified service type from the service container.

Parameter
Type
Description

serviceType

Type of the service to remove.

Returns: ServiceProvider.

Throws:

Last updated

Was this helpful?