import Instantiable from '../type/Instantiable.ts' import { DEPENDENCY_KEYS_METADATA_KEY } from '../type/DependencyKey.ts' import { Reflect } from '../../../lib/src/external/reflect.ts' import { Collection } from '../../../lib/src/collection/Collection.ts' import { DependencyRequirement } from '../type/DependencyRequirement.ts' import AbstractFactory from './AbstractFactory.ts' /** * Standard factory that produces injected versions of instantiable classes. * @extends AbstractFactory */ export default class Factory extends AbstractFactory { constructor( protected token: Instantiable ) { super(token) } produce(dependencies: any[], parameters: any[]) { return new this.token(...dependencies, ...parameters) } match(something: any) { return something === this.token || (something.toString && String(something) === this.token.name) } get_dependency_keys(): Collection { const meta = Reflect.getMetadata(DEPENDENCY_KEYS_METADATA_KEY, this.token) if ( meta ) return meta return new Collection() } }