Just a fast, tiny and useful IoC container made in Javascript
$ npm install inverter-ioc
// Importing the module.
let inverter = require('inverter-ioc');
// Registering the current instance for future use.
inverter.register("registerName", YourClassName);
// Calling a previously created instance.
let resolvedInstance = inverter.resolve("registerName", YourClassName);
// Importing the module.
let inverter = require('inverter-ioc');
// Registering Constants
inverter.register('Constants', function() {
this.pi = 3.14159;
return this;
});
// Registering the circle class, using a previously registred function
inverter.register('Circle', function(Constants) {
this.area = function(radius) {
return Constants.pi * radius * radius;
};
this.getPi = function () {
return Constants.pi;
}
return this;
});
// Resolving the cicle instance
var circle = inverter.resolve('Circle');
// Using the instance
console.log(circle.area(2));
console.log(circle.getPi());
To run the test suite, first install the dependencies, then run npm test
:
$ npm install
$ npm test
To analyze the code coverage status, install all dependencies and run npm run coverage
:
$ npm install
$ npm run coverage
- Upcoming