parent
f00233d49a
commit
9796a7277e
@ -0,0 +1,42 @@
|
||||
import {Instantiable} from './types'
|
||||
import NamedFactory from './factory/NamedFactory'
|
||||
import {AbstractFactory} from './factory/AbstractFactory'
|
||||
import {Factory} from './factory/Factory'
|
||||
|
||||
export class ContainerBlueprint {
|
||||
private static instance?: ContainerBlueprint
|
||||
|
||||
public static getContainerBlueprint(): ContainerBlueprint {
|
||||
if ( !this.instance ) {
|
||||
this.instance = new ContainerBlueprint()
|
||||
}
|
||||
|
||||
return this.instance
|
||||
}
|
||||
|
||||
protected factories: (() => AbstractFactory<any>)[] = []
|
||||
|
||||
/**
|
||||
* Register a basic instantiable class as a standard Factory with this container,
|
||||
* identified by a string name rather than static class.
|
||||
* @param {string} name - unique name to identify the factory in the container
|
||||
* @param {Instantiable} dependency
|
||||
*/
|
||||
registerNamed(name: string, dependency: Instantiable<any>): this {
|
||||
this.factories.push(() => new NamedFactory(name, dependency))
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a basic instantiable class as a standard Factory with this container.
|
||||
* @param {Instantiable} dependency
|
||||
*/
|
||||
register(dependency: Instantiable<any>): this {
|
||||
this.factories.push(() => new Factory(dependency))
|
||||
return this
|
||||
}
|
||||
|
||||
resolve(): AbstractFactory<any>[] {
|
||||
return this.factories.map(x => x())
|
||||
}
|
||||
}
|
Loading…
Reference in new issue