Options
All
  • Public
  • Public/Protected
  • All
Menu

Class 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.

Command line arguments

  • --config / -c path to JSON or YAML file with container configuration (default: "./config/config.yml")
  • --param / --params / -p value(s) to parameterize the container configuration
  • --help / -h prints the container usage help
see

Container

Example

let container = new ProcessContainer();
container.addFactory(new MyComponentFactory());

container.run(process.args);

Hierarchy

Implements

  • any
  • any
  • any
  • any

Index

Constructors

constructor

  • Creates a new instance of the container.

    Parameters

    • Optional name: string

      (optional) a container name (accessible via ContextInfo)

    • Optional description: string

      (optional) a container description (accessible via ContextInfo)

    Returns ProcessContainer

Properties

Protected _config

Protected _configPath

_configPath: string = "./config/config.yml"

Protected _factories

_factories: DefaultContainerFactory = new DefaultContainerFactory()

Protected _info

_info: ContextInfo

Protected _logger

_logger: ILogger = new NullLogger()

Protected _references

_references: ContainerReferences

Methods

addFactory

  • addFactory(factory: IFactory): void
  • Adds a factory to the container. The factory is used to create components added to the container by their locators (descriptors).

    Parameters

    • factory: IFactory

      a component factory to be added.

    Returns void

close

  • close(correlationId: string, callback?: function): void
  • Closes component and frees used resources.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • Optional callback: function

      callback function that receives error or null no errors occured.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

configure

  • configure(config: ConfigParams): void
  • Configures component by passing configuration parameters.

    Parameters

    • config: ConfigParams

      configuration parameters to be set.

    Returns void

isOpen

  • isOpen(): boolean
  • Checks if the component is opened.

    Returns boolean

    true if the component has been opened and false otherwise.

open

  • open(correlationId: string, callback?: function): void
  • Opens the component.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • Optional callback: function

      callback function that receives error or null no errors occured.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

readConfigFromFile

  • readConfigFromFile(correlationId: string, path: string, parameters: ConfigParams): void
  • Reads container configuration from JSON or YAML file and parameterizes it with given values.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • path: string

      a path to configuration file

    • parameters: ConfigParams

      values to parameters the configuration or null to skip parameterization.

    Returns void

run

  • run(args: string[]): void
  • Runs the container by instantiating and running components inside the container.

    It reads the container configuration, creates, configures, references and opens components. On process exit it closes, unreferences and destroys components to gracefully shutdown.

    Parameters

    • args: string[]

      command line arguments

    Returns void

setReferences

  • setReferences(references: IReferences): void
  • Sets references to dependent components.

    Parameters

    • references: IReferences

      references to locate the component dependencies.

    Returns void

unsetReferences

  • unsetReferences(): void
  • Unsets (clears) previously set references to dependent components.

    Returns void

Generated using TypeDoc