How to use the injection-js.InjectionToken function in injection-js

To help you get started, we’ve selected a few injection-js 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 ng-packagr / ng-packagr / src / lib / steps / entry-point-transforms.ts View on Github external
log.info('Writing package metadata');
    const relativeDestPath: string = path.relative(entryPoint.destinationPath, pkg.primary.destinationPath);
    await writePackage(entryPoint, {
      main: ensureUnixPath(path.join(relativeDestPath, 'bundles', entryPoint.flatModuleFile + '.umd.js')),
      module: ensureUnixPath(path.join(relativeDestPath, 'esm5', entryPoint.flatModuleFile + '.js')),
      es2015: ensureUnixPath(path.join(relativeDestPath, 'esm2015', entryPoint.flatModuleFile + '.js')),
      typings: ensureUnixPath(`${entryPoint.flatModuleFile}.d.ts`),
      // XX 'metadata' property in 'package.json' is non-standard. Keep it anyway?
      metadata: ensureUnixPath(`${entryPoint.flatModuleFile}.metadata.json`)
    });

    log.success(`Built ${entryPoint.moduleId}`);
  };
}

export const ENTRY_POINT_TRANSFORMS_TOKEN = new InjectionToken('ng.v5.entryPointTransforms');

export const ENTRY_POINT_TRANSFORMS_PROVIDER: FactoryProvider = {
  provide: ENTRY_POINT_TRANSFORMS_TOKEN,
  useFactory: transformSourcesFactory,
  deps: [INIT_TS_CONFIG_TOKEN]
};
github Hotell / rea-di / examples / counter-with-multiple-injectors / src / app / multiply-counter.service.ts View on Github external
import { Inject, Injectable, InjectionToken, Optional } from 'injection-js'

import { CounterService } from './counter.service'
import { getClassName } from './helpers'
import { Logger } from './logger.service'

const defaultConfig = {
  multiplyBy: 2,
}
export type MultiplyCounterConfig = typeof defaultConfig
export const MultiplyCounterConfig = new InjectionToken(
  'MultiplyCounterConfig'
)

@Injectable()
export class MultiplyCounterService extends CounterService {
  constructor(
    @Optional()
    @Inject(MultiplyCounterConfig)
    private config: MultiplyCounterConfig,
    public logger: Logger
  ) {
    super(logger)
    this.config = config || defaultConfig
  }
  onIncrement() {
    this.setState((prevState) => {
github rxstack / rxstack / packages / security / src / security.module.ts View on Github external
import {TokenExtractorListener} from './event-listeners/token-extractor-listener';
import {AuthenticationTokenListener} from './event-listeners/authentication-token-listener';
import {InMemoryRefreshTokenManager} from './services/in-memory.refresh-token.manager';
import { BootstrapListener } from './event-listeners/bootstrap-listener';
import {SecurityController} from './controllers/security-controller';
import {AsyncEventDispatcher} from '@rxstack/async-event-dispatcher';
import {TokenAuthenticationProvider} from './authentication/token.authentication-provider';
import {ConnectionListener} from './event-listeners/connection-listener';
import {AbstractRefreshTokenManager, KeyLoader, TokenManager} from './services';
import {PlainTextPasswordEncoder} from './password-encoders';

export const AUTH_PROVIDER_REGISTRY = new InjectionToken('AUTH_PROVIDER_REGISTRY');
export const USER_PROVIDER_REGISTRY = new InjectionToken('USER_PROVIDER_REGISTRY');
export const PASSWORD_ENCODER_REGISTRY = new InjectionToken('PASSWORD_ENCODER_REGISTRY');
export const TOKEN_EXTRACTOR_REGISTRY = new InjectionToken('TOKEN_EXTRACTOR_REGISTRY');
export const TOKEN_MANAGER = new InjectionToken('TOKEN_MANAGER');
export const REFRESH_TOKEN_MANAGER = new InjectionToken('REFRESH_TOKEN_MANAGER');

@Module()
export class SecurityModule {
  static configure(configuration: SecurityConfiguration): ModuleWithProviders {
    return {
      module: SecurityModule,
      providers: [
        {
          provide: SecurityConfiguration,
          useFactory: () => new SecurityConfiguration(configuration),
          deps: []
        },
        ...this.addCommonProviders(),
        ...this.addEncoderRelatedProviders(),
        ...this.addLocalAuthenticationProviders(),
github mflorence99 / serverx-ts / src / middlewares / compressor.ts View on Github external
export enum CompressorStrategy {
  FILTERED = 1,
  HUFFMAN_ONLY = 2,
  RLE = 3,
  FIXED = 4,
  DEFAULT_STRATEGY = 0
}

export interface CompressorOpts {
  level?: CompressorLevel;
  methods?: Method[];
  strategy?: CompressorStrategy;
  threshold?: number;
}

export const COMPRESSOR_OPTS = new InjectionToken('COMPRESSOR_OPTS');

export const COMPRESSOR_DEFAULT_OPTS: CompressorOpts = {
  level: CompressorLevel.DEFAULT_COMPRESSION,
  methods: ALL_METHODS,
  strategy: CompressorStrategy.DEFAULT_STRATEGY,
  threshold: 1024
};

/**
 * Request logger
 */

@Injectable() export class Compressor extends Middleware {

  private opts: CompressorOpts;
github rxstack / rxstack / packages / security / src / security.module.ts View on Github external
import {UserPasswordAuthenticationProvider} from './authentication/user-password.authentication-provider';
import {TokenExtractorManager} from './token-extractors/token-extractor-manager';
import {QueryParameterTokenExtractor} from './token-extractors/query-parameter-token-extractor';
import {HeaderTokenExtractor} from './token-extractors/header-token-extractor';
import {TokenExtractorListener} from './event-listeners/token-extractor-listener';
import {AuthenticationTokenListener} from './event-listeners/authentication-token-listener';
import {InMemoryRefreshTokenManager} from './services/in-memory.refresh-token.manager';
import { BootstrapListener } from './event-listeners/bootstrap-listener';
import {SecurityController} from './controllers/security-controller';
import {AsyncEventDispatcher} from '@rxstack/async-event-dispatcher';
import {TokenAuthenticationProvider} from './authentication/token.authentication-provider';
import {ConnectionListener} from './event-listeners/connection-listener';
import {AbstractRefreshTokenManager, KeyLoader, TokenManager} from './services';
import {PlainTextPasswordEncoder} from './password-encoders';

export const AUTH_PROVIDER_REGISTRY = new InjectionToken('AUTH_PROVIDER_REGISTRY');
export const USER_PROVIDER_REGISTRY = new InjectionToken('USER_PROVIDER_REGISTRY');
export const PASSWORD_ENCODER_REGISTRY = new InjectionToken('PASSWORD_ENCODER_REGISTRY');
export const TOKEN_EXTRACTOR_REGISTRY = new InjectionToken('TOKEN_EXTRACTOR_REGISTRY');
export const TOKEN_MANAGER = new InjectionToken('TOKEN_MANAGER');
export const REFRESH_TOKEN_MANAGER = new InjectionToken('REFRESH_TOKEN_MANAGER');

@Module()
export class SecurityModule {
  static configure(configuration: SecurityConfiguration): ModuleWithProviders {
    return {
      module: SecurityModule,
      providers: [
        {
          provide: SecurityConfiguration,
          useFactory: () => new SecurityConfiguration(configuration),
          deps: []
github ng-packagr / ng-packagr / src / lib / ng-v5 / project.di.ts View on Github external
import { InjectionToken, ValueProvider } from 'injection-js';

export const PROJECT_TOKEN = new InjectionToken(`ng.v5.project`);

export const provideProject = (project: string): ValueProvider => ({
  provide: PROJECT_TOKEN,
  useValue: project,
});
github ng-packagr / ng-packagr / src / lib / ng-v5 / entry-point / write-bundles.di.ts View on Github external
import { InjectionToken } from 'injection-js';
import { Transform } from '../../brocc/transform';
import { TransformProvider, provideTransform } from '../../brocc/transform.di';
import { writeBundlesTransform } from './write-bundles.transform';

export const WRITE_BUNDLES_TRANSFORM_TOKEN = new InjectionToken(`ng.v5.writeBundlesTransform`);

export const WRITE_BUNDLES_TRANSFORM: TransformProvider = provideTransform({
  provide: WRITE_BUNDLES_TRANSFORM_TOKEN,
  useFactory: () => writeBundlesTransform,
});
github ng-packagr / ng-packagr / src / lib / ng-v5 / entry-point / resources / template.di.ts View on Github external
import { InjectionToken } from 'injection-js';
import { Transform } from '../../../brocc/transform';
import { TransformProvider, provideTransform } from '../../../brocc/transform.di';
import { templateTransform } from './template.transform';

export const TEMPLATE_TRANSFORM_TOKEN = new InjectionToken(`ng.v5.templateTransform`);

export const TEMPLATE_TRANSFORM: TransformProvider = provideTransform({
  provide: TEMPLATE_TRANSFORM_TOKEN,
  useFactory: () => templateTransform
});
github ng-packagr / ng-packagr / src / lib / ng-v5 / init / init-tsconfig.di.ts View on Github external
export const provideTsConfig = (values?: ParsedConfiguration | string): Provider => {
  return {
    provide: DEFAULT_TS_CONFIG_TOKEN,
    useFactory: () => {
      return createDefaultTsConfig(values);
    },
    deps: [],
  };
};

export const DEFAULT_TS_CONFIG_TOKEN = new InjectionToken('ng.v5.defaultTsConfig');

export const DEFAULT_TS_CONFIG_PROVIDER: Provider = provideTsConfig();

export const INIT_TS_CONFIG_TOKEN = new InjectionToken('ng.v5.initTsConfigTransform');

export const INIT_TS_CONFIG_TRANSFORM: TransformProvider = provideTransform({
  provide: INIT_TS_CONFIG_TOKEN,
  useFactory: initTsConfigTransformFactory,
  deps: [DEFAULT_TS_CONFIG_TOKEN],
});
github ng-packagr / ng-packagr / src / lib / ng-v5 / entry-point / ts / transform-sources.di.ts View on Github external
import { InjectionToken } from 'injection-js';
import { Transform } from '../../../brocc/transform';
import { TransformProvider, provideTransform } from '../../../brocc/transform.di';
import { transformSourcesTransform } from './transform-sources.transform';

export const TRANSFORM_SOURCES_TOKEN = new InjectionToken(`ng.v5.transformSourcesTransform`);

export const TRANSFORM_SOURCES_TRANSFORM: TransformProvider = provideTransform({
  provide: TRANSFORM_SOURCES_TOKEN,
  useFactory: () => transformSourcesTransform
});