How to use the awilix.createContainer 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 ramdesh / node-express-es6-base / src / ConfigIoc.js View on Github external
import CrossOriginMW from './middleware/CrossOriginMW';

// Import controllers
import UserController from './api/user/UserController';

// Import Factories
import ExceptionFactory from './error/ExceptionFactory';

// Import Services
import UserService from './services/UserService';

// Import Repositories
import BaseRepository from './repository/BaseRepository';
import UserRepository from './repository/UserRepository';

let container = awilix.createContainer({
    resolutionMode: awilix.ResolutionMode.CLASSIC
});

mongoose.Promise = global.Promise;
mongoose.connect(config.DB.mongodb.nodebaseapp.connection, { useMongoClient: true });

console.log("Initializing Swagger API documentation...");
let swaggerDefinition = {
    info: {
        title: 'RESTful web services for node/express/es6 starter',
        version: '1.0.0',
        description: 'Documentation for node/express/es6 starter',
    },
    host: 'localhost:3001',
    basePath: '/v1/',
    schemes: ['http'],
github mollyywang / koa2-mongodb-jwt-server / src / lib / container.js View on Github external
export function configureContainer() {
  const opts = {
    injectionMode: InjectionMode.CLASSIC
  }
  return createContainer(opts)
    // load modules and registers 加载,注册模块 e.g. import userService from `services/user-service.js` 
    .loadModules(modulesToLoad, {
      cwd: `${__dirname}/..`,
      formatName: 'camelCase'
    })
    .register({
      // construct logger 
      logger: asValue(logger)
    })
}
github jeffijoe / koa-es7-boilerplate / src / lib / container.js View on Github external
export function configureContainer() {
  const opts = {
    // Classic means Awilix will look at function parameter
    // names rather than passing a Proxy.
    injectionMode: InjectionMode.CLASSIC
  }
  return createContainer(opts)
    .loadModules(modulesToLoad, {
      // `modulesToLoad` paths should be relative
      // to this file's parent directory.
      cwd: `${__dirname}/..`,
      // Example: registers `services/todo-service.js` as `todoService`
      formatName: 'camelCase'
    })
    .register({
      // Our logger is already constructed,
      // so provide it as-is to anyone who wants it.
      logger: asValue(logger)
    })
}
github joshuaalpuerto / node-ddd-boilerplate / src / container.js View on Github external
const { createContainer, asValue, asFunction } = require('awilix')
// you can do this
const app = require('./app')
const server = require('./interfaces/http/server')
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()
  })
github Crizstian / cinema-microservice / booking-service / src / config / di / di.js View on Github external
mediator.on('db.ready', (db) => {
      const container = createContainer()

      container.register({
        database: asValue(db),
        validate: asValue(models.validate),
        booking: asValue(models.booking),
        user: asValue(models.user),
        ticket: asValue(models.ticket),
        ObjectID: asValue(database.ObjectID),
        serverSettings: asValue(serverSettings),
        paymentService: asValue(services.paymentService),
        notificationService: asValue(services.notificationService)
      })

      mediator.emit('di.ready', container)
    })
github Crizstian / cinema-microservice / api-gateway / src / config / di / di.js View on Github external
mediator.once('init', () => {
    const container = createContainer()

    container.register({
      dockerSettings: asValue(dockerSettings),
      serverSettings: asValue(serverSettings)
    })

    mediator.emit('di.ready', container)
  })
}
github openintegrationhub / openintegrationhub / lib / backend-commons-lib / src / App.js View on Github external
_initContainer() {
        this._container = awilix.createContainer();
        this._container.register({
            config: asValue(this._config),
            logger: asValue(this._logger),
            amqp: asClass(AMQPService).singleton(),
            k8s: asClass(K8sService).singleton(),
            amqpConnection: asFunction(() => this._container.resolve('amqp').getConnection())
        });
    }
github dannielhugo / typescript-clean-architecture / src / deliveries / api / app.ts View on Github external
private middleware(): void {
    this.express.use(logger('dev'));
    this.express.use(bodyParser.json());
    this.express.use(bodyParser.urlencoded({ extended: false }));
    this.router = express.Router();
    this.container = createContainer();
    this.container.register({ router: asValue(this.router) });

    this.injectModules();
    this.injectStorage();
    this.injectFiles();
    this.injectExternalLibraries();
    this.injectSchemas();
    this.injectPlugins();

    this.express.use((req: Request, res, next) => {
      req.container = this.container.createScope();

      req.container.register({
        user: asValue(req.user)
      });
      next();
github dannielhugo / typescript-clean-architecture / src / injector.ts View on Github external
constructor() {
    this.container = createContainer();
  }
github Crizstian / cinema-microservice / payment-service / src / api / payment.spec.js View on Github external
describe('Payment API', () => {
  let app = null
  let paid = null

  const serverSettings = {
    port: 3000
  }

  const container = createContainer()

  container.register({
    validate: asValue(models.validate),
    serverSettings: asValue(serverSettings),
    stripe: asValue(stripe(stripeSettings.secret))
  })

  let _testRepo = {
    registerPurchase ({container}, payment) {
      return new Promise((resolve, reject) => {
        container.cradle.stripe.charges.create({
          amount: Math.ceil(payment.amount * 100),
          currency: payment.currency,
          source: {
            number: payment.number,
            cvc: payment.cvc,