Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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[]
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),
);
}
}
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
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
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
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
export const ngPackagrDi = () => {
const ng = ReflectiveInjector.resolveAndCreate([
NgPackagr
]).get(NgPackagr);
(ng as NgPackagr).run();
}
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 })
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;
}
}