Elao/container.js

Name: container.js

Owner: Elao

Description: Microscopic dependency injection container

Created: 2017-03-28 12:31:18.0

Updated: 2017-12-15 08:56:15.0

Pushed: 2017-06-13 07:09:09.0

Homepage: null

Size: 10

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

container.js

Microscopic dependency injection container

Installation
npm install @elao/container.js
Usage

Given the given class, you want to declare as a service:

yApiClient.js
rt default class MyApiClient {
constructor(host, key) {
    this.host = host;
    this.key = key;
}

login() {
    // ...
}

Set up your container like that:

y-container.js
rt Container from '@elao/container.js';
rt MyApiClient from './MyApiClient';

t container = new Container();

egister a parameter:
ainer.registerParameter('api:host', 'my.api.com');
ainer.registerParameter('api:key', 'xxxxxxxxxxx');

egister a service:
ainer.registerDefinition('api', MyApiClient, ['api:host', 'api:key']);

rt default container;

Require the api service wherever you need it:

rt container from 'my-container.js';

ainer.get('api').login();

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.