How to use awilix - 10 common examples

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 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 dannielhugo / typescript-clean-architecture / src / deliveries / api / app.ts View on Github external
private injectStorage(): void {
    // transform something.repo.repository into repoRepository
    const formatter = (name, descriptor) => {
      const splat = name.split('.');
      splat.shift();

      return camelcase(splat.join('.'));
    };

    this.registerModule([
      [`${__dirname}/../../external/repositories/${config.storage}/**/*.js`, { lifetime: Lifetime.SINGLETON }]
    ], formatter);
  }
github ramdesh / node-express-es6-base / src / ConfigIoc.js View on Github external
// 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'],
    consumes: ["application/json"],
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 SelfKeyFoundation / Identity-Wallet / src / main / context.js View on Github external
inventoryService: asClass(InventoryService).singleton(),
		inventorySyncJobHandler: asClass(InventorySyncJobHandler).singleton(),
		marketplaceCountryService: asClass(MarketplaceCountryService).singleton(),
		marketplaceCountrySyncJobHandler: asClass(MarketplaceCountrySyncJobHandler).singleton(),
		taxTreatiesService: asClass(TaxTreatiesService).singleton(),
		taxTreatiesSyncJobHandler: asClass(TaxTreatiesSyncJobHandler).singleton(),
		web3Service: asClass(Web3Service).singleton(),
		walletService: asClass(WalletService).singleton(),
		addressBookService: asClass(AddressBookService).singleton(),
		// TODO: refactor to not use static methods
		CrashReportService: asValue(CrashReportService),
		txHistoryService: asClass(TxHistoryService).singleton(),
		TxHistoryService: asValue(TxHistoryService),
		priceService: asClass(PriceService).singleton(),
		lwsService: asClass(LWSService).singleton(),
		exchangesService: asClass(ExchangesService).singleton(),
		identityService: asClass(IdentityService).singleton(),
		marketplaceService: asClass(MarketplaceService).singleton(),
		paymentService: asClass(PaymentService).singleton(),
		selfkeyService: asClass(SelfkeyService).singleton(),
		rpcHandler: asFunction(cradle => {
			let Handler = RpcHandler(cradle);
			return new Handler();
		}).singleton(),
		stakingService: asClass(StakingService).singleton(),
		tokenService: asClass(TokenService).singleton(),
		walletTokenService: asClass(WalletTokenService).singleton(),
		incorporationsService: asClass(IncorporationsService).singleton(),
		bankAccountsService: asClass(BankAccountsService).singleton(),
		guideSettingsService: asClass(GuideSettingsService).singleton(),
		countryService: asClass(CountryService).singleton(),
		kycApplicationService: asClass(KycApplicationService).singleton(),
github antoinechalifour / memento / src / index.ts View on Github external
configuration.cacheDirectory = cacheDirectory;
    }

    container.register({
      // Constants
      config: asValue(configuration),

      // Use cases
      respondToRequestUseCase: asClass(RespondToRequest),
      clearAllRequestsUseCase: asClass(ClearAllRequests),
      clearRequestUseCase: asClass(ClearRequest),
      refreshRequestUseCase: asClass(RefreshRequest),
      listRequestsUseCase: asClass(ListRequest),
      getRequestDetailsUseCase: asClass(GetRequestDetails),
      setResponseTimeUseCase: asClass(SetResponseTime),
      importCurlUseCase: asClass(ImportCurl),

      // Repositories
      requestRepository: asClass(RequestRepositoryFile),

      // Services
      networkService: asClass(NetworkServiceAxios),
    });
  }
github SelfKeyFoundation / Identity-Wallet / src / main / context.js View on Github external
export const registerMainServices = container => {
	container.register({
		app: asFunction(createApp).singleton(),
		networkService: asClass(NetworkService).singleton(),
		schedulerService: asClass(SchedulerService).singleton(),
		vendorService: asClass(VendorService).singleton(),
		vendorSyncJobHandler: asClass(VendorSyncJobHandler).singleton(),
		inventoryService: asClass(InventoryService).singleton(),
		inventorySyncJobHandler: asClass(InventorySyncJobHandler).singleton(),
		marketplaceCountryService: asClass(MarketplaceCountryService).singleton(),
		marketplaceCountrySyncJobHandler: asClass(MarketplaceCountrySyncJobHandler).singleton(),
		taxTreatiesService: asClass(TaxTreatiesService).singleton(),
		taxTreatiesSyncJobHandler: asClass(TaxTreatiesSyncJobHandler).singleton(),
		web3Service: asClass(Web3Service).singleton(),
		walletService: asClass(WalletService).singleton(),
		addressBookService: asClass(AddressBookService).singleton(),
		// TODO: refactor to not use static methods
		CrashReportService: asValue(CrashReportService),
		txHistoryService: asClass(TxHistoryService).singleton(),
		TxHistoryService: asValue(TxHistoryService),
		priceService: asClass(PriceService).singleton(),
		lwsService: asClass(LWSService).singleton(),
github antoinechalifour / memento / src / index.ts View on Github external
// Use cases
      respondToRequestUseCase: asClass(RespondToRequest),
      clearAllRequestsUseCase: asClass(ClearAllRequests),
      clearRequestUseCase: asClass(ClearRequest),
      refreshRequestUseCase: asClass(RefreshRequest),
      listRequestsUseCase: asClass(ListRequest),
      getRequestDetailsUseCase: asClass(GetRequestDetails),
      setResponseTimeUseCase: asClass(SetResponseTime),
      importCurlUseCase: asClass(ImportCurl),

      // Repositories
      requestRepository: asClass(RequestRepositoryFile),

      // Services
      networkService: asClass(NetworkServiceAxios),
    });
  }
github asyrafduyshart / node-clean-architecture / src / container.js View on Github external
const swaggerMiddleware = require('./interfaces/http/swagger/swaggerMiddleware');

const MongoUsersRepository = require('./infra/repository/user/MongoUsersRepository');

const { User: UserModel } = require('./infra/database/models');

const logger = require('./infra/logging/logger');

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 }),