node package manager


Dependency Injection via function arguments


JavaScript dependency injection

npm install dependency-injector
var DI = require('dependency-injector')
var di = new DI()

di.register({ foo: 2 })

var functionWithDependency = di.inject(function (foo) {
  return foo

functionWithDependency == 2 // true

Registers your dependencies with the current instance of DI.

register('foo', 2)
register({ foo: 2 })

Utility function to retrieve parameter names from a function.

getParameterNames(function (foo, bar, baz) { }) // == ['foo', 'bar', 'baz']

Creates a function that is loaded with the dependencies. You may pass in additional dependencies at this point.

inject(function (foo + bar) { return foo + bar }, { bar: 3 })

Clones the current set of dependencies into its own object.

var anotherInstance = clone()