Simple dependency injection and library loader.


Simple dependency injection and library loader for node.

Rely allows you to depend on named libraries which can be overriden in the configuration.

var rely = require('rely')(options);['dependency1', 'dependency2'], function (dep1dep2) {
  // the dependencies will be automatically injected. 

You should require() rely once in your main script, then use it to load all other dependencies. This way, all other modules share a common container (dependency configuration). Rely can load modules that have not been designed to use Rely, and the dependencies for those modules will still be overriden.

To make the best use of Rely, define modules using the Asynchronous Module Definition:

define("alpha", ["require", "exports", "beta"], function (requireexportsbeta) {
  exports.verb = function() {
    return beta.verb();
    return require("beta").verb();

As well as loading modules that have been defined using define(), modules can be mapped to files by calling map():

// set implementation to be provided for 'name''name', implementation);

The value implementation can be the name of another module to alias, the path to the implementation script, or any value to set as the implementation.

You can also specify all dependencies at the same time by calling map() with an object:{
  'foo': foo,
  'bar': bar

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.


Copyright (c) 2013 Gordon Mackenzie-Leigh Licensed under the MIT license.