How to use the awilix.Lifetime.SCOPED 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 inkubux / MediaSpeed / src / lib / container.js View on Github external
import basicStreamer from './streamer/basic-streamer';
import ffmpegStreamer from './streamer/ffmpeg-streamer';
import ffmpegHlsStreamer from './streamer/ffmpeg-hls-streamer';
import ffmpeDashStreamer from './streamer/ffmpeg-dash-streamer';
import hlsPresetDecision from './streamer/hls/hls-preset-decision';
import M3u8Generator from './streamer/m3u8-generator';
import fsExtra from 'fs-extra';
import path from 'path';
import throttledQueue from 'throttled-queue';

/**
 * Using Awilix, the following files and folders (glob patterns)
 * will be loaded.
 */
const modulesToLoad = [
    ['services/*.js', Lifetime.SCOPED],
    ['lib/extended-info-providers/*-provider.js', Lifetime.SINGLETON],
    ['stores/*.js', Lifetime.SINGLETON]
];

/**
 * Configures a new container.
 *
 * @return {Object} The container.
 */
export async function configureContainer() {
    const opts = {
        resolutionMode: ResolutionMode.CLASSIC
    };

    // @todo create a bootstrap sequence
    const dataFolder = process.env.DATA_FOLDER || path.join(process.env.HOME, '.media_speed');
github jeffijoe / koa-es7-boilerplate / src / lib / container.js View on Github external
import { createContainer, Lifetime, InjectionMode, asValue } from 'awilix'
import { logger } from './logger'

/**
 * Using Awilix, the following files and folders (glob patterns)
 * will be loaded.
 */
const modulesToLoad = [
  // Services should be scoped to the request.
  // This means that each request gets a separate instance
  // of a service.
  ['services/*.js', Lifetime.SCOPED],
  // Stores will be singleton (1 instance per process).
  // This is just for demo purposes, you can do whatever you want.
  ['stores/*.js', Lifetime.SINGLETON]
]

/**
 * Configures a new container.
 *
 * @return {Object} The container.
 */
export function configureContainer() {
  const opts = {
    // Classic means Awilix will look at function parameter
    // names rather than passing a Proxy.
    injectionMode: InjectionMode.CLASSIC
  }
github mollyywang / koa2-mongodb-jwt-server / src / lib / container.js View on Github external
import { createContainer, Lifetime, InjectionMode, asValue } from 'awilix'
import { logger } from './logger'

/**
 * Configures a new container 配置容器 
 *
 * @return {Object} The container.
 */

const modulesToLoad = [
  ['services/*.js', Lifetime.SCOPED],
  ['stores/*.js', Lifetime.SINGLETON]
]

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 dannielhugo / typescript-clean-architecture / src / deliveries / api / app.ts View on Github external
private injectPlugins(): void {
    this.registerModule([
      [`${__dirname}/plugins/**/*.js`, { lifetime: Lifetime.SCOPED }]
    ]);
  }