inverter-ioc
Version:
Just an ioc container made in javascript
85 lines (65 loc) • 2.11 kB
Markdown
Just a fast, tiny and useful IoC container made in Javascript
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Linux Build][travis-image]][travis-url]
[![Coverage][coverage-image]][coverage-url]
```bash
$ npm install inverter-ioc
```
```js
// Importing the module.
let inverter = import('inverter-ioc');
// Registering the current instance for future use.
inverter.register("registerName", YourClassName);
// Calling a previously created instance.
let resolvedInstance = inverter.resolve("registerName", YourClassName);
```
```js
// 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`:
```bash
$ npm install
$ npm test
```
To analyze the code coverage status, install all dependencies and run `npm run coverage`:
```bash
$ npm install
$ npm run coverage
```
* Upcoming
[](LICENSE)
[]: https://img.shields.io/npm/v/inverter-ioc.svg
[]: https://npmjs.org/package/inverter-ioc
[]: https://img.shields.io/npm/dm/inverter-ioc.svg
[]: https://npmjs.org/package/inverter-ioc
[]: https://coveralls.io/github/felipeuntill/inverter-ioc?branch=master
[]: https://travis-ci.org/felipeuntill/inverter-ioc.svg
[]: https://coveralls.io/repos/github/felipeuntill/inverter-ioc/badge.svg?branch=master
[]: https://travis-ci.org/felipeuntill/inverter-ioc