tiny-di
A tini tiny dependency injection container for node.js/io.js
example
// main.jsvar tiny = ; // `require` the module now and bind it to `app`tiny; var something = ;something; // bind an existing object to `something`tiny; // layz bind// this module is loaded as soon as somebody requests the binding `another`tiny; // use namespacestiny;tiny; // will require('./some/local/dir/foo') // use custom providerstiny; // this function is called whenever a module requires `Somehing` { return 'I was required by ' + envbinding;} // tiny-di comes with built-in resolver which tries// to cover basic use cases.// if you need a more advanced resolving of your deps, you can// set a custom resolver// have a look at the built-in resolver before doing this!tiny; ...
// modulemoduleexports = Module; Module$inject = 'app' 'something' 'another'; { // use the constructor pattern for your modules/libs/classes.. if !this instanceof Module return app something another; var self = this; // app, something and another are injected :) ...}
advanced $inject configuration
// modulemoduleexports = Module; Module$inject = deps: 'app' 'something' 'another' callAs: 'class' // or: 'function' (default is 'function'); { // callAs='class' tells the injector to instantiate a new class // now you don't need to use the constructor pattern. yah! var self = this; // (this instanceof Module) -> true!}
examples
look at the example
-folder for a simple howto
develop
npm installnpm run watch
tests
Test coverage is quite good at the moment (see badge above).
npm installnpm test
license
MIT