injekt

0.1.9 • Public • Published

INJEKT - Simple Dependency Injection

INJEKT is a tiny, integration-tested dependency injection framework for NodeJS.

Feel free to skip ahead if you know what you're looking for.

Background Philosophy

NOTE: This section is still under construction.

Installation Options

In addition to the options below, you can download either the raw export or package tarball.

Install via npm:

npm install injekt

Clone GIT repository:

git clone git@github.com:arkbot/injekt.git

Syntax: Library Instantiation

General Usage: require('injekt')( default_options [, closure] );

The following examples are all valid. Use them wisely.

Minimal Reference

var injekt = require('injekt')();
  • NOTE: closure defaults to empty { } when default_options are excluded.

Reference via require(...): injekt(...)

var injekt = require('injekt')({
  'context' : {
    'inspect' : require('util').inspect
  },
  'mocks' : { 
    'assert' : require('should')
  }
}, { });

Reference via closure: closure.injekt(...)

var closure = {};
 
require('injekt')({
  'context' : {
    'inspect' : require('util').inspect
  },
  'mocks' : { 
    'assert' : require('should')
  }
}, closure);

Reference via global: global.injekt(...)

require('injekt')({
  'context' : {
    'inspect' : require('util').inspect
  },
  'mocks' : { 
    'assert' : require('should')
  }
});
  • NOTE: closure defaults to global when excluded.

Syntax: Module Injection

General Usage: injekt( module_path [, options] );

INJEKT gives you two different methods of injecting your dependencies:

  • context: embed directly into the global context of your product module.
  • mock: available as a mock to be retrieved via require(...) inside your product module.
var my_module = injekt('./my_module.js', {
  'context' : { 
    'EventEmitter' : require('events').EventEmitter
  },
  'mocks' : {
    'Foo' : Object.create({ bar: function () { return 'YIPPPEEEE!'; } })
  }
});
  • NOTE: module_path must be relative to the overall working directory.

Current Goals

Future Thoughts

  • Use factories for params parsing / properties building
  • Integrate browser compatability:

Bug Reports + Other Requests

  • Please submit an issue on the GitHub Issue Tracker.

  • Please attach at least one of the following for bug reports:

    • diagnostic procedure
    • sample code
    • assertion tests
  • Please e-mail me before sending a pull request.

Further Notes

  • Released under the MIT License (attached).
  • Accompanied by a full integration test suite, via should and vows.
  • DISCLAIMER: This project is still highly experimental - updates may break backwords-compatibility.

Readme

Keywords

none

Package Sidebar

Install

npm i injekt

Weekly Downloads

2

Version

0.1.9

License

none

Last publish

Collaborators

  • aeberlin
  • arkbot