You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

32 lines
1.1 KiB

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<any>
) {
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<DependencyRequirement> {
const meta = Reflect.getMetadata(DEPENDENCY_KEYS_METADATA_KEY, this.token)
if ( meta ) return meta
return new Collection<DependencyRequirement>()
}
}