ninject
Node Dependency Injection
var config = require('ninject')('config');
init
Should be run in your application's entry point before any require statements.
require('ninject').init(options);
options
- K/V pairs where the
key
is the require name and thevalue
is the path to the file. - The path is from the file where you have initialised.
- K/V pairs where the
//ProjectRoot
// |-example.js
// |-config.js
// |-Controllers
// |-home.js
// |-account.js
var options = {
config: './config',
HomeController: './Controllers/home',
AccountController: './Controllers/account'
}
require('ninject').init(options);
//...the rest of your startup can continue now...
register
External registrations can be made once the init
has run by performing a register
.
require('ninject').register(packageName, packagePath);
packageName
- the name to use when ninjectingpackagePath
- The path to the package.