How to use the awilix.asValue 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 ArkEcosystem / core / packages / core-container / src / registrars / plugin.ts View on Github external
if (!semver.valid(version)) {
            throw new Error(
                // tslint:disable-next-line:max-line-length
                `The plugin "${name}" provided an invalid version "${version}". Please check https://semver.org/ and make sure you follow the spec.`,
            );
        }

        options = this.applyToDefaults(name, defaults, options);
        this.container.register(`pkg.${alias || name}.opts`, asValue(options));

        try {
            plugin = await item.plugin.register(this.container, options);
            this.container.register(
                alias || name,
                asValue({
                    name,
                    version,
                    plugin,
                }),
            );

            this.plugins[name] = options;

            if (item.plugin.deregister) {
                this.deregister.push({ plugin: item.plugin, options });
            }
        } catch (error) {
            if (item.plugin.required) {
                this.container.forceExit(`Failed to load required plugin '${name}'`, error);
            } else {
                this.failedPlugins[name] = error;
github ArkEcosystem / core / packages / core-container / src / registrars / plugin.ts View on Github external
const defaults = item.plugin.defaults || item.plugin.pkg.defaults;
        const alias = item.plugin.alias || item.plugin.pkg.alias;

        if (this.container.has(alias || name)) {
            return;
        }

        if (!semver.valid(version)) {
            throw new Error(
                // tslint:disable-next-line:max-line-length
                `The plugin "${name}" provided an invalid version "${version}". Please check https://semver.org/ and make sure you follow the spec.`,
            );
        }

        options = this.applyToDefaults(name, defaults, options);
        this.container.register(`pkg.${alias || name}.opts`, asValue(options));

        try {
            plugin = await item.plugin.register(this.container, options);
            this.container.register(
                alias || name,
                asValue({
                    name,
                    version,
                    plugin,
                }),
            );

            this.plugins[name] = options;

            if (item.plugin.deregister) {
                this.deregister.push({ plugin: item.plugin, options });
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 vitta-health / attiv / framework / application / middlewares / paginateHandler.ts View on Github external
pageSize: pageSize,
    order: orderBy,
    fields: [],
    includes: request.query.includes,
    includesRequired: includesRequiredFilter,
  };

  Object.keys(request.query).forEach(keys => {
    if (fieldDefaultFilter.indexOf(keys) < 0) {
      queryFilter.fields.push(`${keys}=${request.query[keys]}`);
      queryFilter[keys] = request.query[keys];
    }
  });

  request.container.register({
    paginateParams: asValue(queryFilter),
  });
  return next();
}
github Crizstian / book-store / server / src / api / bookstore.spec.js View on Github external
beforeEach(() => {
    const container = createContainer()

    container.register({
      validate: asValue(models.validate),
      serverSettings: asValue(serverSettings),
      repo: asValue(testRepo),
      categoryRepo: asValue({}),
      publisherRepo: asValue({}),
      authorRepo: asValue({}),
      authRepo: asValue({})
    })

    return server.start(container)
      .then(serv => {
        app = serv
      })
  })
github Crizstian / book-store / server / src / api / author.spec.js View on Github external
beforeEach(() => {
    const container = createContainer()

    container.register({
      validate: asValue(models.validate),
      serverSettings: asValue(serverSettings),
      repo: asValue({}),
      categoryRepo: asValue({}),
      publisherRepo: asValue({}),
      authorRepo: asValue(testRepo),
      authRepo: asValue({})
    })

    return server.start(container)
      .then(serv => {
        app = serv
      })
  })
github SelfKeyFoundation / Identity-Wallet / src / common / context.js View on Github external
export const registerCommonServices = (container, thread) => {
	container.register({
		initialState: asValue(global.state),
		threadName: asValue(thread),
		store: asFunction(({ initialState, threadName }) =>
			configureStore(initialState, threadName)
		).singleton(),
		ethGasStationService: asClass(EthGasStationService).singleton(),
		config: asValue(config)
	});
	return container;
};
github Crizstian / book-store / server / src / api / publisher.spec.js View on Github external
beforeEach(() => {
    const container = createContainer()

    container.register({
      validate: asValue(models.validate),
      serverSettings: asValue(serverSettings),
      repo: asValue({}),
      categoryRepo: asValue({}),
      publisherRepo: asValue(testRepo),
      authorRepo: asValue({}),
      authRepo: asValue({})
    })

    return server.start(container)
      .then(serv => {
        app = serv
      })
  })
github Crizstian / book-store / server / src / api / author.spec.js View on Github external
beforeEach(() => {
    const container = createContainer()

    container.register({
      validate: asValue(models.validate),
      serverSettings: asValue(serverSettings),
      repo: asValue({}),
      categoryRepo: asValue({}),
      publisherRepo: asValue({}),
      authorRepo: asValue(testRepo),
      authRepo: asValue({})
    })

    return server.start(container)
      .then(serv => {
        app = serv
      })
  })
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,
            exp_month: payment.exp_month,
            exp_year: payment.exp_year
          },
          description: payment.description