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
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Microscopic dependency injection container
npm install @elao/container.js
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();