Skip to content

Latest commit

 

History

History
100 lines (74 loc) · 2.09 KB

README.md

File metadata and controls

100 lines (74 loc) · 2.09 KB

inversion.js

npm version npm Build Status dependencies Inline docs contributions welcome

A lightweight DI and IOC container to register service into service center

Introduction

A lightweight DI and IOC container to register service into service center

Installation

inversion.js can be used in a browser or in a nodejs app. It can be installed via bower or npm:

> $ bower install inversionjs
> $ npm install inversionjs

Simple example

// Module A

function Foo(name, age) {
    this.name = name;
    this.age = age;
}

Foo.prototype.say = function () {
    console.log('My name:' + this.name + ', age: ' + this.age);
}
// Registry

var registry = new Registry();

// Register A via deps
registry.register({
    name: 'moduleDeps',
    module: Foo,
    deps: ['zemin', 'infinity']
});

// Register B via factory
registry.register({
    name: 'moduleFactory',
    module: Foo,
    deps: { name: 'zemin', age: 'infinity' }
    factory: function (registry, Module, deps) {
        return new Module(deps.name, deps.age);
    }
});

registry.get('moduleDeps').say()
registry.get('moduleFactory').say()

//    ==> `My name: zemin, age: infinity`

Test

Test once

> $ npm run test

Or watch files changes

> $ npm run test:watch

Build

Build umd

> $ npm run build:umd

Build umd min

> $ npm run build:umd:min

Build all

> $ npm run build

All built files will in /dist/*