How to use the injection-js.ReflectiveInjector.resolveAndCreate 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 Hotell / blogposts / 2018-06 / ts-react-di / src / app / inject.tsx View on Github external
import React, { Component, ReactNode, createContext, PureComponent, ComponentType } from 'react'
import {
  Type,
  ReflectiveInjector,
  Provider as ProviderConfig,
  Injector,
  InjectionToken,
} from 'injection-js'
import { isType, isProvider, isObject } from './guards'

const rootInjector = ReflectiveInjector.resolveAndCreate([])
// let lastInjector: ReflectiveInjector

const Context = createContext(rootInjector)

type ProviderProps = { provide: ProviderConfig[] }
export class Provider extends Component {
  private static debugMode = {
    on: false,
  }
  static enableDebugMode() {
    this.debugMode.on = true
  }
  private static Debug = (props: {
    parentInjector: ReflectiveInjector
    children: ReactNode
    registeredProviders: ProviderConfig[]
github ng-packagr / ng-packagr / src / lib / ng-v5 / packagr.ts View on Github external
public buildAsObservable(): Observable {
    const injector = ReflectiveInjector.resolveAndCreate(this.providers);
    const buildTransformOperator = injector.get(this.buildTransform);

    return observableOf(new BuildGraph()).pipe(
      buildTransformOperator,
      catchError(err => {
        // Report error and re-throw to subscribers
        log.error(err);
        return throwError(err);
      }),
      map(() => undefined),
    );
  }
}
github tomyitav / create-graphql-app / test / commands / service / projects-for-test / project-with-legal-files / src / core / injector.ts View on Github external
import { Injector, ReflectiveInjector } from 'injection-js'
import 'reflect-metadata'
import 'zone.js'
import { AbstractPubsubManager } from '../graphql/subscriptions/Pubsub/AbstractPubsubManager'
import { PubsubManager } from '../graphql/subscriptions/Pubsub/PubsubManager'
import { TrainsService } from '../services/trains/TrainsService'
import { Server } from '../server'
import { AbstractSetting } from './config/AbstractSetting'
import { Setting } from './config/Setting'
import { AbstractLogger } from './logger/AbstractLogger'
import { Logger } from './logger/Logger'

const injector: Injector = ReflectiveInjector.resolveAndCreate([
  { provide: AbstractLogger, useClass: Logger },
  { provide: AbstractSetting, useClass: Setting },
  { provide: AbstractPubsubManager, useClass: PubsubManager },
  Server,
  TrainsService
])

export default injector
github tomyitav / create-graphql-app / test / output / expected / commands / service / project-with-legal-files-inner-dir / src / core / injector.ts View on Github external
import { Injector, ReflectiveInjector } from 'injection-js'
import 'reflect-metadata'
import 'zone.js'
import { AbstractPubsubManager } from '../graphql/subscriptions/Pubsub/AbstractPubsubManager'
import { PubsubManager } from '../graphql/subscriptions/Pubsub/PubsubManager'
import { TrainsService } from '../services/trains/TrainsService'
import { Server } from '../server'
import { AbstractSetting } from './config/AbstractSetting'
import { Setting } from './config/Setting'
import { AbstractLogger } from './logger/AbstractLogger'
import { Logger } from './logger/Logger'
import { CarService } from '@src/services/inner/dir/car'

const injector: Injector = ReflectiveInjector.resolveAndCreate([
  CarService,
  { provide: AbstractLogger, useClass: Logger },
  { provide: AbstractSetting, useClass: Setting },
  { provide: AbstractPubsubManager, useClass: PubsubManager },
  Server,
  TrainsService
])

export default injector
github tomyitav / create-graphql-app / test / output / expected / commands / service / project-with-legal-files-ignore-context / src / core / injector.ts View on Github external
import {Injector, ReflectiveInjector} from 'injection-js'
import 'reflect-metadata'
import 'zone.js'
import {AbstractPubsubManager} from '../graphql/subscriptions/Pubsub/AbstractPubsubManager'
import {PubsubManager} from '../graphql/subscriptions/Pubsub/PubsubManager'
import {TrainsService} from '../services/trains/TrainsService'
import {Server} from '../server'
import {AbstractSetting} from './config/AbstractSetting'
import {Setting} from './config/Setting'
import {AbstractLogger} from './logger/AbstractLogger'
import {Logger} from './logger/Logger'
import {CarService} from '@src/services/car'

const injector: Injector = ReflectiveInjector.resolveAndCreate([
  CarService,
  {provide: AbstractLogger, useClass: Logger},
  {provide: AbstractSetting, useClass: Setting},
  {provide: AbstractPubsubManager, useClass: PubsubManager},
  Server,
  TrainsService
])

export default injector
github tomyitav / create-graphql-app / test / output / expected / commands / service / project-with-legal-files / src / core / injector.ts View on Github external
import {Injector, ReflectiveInjector} from 'injection-js'
import 'reflect-metadata'
import 'zone.js'
import {AbstractPubsubManager} from '../graphql/subscriptions/Pubsub/AbstractPubsubManager'
import {PubsubManager} from '../graphql/subscriptions/Pubsub/PubsubManager'
import {TrainsService} from '../services/trains/TrainsService'
import {Server} from '../server'
import {AbstractSetting} from './config/AbstractSetting'
import {Setting} from './config/Setting'
import {AbstractLogger} from './logger/AbstractLogger'
import {Logger} from './logger/Logger'
import { CarService } from '@src/services/car'

const injector: Injector = ReflectiveInjector.resolveAndCreate([
  CarService,
  {provide: AbstractLogger, useClass: Logger},
  {provide: AbstractSetting, useClass: Setting},
  {provide: AbstractPubsubManager, useClass: PubsubManager},
  Server,
  TrainsService
])

export default injector
github ng-packagr / ng-packagr / src / lib / ng-v5-packagr.ts View on Github external
export const ngPackagrDi = () => {
  const ng = ReflectiveInjector.resolveAndCreate([
    NgPackagr
  ]).get(NgPackagr);

  (ng as NgPackagr).run();
}
github Hotell / rea-di / src / services / injector-context.ts View on Github external
import { ReflectiveInjector } from 'injection-js'
import { createContext } from 'react'

export type ContextApi = {
  injector: ReflectiveInjector
  [providerName: string]: any
}

export const rootInjector = ReflectiveInjector.resolveAndCreate([])

export const Context = createContext({ injector: rootInjector })
github bougarfaoui / back / container.ts View on Github external
tokenName = token;
        }

        if (Container.instances[tokenName]) {
            return Container.instances[tokenName];
        }

        let component = Container.components[tokenName];

        if (component) {
            let _components = Object.keys(Container.components)
                                    .map(function(key){
                                        return Container.components[key];
                                    });

            const injector = ReflectiveInjector.resolveAndCreate(_components);
            return this.instances[tokenName] = injector.get(component);
        }

        return undefined;
    }
}