Egg plugin to define multiple singletons in a convenient way.
$ npm install egg-singletons
config/plugin.js
exports.singletons = {
enable: true,
package: 'egg-singletons'
}
config/config.default.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:
...
async doSomething () {
this.app.foo('hello')
}
...
MIT