https://github.com/suhdev/shinjector
A simple dependency injection module for browser JavaScript applications.
https://github.com/suhdev/shinjector
Last synced: about 1 year ago
JSON representation
A simple dependency injection module for browser JavaScript applications.
- Host: GitHub
- URL: https://github.com/suhdev/shinjector
- Owner: suhdev
- Created: 2015-06-05T14:38:09.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-10-26T20:09:00.000Z (over 10 years ago)
- Last Synced: 2024-12-06T21:47:37.341Z (over 1 year ago)
- Language: JavaScript
- Size: 145 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# shInjector
A simple dependency injection class for JavaScript apps. Supports both named parameters and Angular strict injection model (using arrays). The module has no dependencies, and can be intergrated with any JavaScript application. There will also be a NodeJS version of the injector to be released soon.
## Usage
Just include the file `shinject.min.js` in your html files.
```html
```
Then use it in your code:
```javascript
var injector = new shInjector();
injector.register('testServ',function testServ(logger,serv1){
return {
testServ:function(){
return 'testserv';
}
};
});
injector.register('serv1',function testServ2(logger,testServ){
return {
testServ2:function(){
return 'testserv2';
}
};
});
injector.register('servz',['logger','serv1','testServ',function testServx(logger,serv1,serv2){
return {
testServZ:function(){
return serv1.testServ2()+" "+serv2.testServ();
}
};
}]);
//then to get an instance just use
//injector.get('__NAME__OF__ENTITY__')
var servz = injector.get('servz');
servz.testServZ();
```
Suhail Abood © 2015