2021-06-03 03:36:25 +00:00
|
|
|
import {Factory} from './Factory'
|
|
|
|
import {Instantiable} from '../types'
|
2021-06-02 01:59:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Container factory that produces an instance of the token, however the token
|
|
|
|
* is identified by a string name rather than a class reference.
|
|
|
|
* @extends Factory
|
|
|
|
*/
|
2021-06-03 03:36:25 +00:00
|
|
|
export default class NamedFactory<T> extends Factory<T> {
|
2021-06-02 01:59:40 +00:00
|
|
|
constructor(
|
|
|
|
/**
|
|
|
|
* The name identifying this factory in the container.
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
protected name: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The token to be instantiated.
|
|
|
|
* @type {Instantiable}
|
|
|
|
*/
|
2021-06-03 03:36:25 +00:00
|
|
|
protected token: Instantiable<T>,
|
2021-06-02 01:59:40 +00:00
|
|
|
) {
|
|
|
|
super(token)
|
|
|
|
}
|
|
|
|
|
2021-06-03 03:36:25 +00:00
|
|
|
match(something: unknown): boolean {
|
2021-06-02 01:59:40 +00:00
|
|
|
return something === this.name
|
|
|
|
}
|
|
|
|
}
|