Home Reference Source Repository

emblem

Angie Injector

npm version iojs support node support npm downloads build status Coverage Status documentation

NPM

About

This is a very slim dependency injector for the Angie Framework. It will, based on the instantiated Angie application, inject functional dependencies into modules which have been registered via the exposed Angie application functions (including Controller, directive or component or view, config, and factory). The module itself can also be used via manual import to use the $Injector functionally. It also provides supported decorators for additional injection support.

Usage

Note: as of version 1.0.0, this package can no longer be used standalone, it must be used as a byproduct of an Angie application via the Angie Framework. 0.10.x versions and below will continue to be supported for standalone use.

npm i -g angie-injector
import $Injector, { $injectionBinder as binder } from 'angie-injector';
import { injector } from 'angie-injector/src/util/decorators';
import { Controller } from 'angie/src/util/decorators';

// Fetch dependencies
const test = $Injector.get('test');

// Fetch many dependencies, excusing for a moment that `test` cannot be redefined
const [ test, test1 ] = $Injector.get('test', 'test1');

// Bind arguments to a function using the injector service
binder(function(test) {
    return test === 'test';
});

// Slim decorator for instance methods
class Test {
    constructor() {
        this._test = this.test();
    }
    @injector
    test(test) {
        test === 'test'; // true
    }
}

// Or, on modules
@Controller
class Test {
    constructor(test) {
        test === 'test'; // true
    }
}

For a list of Frequently Asked Questions, please see the FAQ and the CHANGELOG for an up to date list of changes. Contributors to this Project are outlined in the CONTRIBUTORS file.

Documentation

Angie Injector documentation can be found here.

Angie

Please see the site for information about the project, a quickstart guide, and documentation and the CHANGELOG for an up to date list of changes.