egg-singletons
Version:
Egg plugin for multiple singletons.
68 lines (54 loc) • 1.55 kB
Markdown
[](https://travis-ci.org/kaelzhang/egg-singletons)
[](https://codecov.io/gh/kaelzhang/egg-singletons)
<!-- optional appveyor tst
[](https://ci.appveyor.com/project/kaelzhang/egg-singletons)
-->
<!-- optional npm version
[](http://badge.fury.io/js/err-object)
-->
<!-- optional npm downloads
[](https://www.npmjs.org/package/err-object)
-->
<!-- optional dependency status
[](https://david-dm.org/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