Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kroid/node-injector
https://github.com/kroid/node-injector
Last synced: 18 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/kroid/node-injector
- Owner: Kroid
- Created: 2014-08-30T17:52:56.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-09-12T18:39:07.000Z (over 10 years ago)
- Last Synced: 2024-11-05T08:49:56.803Z (2 months ago)
- Language: JavaScript
- Size: 219 KB
- Stars: 0
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
node-injector
=================```js
npn install --save node-injector
```Usage
---------
app.js:
```js
var Injector = require('node-injector')
, rootPath = __dirname
, injector = new Injector(rootPath);injector.set('answer', 42);
injector.load('services/*.js');
injector.done(); // preparinginjector.get('service.answer') === 'answer is 42' // true
```services/printAnswer.js:
```js
module.exports = function(numberAnswer) {
var str = 'answer is ' + numberAnswer;
return str;
};module.exports['@name'] = 'service.answer';
module.exports['@inject'] = ['answer'];
```API
---------```js
var injector = new Injector(rootPath)
``````js
injector.load('foo/bar/**/*.js')
injector.load(['foo/bar/**/*.js', 'foo/bar/**/*.json'])
injector.load(['foo/bar/**/*.js', 'foo/bar/**/*.json'], {basePath: 'app/baz'})
``````js
injector.set(key, value)
injector.setHelper(fn, ['dep1', 'dep2', 'depN'])
injector.setService(key, value, ['dep1', 'dep2', 'depN'])
``````js
injector.get(key)
``````js
injector.done()
``````js
module.exports = function(dep1, dep2) {
// ...
// return anything - object, fn, etc
}module.exports['@name'] = 'anyNameSpace.moduleName'
module.exports['@inject'] = ['dep1', 'foo.dep2']
```