How to use the awilix.asFunction 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 talyssonoc / node-api-boilerplate / src / container.js View on Github external
.register({
    app: asClass(Application).singleton(),
    server: asClass(Server).singleton()
  })
  .register({
    router: asFunction(router).singleton(),
    logger: asFunction(logger).singleton()
  })
  .register({
    config: asValue(config)
  });

// Middlewares
container
  .register({
    loggerMiddleware: asFunction(loggerMiddleware).singleton()
  })
  .register({
    containerMiddleware: asValue(scopePerRequest(container)),
    errorHandler: asValue(config.production ? errorHandler : devErrorHandler),
    swaggerMiddleware: asValue([swaggerMiddleware])
  });

// Repositories
container.register({
  usersRepository: asClass(SequelizeUsersRepository).singleton()
});

// Database
container.register({
  database: asValue(database),
  UserModel: asValue(UserModel)
github asyrafduyshart / node-clean-architecture / src / container.js View on Github external
const database = require('./infra/mongoose');

const container = createContainer();

container.register({
  // System
  app: asClass(Application, { lifetime: Lifetime.SINGLETON }),
  server: asClass(Server, { lifetime: Lifetime.SINGLETON }),
  
  router: asFunction(router, { lifetime: Lifetime.SINGLETON }),
  logger: asFunction(logger, { lifetime: Lifetime.SINGLETON }),

  config: asValue(config),

  //Middlewares
  loggerMiddleware: asFunction(loggerMiddleware, { lifetime: Lifetime.SINGLETON }),
  containerMiddleware: asValue(scopePerRequest(container)),
  errorHandler: asValue(config.production ? errorHandler : devErrorHandler),
  swaggerMiddleware: asValue(swaggerMiddleware),


  //Repositories
  usersRepository: asClass(MongoUsersRepository, { lifetime: Lifetime.SINGLETON }),

  //Database
  database: asFunction(database),
  UserModel: asValue(UserModel),

  //Operations
  createUser: asClass(CreateUser),
  getAllUsers: asClass(GetAllUsers),
  updateUser: asClass(UpdateUser),
github joshuaalpuerto / node-ddd-boilerplate / src / container.js View on Github external
const router = require('./interfaces/http/router')
const auth = require('./interfaces/http/auth')
const config = require('../config')
const logger = require('./infra/logging/logger')
const database = require('./infra/database')
const jwt = require('./infra/jwt')
const response = require('./infra/support/response')
const date = require('./infra/support/date')
const repository = require('./infra/repositories')

const container = createContainer()

// SYSTEM
container
  .register({
    app: asFunction(app).singleton(),
    server: asFunction(server).singleton(),
    router: asFunction(router).singleton(),
    logger: asFunction(logger).singleton(),
    database: asFunction(database).singleton(),
    auth: asFunction(auth).singleton(),
    jwt: asFunction(jwt).singleton(),
    response: asFunction(response).singleton(),
    date: asFunction(date).singleton(),
    config: asValue(config),
    repository: asFunction(repository).singleton()
  })

module.exports = container
github talyssonoc / node-api-boilerplate / src / container.js View on Github external
const swaggerMiddleware = require('./interfaces/http/swagger/swaggerMiddleware');

const logger = require('./infra/logging/logger');
const SequelizeUsersRepository = require('./infra/user/SequelizeUsersRepository');
const { database, User: UserModel } = require('./infra/database/models');

const container = createContainer();

// System
container
  .register({
    app: asClass(Application).singleton(),
    server: asClass(Server).singleton()
  })
  .register({
    router: asFunction(router).singleton(),
    logger: asFunction(logger).singleton()
  })
  .register({
    config: asValue(config)
  });

// Middlewares
container
  .register({
    loggerMiddleware: asFunction(loggerMiddleware).singleton()
  })
  .register({
    containerMiddleware: asValue(scopePerRequest(container)),
    errorHandler: asValue(config.production ? errorHandler : devErrorHandler),
    swaggerMiddleware: asValue([swaggerMiddleware])
  });
github talyssonoc / node-api-boilerplate / src / container.js View on Github external
const logger = require('./infra/logging/logger');
const SequelizeUsersRepository = require('./infra/user/SequelizeUsersRepository');
const { database, User: UserModel } = require('./infra/database/models');

const container = createContainer();

// System
container
  .register({
    app: asClass(Application).singleton(),
    server: asClass(Server).singleton()
  })
  .register({
    router: asFunction(router).singleton(),
    logger: asFunction(logger).singleton()
  })
  .register({
    config: asValue(config)
  });

// Middlewares
container
  .register({
    loggerMiddleware: asFunction(loggerMiddleware).singleton()
  })
  .register({
    containerMiddleware: asValue(scopePerRequest(container)),
    errorHandler: asValue(config.production ? errorHandler : devErrorHandler),
    swaggerMiddleware: asValue([swaggerMiddleware])
  });
github joshuaalpuerto / node-ddd-boilerplate / src / container.js View on Github external
const database = require('./infra/database')
const jwt = require('./infra/jwt')
const response = require('./infra/support/response')
const date = require('./infra/support/date')
const repository = require('./infra/repositories')

const container = createContainer()

// SYSTEM
container
  .register({
    app: asFunction(app).singleton(),
    server: asFunction(server).singleton(),
    router: asFunction(router).singleton(),
    logger: asFunction(logger).singleton(),
    database: asFunction(database).singleton(),
    auth: asFunction(auth).singleton(),
    jwt: asFunction(jwt).singleton(),
    response: asFunction(response).singleton(),
    date: asFunction(date).singleton(),
    config: asValue(config),
    repository: asFunction(repository).singleton()
  })

module.exports = container
github asyrafduyshart / node-clean-architecture / src / container.js View on Github external
logger: asFunction(logger, { lifetime: Lifetime.SINGLETON }),

  config: asValue(config),

  //Middlewares
  loggerMiddleware: asFunction(loggerMiddleware, { lifetime: Lifetime.SINGLETON }),
  containerMiddleware: asValue(scopePerRequest(container)),
  errorHandler: asValue(config.production ? errorHandler : devErrorHandler),
  swaggerMiddleware: asValue(swaggerMiddleware),


  //Repositories
  usersRepository: asClass(MongoUsersRepository, { lifetime: Lifetime.SINGLETON }),

  //Database
  database: asFunction(database),
  UserModel: asValue(UserModel),

  //Operations
  createUser: asClass(CreateUser),
  getAllUsers: asClass(GetAllUsers),
  updateUser: asClass(UpdateUser),
  getUserByUid: asClass(GetByUid),
  deleteUser: asClass(DeleteUser),

  //Serializer
  userSerializer: asValue(UserSerializer)
});

module.exports = container;
github commander-mvc / commander-mvc / src / lib / register-injectable.ts View on Github external
function getResolver (options: InjectableTableEntry) {
  const provider = options.provider
  if (provider.useConstructor) {
    return asClass(provider.useConstructor, options)
  } else if (provider.useValue) {
    return asValue(provider.useValue)
  } else if (provider.useFactory) {
    return asFunction(provider.useFactory)
  } else {
    throw new Error('useConstructor, useValue, or useFactory must be specified')
  }
}