pip_services3_container library

Preferred Contains implementation of the inversion of control container, which creates objects and controls their lifecycle(*) using various configurations.

Using generic containers, we can create more specialized containers – one of which is the process container. It represents a system process, receives its configuration file via the command line, and creates a container, starts it, reads its configuration, recreates objects, runs them, and then, after pressing ctrl-c, turns off and destroys the objects.

Another example of containers are lambda functions, service fabric containers, and so on.

(*) Component lifecycle:

External configurations (stored as YAML or JSON) are passed to the container and define the structure of objects that need to be recreated in the container. Objects can be defined in two ways:

  • using descriptors (using which registered factories can recreate the object)
  • using hard-coded types (objects are recreated directly, based on their type, bypassing factories).

In addition, various configurations are stored for each object. The container recreates the objects and, if they implement the IConfigurable interface, passes them their configurations.

Once the objects of a container are configured, if they implement the IReferenceable interface, they are passed a set of references for recreating links between objects in the container. If objects implement the IOpenable interface, the open() method is called and they start to work. Connections to various services are made, after which the objects start, the container starts running, and the objects carry out their tasks. When the container starts to close, the objects that implement the IClosable interface are closed via their close() method (which should make them stop working and disconnect from other services), after which objects that implement the IUnreferenceable interface delete various links between objects, and, finally, the contains destroys all objects and turns off.


References decorator that automatically creates missing components using available component factories upon component retrival.
Configuration of a component inside a container.
Inversion of control (IoC) container that creates components and manages their lifecycle.
Container configuration defined as a list of component configurations.
Helper class that reads container configuration from JSON or YAML file.
Container managed references that can be created from container configuration.
Creates default container components (loggers, counters, caches, locks, etc.) by their descriptors.
References decorator that automatically sets references to newly added components that implement IReferenceable interface and unsets references from removed components that implement IUnreferenceable interface.
Managed references that in addition to keeping and locating references can also manage their lifecycle:
Inversion of control (IoC) container that runs as a system process. It processes command line arguments and handles unhandled exceptions and Ctrl-C signal to gracefully shutdown the container.
Chainable decorator for IReferences that allows to inject additional capabilities such as automatic component creation, automatic registration and opening.
References decorator that automatically opens to newly added components that implement IOpenable interface and closes removed components that implement IClosable interface.