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.
Classes
- BuildReferencesDecorator
- References decorator that automatically creates missing components using available component factories upon component retrival.
- ComponentConfig
- Configuration of a component inside a container.
- Container
- Inversion of control (IoC) container that creates components and manages their lifecycle.
- ContainerConfig
- Container configuration defined as a list of component configurations.
- ContainerConfigReader
- Helper class that reads container configuration from JSON or YAML file.
- ContainerReferences
- Container managed references that can be created from container configuration.
- DefaultContainerFactory
- Creates default container components (loggers, counters, caches, locks, etc.) by their descriptors.
- LinkReferencesDecorator
- References decorator that automatically sets references to newly added components that implement IReferenceable interface and unsets references from removed components that implement IUnreferenceable interface.
- ManagedReferences
- Managed references that in addition to keeping and locating references can also manage their lifecycle:
- ProcessContainer
- 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.
- ReferencesDecorator
- Chainable decorator for IReferences that allows to inject additional capabilities such as automatic component creation, automatic registration and opening.
- RunReferencesDecorator
- References decorator that automatically opens to newly added components that implement IOpenable interface and closes removed components that implement IClosable interface.