How to use the awilix.listModules function in awilix

To help you get started, we’ve selected a few awilix examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lanvige / koa2-boilerplate / lib / serviceContainer.js View on Github external
export default function getConfiguredContainer () {
  const container = createContainer()

  // register the values
  container.register({ db: asValue(db) })
  container.register({ environment: asValue(environment) })
  container.register({ packagejson: asValue(packagejson) })

  const models = listModules('../app/models/*.js', { cwd: __dirname })
  models.forEach(
    (m) => {
      const target = require(m.path).default
      const name = m.name[0].toUpperCase() + m.name.slice(1)

      if (target.init) {
        container.register({ [name]: asFunction(target.init.bind(target)).singleton() })
      } else {
        container.register({ name, target })
      }
    }
  )

  container.loadModules([
    '../app/services/*.js'
  ], {
github lanvige / koa2-boilerplate / lib / apiContainer.js View on Github external
export default function createApis (router, container) {
  const result = listModules('../app/apis/v1/*.js', { cwd: __dirname })

  result.forEach(
    m => require(m.path).default(router, container)
  )
}
github jeffijoe / koa-es7-boilerplate / src / lib / createApis.js View on Github external
export default function createApis (router) {
  const result = listModules('../api/*.js', { cwd: __dirname })
  result.forEach(
    m => require(m.path).default(router)
  )
}