Skip to content
/ injekt Public

A tiny dependency injection and context isolation framework for NodeJS.

License

Notifications You must be signed in to change notification settings

arkbot/injekt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

INJEKT - Simple Dependency Injection

Dependency Status Code Climate

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 [email protected]: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

About

A tiny dependency injection and context isolation framework for NodeJS.

Resources

License

Stars

Watchers

Forks

Packages

No packages published