How to use typedi - 10 common examples

To help you get started, we’ve selected a few typedi 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 vaultage-pm / vaultage / packages / vaultage / src / main.ts View on Github external
async function boot(port: number, addr: string) {
    // Tell routing-controller to use our dependency injection container
    useContainer(Container);

    // Wires all dependencies
    const vaultPath = storagePath(VAULT_FILENAME, program.data);
    Container.set('cipherLocation', vaultPath);

    await loadConfig(true);

    Container.set(DatabaseWithAuth, Container.get(JSONDatabaseWithAuth));

    // Create an express server which is preconfigured to serve the API
    const server = createVaultageAPIServer();

    // Bind static content to server
    const pathToWebCliGUI = path.dirname(require.resolve('vaultage-ui-webcli'));
    const staticDirToServer = path.join(pathToWebCliGUI, 'public');
    server.use(express.static(staticDirToServer));

    // run application on port port
    server.listen(port, addr, () => {
        console.log(`Server is listening on port ${port}`);
github vaultage-pm / vaultage / packages / vaultage / src / main.ts View on Github external
async function boot(port: number, addr: string) {
    // Tell routing-controller to use our dependency injection container
    useContainer(Container);

    // Wires all dependencies
    const vaultPath = storagePath(VAULT_FILENAME, program.data);
    Container.set('cipherLocation', vaultPath);

    await loadConfig(true);

    Container.set(DatabaseWithAuth, Container.get(JSONDatabaseWithAuth));

    // Create an express server which is preconfigured to serve the API
    const server = createVaultageAPIServer();

    // Bind static content to server
    const pathToWebCliGUI = path.dirname(require.resolve('vaultage-ui-webcli'));
    const staticDirToServer = path.join(pathToWebCliGUI, 'public');
    server.use(express.static(staticDirToServer));

    // run application on port port
    server.listen(port, addr, () => {
        console.log(`Server is listening on port ${port}`);
    });
}
github MichalLytek / type-graphql / examples / using-scoped-container / recipe / recipe.samples.ts View on Github external
export function setSamplesInContainer() {
  // add sample recipes to container
  Container.set({
    id: "SAMPLE_RECIPES",
    transient: true, // create a fresh copy for each `get` of samples
    factory: () => {
      console.log("sampleRecipes copy created!");
      return sampleRecipes.slice();
    },
  });
}
github MichalLytek / type-graphql / examples / using-scoped-container / index.ts View on Github external
willSendResponse(requestContext: GraphQLRequestContext) {
            // remember to dispose the scoped container to prevent memory leaks
            Container.reset(requestContext.context.requestId);

            // for developers curiosity purpose, here is the logging of current scoped container instances
            // we can make multiple parallel requests to see in console how this works
            const instancesIds = ((Container as any).instances as ContainerInstance[]).map(
              instance => instance.id,
            );
            console.log("instances left in memory:", instancesIds);
          },
        }),
github rockstat / front / src / StaticData.ts View on Github external
constructor() {
    this.log = Container.get(Logger).for(this);
    const appConfig = Container.get>(AppConfig);
    this.dev = appConfig.env === ENV_DEV;
    this.options = appConfig.static;
    // warmup lib
    for (const [key, fn] of Object.entries(this.options)) {
      this._paths.push(key);
      const raw = this.content[key] = readSync(fn);
      const size = Math.round(raw.length / 1024)
      this.log.info(`Loaded static file: ${key}/${fn} ${size}kb`)
    }
  }
github rockstat / front / src / StaticData.ts View on Github external
constructor() {
    this.log = Container.get(Logger).for(this);
    const appConfig = Container.get>(AppConfig);
    this.dev = appConfig.env === ENV_DEV;
    this.options = appConfig.static;
    // warmup lib
    for (const [key, fn] of Object.entries(this.options)) {
      this._paths.push(key);
      const raw = this.content[key] = readSync(fn);
      const size = Math.round(raw.length / 1024)
      this.log.info(`Loaded static file: ${key}/${fn} ${size}kb`)
    }
  }
github youzan / zan-proxy / src / core / App / services / profile.ts View on Github external
}

const defaultProfile: Profile = {
  // 是否启用host解析
  enableHost: true,
  // 是否启用转发规则
  enableRule: true,
  // 工程路径配置
  projectPath: {},
};
/**
 * 代理运转需要的规则数据
 * 代理端口、超时时间、gitlab token、工程路径、是否启用转发规则
 * Created by tsxuehu on 8/3/17.
 */
@Service()
export class ProfileService extends EventEmitter {
  private userProfileMap: object;
  private clientIpUserMap: object;
  private profileSaveDir: string;
  private clientIpUserMapSaveFile: string;
  constructor(appInfoService: AppInfoService) {
    super();
    // userId -> profile
    this.userProfileMap = {};
    // clientIp -> userId
    this.clientIpUserMap = {};

    const proxyDataDir = appInfoService.getProxyDataDir();
    this.profileSaveDir = path.join(proxyDataDir, 'profile');
    this.clientIpUserMapSaveFile = path.join(proxyDataDir, 'clientIpUserMap.json');
github vaultage-pm / vaultage / packages / vaultage / src / VaultageServer.ts View on Github external
public static bindToServer(expressApp: Application, initialConfig?: VaultageConfig ) {
        if (initialConfig) {
            Container.set('config', initialConfig);
        }
        // registers our routes (present in Cipher/ConfigController) on this express server
        useExpressServer(expressApp, {
            controllers: [
                CipherController,
                ConfigController
            ]
        });
    }
}
github goldcaddy77 / warthog / examples / 07-feature-flags / src / segment / segment.resolver.ts View on Github external
  constructor(@Inject('SegmentService') readonly service: SegmentService) {
    // no-empty
  }
github goldcaddy77 / warthog / examples / 07-feature-flags / src / feature-flag-segment / feature-flag-segment.resolver.ts View on Github external
  constructor(@Inject('FeatureFlagSegmentService') readonly service: FeatureFlagSegmentService) {
    // no-empty
  }