https://github.com/kaelzhang/egg-singletons
Egg plugin to define multiple singletons in a convenient way.
https://github.com/kaelzhang/egg-singletons
egg egg-plugin eggjs singletons
Last synced: about 2 months ago
JSON representation
Egg plugin to define multiple singletons in a convenient way.
- Host: GitHub
- URL: https://github.com/kaelzhang/egg-singletons
- Owner: kaelzhang
- License: mit
- Created: 2017-12-26T03:40:26.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-12-29T15:14:47.000Z (over 7 years ago)
- Last Synced: 2025-03-25T13:16:15.928Z (2 months ago)
- Topics: egg, egg-plugin, eggjs, singletons
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/kaelzhang/egg-singletons)
[](https://codecov.io/gh/kaelzhang/egg-singletons)# egg-singletons
Egg plugin to define multiple singletons in a convenient way.
## Install
```sh
$ npm install egg-singletons
```## Configurations
config/plugin.js
```js
exports.singletons = {
enable: true,
package: 'egg-singletons'
}
```config/config.default.js
```js
exports.singletons = {
foo: {
// Load into app, default is open
app: true,
// Load into agent, default is close
agent: false,
create: (config, app) => {
return a => {
console.log(a)
}
}
}
}
```Then:
```js
...
async doSomething () {
this.app.foo('hello')
}
...
```## License
MIT