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.

40 lines
1.1 KiB

import Factory from './Factory.ts'
import {Collection} from '../../../lib/src/collection/Collection.ts'
import {DependencyRequirement} from '../type/DependencyRequirement.ts'
/**
* Container factory which returns its token as its value, without attempting
* to instantiate anything. This is used to register already-produced-singletons
* with the container.
* @extends Factory
*/
export default class SingletonFactory extends Factory {
constructor(
/**
* Instantiated value of this factory.
* @type FunctionConstructor
*/
protected token: FunctionConstructor,
/**
* String name of this singleton identifying it in the container.
* @type string
*/
protected key: string,
) {
super(token)
}
produce(dependencies: any[], parameters: any[]) {
return this.token
}
match(something: any) {
return something === this.key
}
get_dependency_keys(): Collection<DependencyRequirement> {
return new Collection<DependencyRequirement>()
}
}