npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pip-services3-container-nodex

v1.0.3

Published

IoC container for Pip.Services in Node.js / ES2017

Downloads

114

Readme

IoC container for Node.js / ES2017

This module is a part of the Pip.Services polyglot microservices toolkit. It provides an inversion-of-control (IoC) container to facilitate the development of services and applications composed of loosely coupled components.

The module containes a basic in-memory container that can be embedded inside a service or application, or can be run by itself. The second container type can run as a system level process and can be configured via command line arguments. Also it can be used to create docker containers.

The containers can read configuration from JSON or YAML files use it as a recipe for instantiating and configuring components. Component factories are used to create components based on their locators (descriptor) defined in the container configuration. The factories shall be registered in containers or dynamically in the container configuration file.

The module contains the following packages:

  • Core - Basic in-memory and process containers
  • Build - Default container factory
  • Config - Container configuration components
  • Refer - Inter-container reference management (implementation of the Referenceable pattern inside an IoC container)

Quick links:

Use

Install the NPM package as

npm install pip-services3-container-nodex --save

Create a factory to create components based on their locators (descriptors).

import { Factory } from 'pip-services3-components-nodex';
import { Descriptor } from 'pip-services3-commons-nodex';

export class MyFactory extends Factory {
  public static MyComponentDescriptor = new Descritor("myservice", "mycomponent", "default", "*", "1.0");

  public constructor() {
    super();
    
    this.registerAsType(MyFactor.MyComponentDescriptor, MyComponent);
  }
}

Then create a process container and register the factory there. You can also register factories defined in other modules if you plan to include external components into your container.

import { ProcessContainer } from 'pip-services3-container-nodex';
import { DefaultRpcFactory } from 'pip-services3-rpc-node'; 

export class MyProcess extends ProcessContainer {
  public constructor() {
    super('myservice', 'My service running as a process');
    
    this._factories.add(new DefaultRpcFactory());
    this._factories.add(new MyFactory());
  }
}

Define YAML configuration file with components and their descriptors. The configuration file is pre-processed using Handlebars templating engine that allows to inject configuration parameters or dynamically include/exclude components using conditional blocks. The values for the templating engine are defined via process command line arguments or via environment variables. Support for environment variables works well in docker or other containers like AWS Lambda functions.

---
# Context information
- descriptor: "pip-services:context-info:default:default:1.0"
  name: myservice
  description: My service running in a process container

# Console logger
- descriptor: "pip-services:logger:console:default:1.0"
  level: {{LOG_LEVEL}}{{^LOG_LEVEL}}info{{/LOG_LEVEL}}

# Performance counters that posts values to log
- descriptor: "pip-services:counters:log:default:1.0"
  
# My component
- descriptor: "myservice:mycomponent:default:default:1.0"
  param1: XYZ
  param2: 987
  
{{#if HTTP_ENABLED}}
# HTTP endpoint version 1.0
- descriptor: "pip-services:endpoint:http:default:1.0"
  connection:
    protocol: "http"
    host: "0.0.0.0"
    port: {{HTTP_PORT}}{{^HTTP_PORT}}8080{{/HTTP_PORT}}

 # Default Status
- descriptor: "pip-services:status-service:http:default:1.0"

# Default Heartbeat
- descriptor: "pip-services:heartbeat-service:http:default:1.0"
{{/if}}

To instantiate and run the container we need a simple process launcher.

let MyProcess = require('./MyProcess').MyProcess;

try {
    let proc = new MyProcess();
    proc._configPath = "./config/config.yml";
    proc.run(process.argv);
} catch (ex) {
    console.error(ex);
}

And, finally, you can run your service launcher as

node ./service.js

Develop

For development you shall install the following prerequisites:

  • Node.js 8+
  • Visual Studio Code or another IDE of your choice
  • Docker
  • Typescript

Install dependencies:

npm install

Compile the code:

tsc

Run automated tests:

npm test

Generate API documentation:

./docgen.ps1

Before committing changes run dockerized build and test as:

./build.ps1
./test.ps1
./clear.ps1

Contacts

The Node.js version of Pip.Services is created and maintained by:

  • Sergey Seroukhov

The documentation is written by:

  • Mark Makarychev