How to use the inversify.AsyncContainerModule function in inversify

To help you get started, we’ve selected a few inversify 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 Emurgo / tangata-manu / src / ioc_config / db.js View on Github external
// @flow
import { AsyncContainerModule, interfaces } from 'inversify'
import pg from 'pg'
import type { PgPoolConfig, Pool } from 'pg'
import config from 'config'


import { DBConnection } from '../interfaces'
import SERVICE_IDENTIFIER from '../constants/identifiers'

const createDb = async (dbSettings: PgPoolConfig): Pool => (new pg.Pool(dbSettings))

const dbModule = new AsyncContainerModule(async (bind: interfaces.Bind) => {
  const dbConn = await createDb(config.get('db'))
  bind(SERVICE_IDENTIFIER.DB_CONNECTION).toConstantValue(dbConn)
})

export default dbModule
github anomalylabs / streams-platform / resources / js / Application.js View on Github external
register = async (Provider) => {
        log('register', {Provider});
        this.events.emit('app:provider:register', Provider);
        let provider = Provider;
        if ( Provider instanceof ServiceProvider === false ) {
            provider = await this.loadProvider(Provider);
        }
        if ( 'register' in provider && Reflect.getMetadata('register', provider) !== true ) {
            Reflect.defineMetadata('register', true, provider);
            await this.loadAsync(new AsyncContainerModule(() => provider.register()));
        }
        this.providers.push(provider);
        this.events.emit('app:provider:registered', provider);
        return this;
    };
github uprtcl / js-uprtcl / packages / micro-orchestrator / src / orchestrator / module-provider.ts View on Github external
async function loadModule(context: interfaces.Context, microModule: MicroModule): Promise {
  if (microModule.submodules) {
    const submodulesPromises = microModule.submodules.map(submoduleConstructor => {
      const submodule = context.container.resolve(submoduleConstructor);
      return loadModule(context, submodule);
    });
    await Promise.all(submodulesPromises);
  }

  if (microModule.onLoad) {
    const containerModule = new AsyncContainerModule((...args) =>
      (microModule as {
        onLoad: (
          context: interfaces.Context,
          bind: interfaces.Bind,
          unbind: interfaces.Unbind,
          isBound: interfaces.IsBound,
          rebind: interfaces.Rebind
        ) => Promise;
      }).onLoad(context, ...args)
    );
    await context.container.loadAsync(containerModule);
  }
}