An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

        

[![Build Status](https://travis-ci.org/kaelzhang/egg-singletons.svg?branch=master)](https://travis-ci.org/kaelzhang/egg-singletons)
[![Coverage](https://codecov.io/gh/kaelzhang/egg-singletons/branch/master/graph/badge.svg)](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