UNPKG

ts-ioc-container

Version:

Fast, lightweight TypeScript dependency injection container with a clean API, scoped lifecycles, decorators, tokens, hooks, lazy injection, customizable providers, and no global container objects.

15 lines (14 loc) 485 B
import { Injector } from './IInjector'; export class ProxyInjector extends Injector { createInstance(scope, Target, { args = [] } = {}) { const proxy = new Proxy({}, { get(target, prop) { if (prop === 'args') { return args; } return prop.toString().search(/alias/gi) >= 0 ? scope.resolveByAlias(prop) : scope.resolve(prop); }, }); return new Target(proxy); } }