How to use typed-inject - 10 common examples

To help you get started, we’ve selected a few typed-inject 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 stryker-mutator / stryker / packages / stryker / src / reporters / ClearTextReporter.ts View on Github external
import chalk from 'chalk';
import { Reporter, MutantResult, MutantStatus, ScoreResult } from 'stryker-api/report';
import { Position, StrykerOptions } from 'stryker-api/core';
import ClearTextScoreTable from './ClearTextScoreTable';
import * as os from 'os';
import { tokens } from 'typed-inject';
import { commonTokens } from 'stryker-api/plugin';
import { Logger } from 'stryker-api/logging';

export default class ClearTextReporter implements Reporter {

  public static inject = tokens(commonTokens.logger, commonTokens.options);
  constructor(private readonly log: Logger, private readonly options: StrykerOptions) {
    this.configConsoleColor();
  }

  private readonly out: NodeJS.WritableStream = process.stdout;

  private writeLine(output?: string) {
    this.out.write(`${output || ''}${os.EOL}`);
  }

  private configConsoleColor() {
    if (!this.options.allowConsoleColors) {
      chalk.level = 0; // All colors disabled
    }
  }
github stryker-mutator / stryker / packages / core / src / reporters / ClearTextReporter.ts View on Github external
import * as os from 'os';

import { Position, StrykerOptions } from '@stryker-mutator/api/core';
import { Logger } from '@stryker-mutator/api/logging';
import { commonTokens } from '@stryker-mutator/api/plugin';
import { MutantResult, MutantStatus, mutationTestReportSchema, Reporter } from '@stryker-mutator/api/report';
import { calculateMetrics } from 'mutation-testing-metrics';
import { tokens } from 'typed-inject';

import chalk = require('chalk');

import ClearTextScoreTable from './ClearTextScoreTable';

export default class ClearTextReporter implements Reporter {
  public static inject = tokens(commonTokens.logger, commonTokens.options);
  constructor(private readonly log: Logger, private readonly options: StrykerOptions) {
    this.configConsoleColor();
  }

  private readonly out: NodeJS.WritableStream = process.stdout;

  private writeLine(output?: string) {
    this.out.write(`${output || ''}${os.EOL}`);
  }

  private configConsoleColor() {
    if (!this.options.allowConsoleColors) {
      chalk.level = 0; // All colors disabled
    }
  }
github stryker-mutator / stryker / packages / test-helpers / src / TestInjector.ts View on Github external
};
  private readonly provideLogger = (): Logger => {
    return this.logger;
  };
  private readonly provideOptions = () => {
    return this.options;
  };
  private readonly provideMutatorDescriptor = () => {
    return this.mutatorDescriptor;
  };

  public pluginResolver: sinon.SinonStubbedInstance;
  public options: StrykerOptions;
  public mutatorDescriptor: MutatorDescriptor;
  public logger: sinon.SinonStubbedInstance;
  public injector: Injector = rootInjector
    .provideValue(commonTokens.getLogger, this.provideLogger)
    .provideFactory(commonTokens.logger, this.provideLogger, Scope.Transient)
    .provideFactory(commonTokens.options, this.provideOptions, Scope.Transient)
    .provideFactory(commonTokens.pluginResolver, this.providePluginResolver, Scope.Transient)
    .provideFactory(commonTokens.mutatorDescriptor, this.provideMutatorDescriptor, Scope.Transient);

  public reset() {
    this.mutatorDescriptor = factory.mutatorDescriptor();
    this.options = factory.strykerOptions();
    this.logger = factory.logger();
    this.pluginResolver = {
      resolve: sinon.stub(),
      resolveAll: sinon.stub()
    };
  }
}
github stryker-mutator / stryker / packages / stryker-test-helpers / src / TestInjector.ts View on Github external
private readonly provideLogger = (): Logger => {
    return this.logger;
  }
  private readonly provideConfig = () => {
    const config = new Config();
    config.set(this.options);
    return config;
  }
  private readonly provideOptions = () => {
    return this.options;
  }

  public pluginResolver: sinon.SinonStubbedInstance;
  public options: StrykerOptions;
  public logger: sinon.SinonStubbedInstance;
  public injector: Injector = rootInjector
    .provideValue(commonTokens.getLogger, this.provideLogger)
    .provideFactory(commonTokens.logger, this.provideLogger, Scope.Transient)
    .provideFactory(commonTokens.options, this.provideOptions, Scope.Transient)
    .provideFactory(commonTokens.config, this.provideConfig, Scope.Transient)
    .provideFactory(commonTokens.pluginResolver, this.providePluginResolver, Scope.Transient);

  public reset() {
    this.options = factory.strykerOptions();
    this.logger = factory.logger();
    this.pluginResolver = {
      resolve: sinon.stub(),
      resolveAll: sinon.stub()
    };
  }
}
github stryker-mutator / stryker / packages / stryker-test-helpers / src / TestInjector.ts View on Github external
config.set(this.options);
    return config;
  }
  private readonly provideOptions = () => {
    return this.options;
  }

  public pluginResolver: sinon.SinonStubbedInstance;
  public options: StrykerOptions;
  public logger: sinon.SinonStubbedInstance;
  public injector: Injector = rootInjector
    .provideValue(commonTokens.getLogger, this.provideLogger)
    .provideFactory(commonTokens.logger, this.provideLogger, Scope.Transient)
    .provideFactory(commonTokens.options, this.provideOptions, Scope.Transient)
    .provideFactory(commonTokens.config, this.provideConfig, Scope.Transient)
    .provideFactory(commonTokens.pluginResolver, this.providePluginResolver, Scope.Transient);

  public reset() {
    this.options = factory.strykerOptions();
    this.logger = factory.logger();
    this.pluginResolver = {
      resolve: sinon.stub(),
      resolveAll: sinon.stub()
    };
  }
}

export const testInjector = new TestInjector();
testInjector.reset();
github stryker-mutator / stryker / packages / stryker-test-helpers / src / TestInjector.ts View on Github external
}
  private readonly provideConfig = () => {
    const config = new Config();
    config.set(this.options);
    return config;
  }
  private readonly provideOptions = () => {
    return this.options;
  }

  public pluginResolver: sinon.SinonStubbedInstance;
  public options: StrykerOptions;
  public logger: sinon.SinonStubbedInstance;
  public injector: Injector = rootInjector
    .provideValue(commonTokens.getLogger, this.provideLogger)
    .provideFactory(commonTokens.logger, this.provideLogger, Scope.Transient)
    .provideFactory(commonTokens.options, this.provideOptions, Scope.Transient)
    .provideFactory(commonTokens.config, this.provideConfig, Scope.Transient)
    .provideFactory(commonTokens.pluginResolver, this.providePluginResolver, Scope.Transient);

  public reset() {
    this.options = factory.strykerOptions();
    this.logger = factory.logger();
    this.pluginResolver = {
      resolve: sinon.stub(),
      resolveAll: sinon.stub()
    };
  }
}

export const testInjector = new TestInjector();
testInjector.reset();
github stryker-mutator / stryker / packages / test-helpers / src / TestInjector.ts View on Github external
return this.logger;
  };
  private readonly provideOptions = () => {
    return this.options;
  };
  private readonly provideMutatorDescriptor = () => {
    return this.mutatorDescriptor;
  };

  public pluginResolver: sinon.SinonStubbedInstance;
  public options: StrykerOptions;
  public mutatorDescriptor: MutatorDescriptor;
  public logger: sinon.SinonStubbedInstance;
  public injector: Injector = rootInjector
    .provideValue(commonTokens.getLogger, this.provideLogger)
    .provideFactory(commonTokens.logger, this.provideLogger, Scope.Transient)
    .provideFactory(commonTokens.options, this.provideOptions, Scope.Transient)
    .provideFactory(commonTokens.pluginResolver, this.providePluginResolver, Scope.Transient)
    .provideFactory(commonTokens.mutatorDescriptor, this.provideMutatorDescriptor, Scope.Transient);

  public reset() {
    this.mutatorDescriptor = factory.mutatorDescriptor();
    this.options = factory.strykerOptions();
    this.logger = factory.logger();
    this.pluginResolver = {
      resolve: sinon.stub(),
      resolveAll: sinon.stub()
    };
  }
}

export const testInjector = new TestInjector();
github stryker-mutator / stryker / packages / test-helpers / src / TestInjector.ts View on Github external
private readonly provideOptions = () => {
    return this.options;
  };
  private readonly provideMutatorDescriptor = () => {
    return this.mutatorDescriptor;
  };

  public pluginResolver: sinon.SinonStubbedInstance;
  public options: StrykerOptions;
  public mutatorDescriptor: MutatorDescriptor;
  public logger: sinon.SinonStubbedInstance;
  public injector: Injector = rootInjector
    .provideValue(commonTokens.getLogger, this.provideLogger)
    .provideFactory(commonTokens.logger, this.provideLogger, Scope.Transient)
    .provideFactory(commonTokens.options, this.provideOptions, Scope.Transient)
    .provideFactory(commonTokens.pluginResolver, this.providePluginResolver, Scope.Transient)
    .provideFactory(commonTokens.mutatorDescriptor, this.provideMutatorDescriptor, Scope.Transient);

  public reset() {
    this.mutatorDescriptor = factory.mutatorDescriptor();
    this.options = factory.strykerOptions();
    this.logger = factory.logger();
    this.pluginResolver = {
      resolve: sinon.stub(),
      resolveAll: sinon.stub()
    };
  }
}

export const testInjector = new TestInjector();
testInjector.reset();
github stryker-mutator / stryker / packages / core / src / config / ConfigEditorApplier.ts View on Github external
import { Config, ConfigEditor } from '@stryker-mutator/api/config';
import { commonTokens, PluginKind, PluginResolver } from '@stryker-mutator/api/plugin';
import { tokens } from 'typed-inject';

import { coreTokens } from '../di';
import { PluginCreator } from '../di/PluginCreator';

/**
 * Class that applies all config editor plugins
 */
export class ConfigEditorApplier implements ConfigEditor {
  public static inject = tokens(commonTokens.pluginResolver, coreTokens.pluginCreatorConfigEditor);

  constructor(private readonly pluginResolver: PluginResolver, private readonly pluginCreator: PluginCreator) {}

  public edit(config: Config): void {
    this.pluginResolver.resolveAll(PluginKind.ConfigEditor).forEach(plugin => {
      const configEditor = this.pluginCreator.create(plugin.name);
      configEditor.edit(config);
    });
  }
}
github stryker-mutator / stryker / packages / stryker / src / config / ConfigEditorApplier.ts View on Github external
import { Config, ConfigEditor } from 'stryker-api/config';
import { tokens } from 'typed-inject';
import { PluginResolver, PluginKind, commonTokens } from 'stryker-api/plugin';
import { PluginCreator } from '../di/PluginCreator';
import { coreTokens } from '../di';

/**
 * Class that applies all config editor plugins
 */
export class ConfigEditorApplier implements ConfigEditor {

  public static inject = tokens(commonTokens.pluginResolver, coreTokens.pluginCreatorConfigEditor);

  constructor(private readonly pluginResolver: PluginResolver,
              private readonly pluginCreator: PluginCreator) { }

  public edit(config: Config): void {
    this.pluginResolver.resolveAll(PluginKind.ConfigEditor).forEach(plugin => {
      const configEditor = this.pluginCreator.create(plugin.name);
      configEditor.edit(config);
    });
  }
}

typed-inject

Type safe dependency injection framework for TypeScript

Apache-2.0
Latest version published 2 years ago

Package Health Score

56 / 100
Full package analysis