Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brunocarvalhodearaujo/dotie
tiny, powerful dependency injection container for node and browser
https://github.com/brunocarvalhodearaujo/dotie
Last synced: 24 days ago
JSON representation
tiny, powerful dependency injection container for node and browser
- Host: GitHub
- URL: https://github.com/brunocarvalhodearaujo/dotie
- Owner: brunocarvalhodearaujo
- Created: 2016-12-21T11:11:56.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-15T11:18:03.000Z (almost 8 years ago)
- Last Synced: 2024-12-12T09:18:56.562Z (28 days ago)
- Language: JavaScript
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Dotie
=====tiny, powerful dependency injection container for node and browser inspired on angularJS
## Instalation
The installation of this package is very simple: In fact, it can be installed by just running:
````bash
$ npm install dotie # if using NodeJS
$ bower install dotie # if you want to use this package in the browser
````## Reference
### API
````typescript
/**
* create an new dependency into container
* @param {string} name - name of dependency
* @param {any} provider - dependence
* @returns {this}
*/
dotie.register(name, provider) /* or */ dotie. = provider/**
* find and resolve dependencies and return then
* @param {string} name - name of dependency
* @returns {any} - registered provider instance
*/
dotie.resolve(name) /* or */ dotie.
````### Example
````typescript
// small sintax
dotie.q = () => $.Deferred() // dotie. = dependence// default sintax
dotie.register('http', function(q) {
return (...params) => {
$.ajax(...params)
.success(data => q.resolve(data))
.error(error => q.reject(error))
return q.promise()
}
})// using angular injection style (option 1)
dotie.register('user', ['http', http => {
return {
find: code => http(`localhost:2650/api/users/${code}`)
}
}])// angular injection style (option 2)
function controller(model) {
user.find(1)
.then(user => console.log(user))
.catch(error => console.log(error))
}controller.$inject = [ 'user' ]
dotie.register('controller', controller) /* or */ dotie.controller = controller
````