import {Container} from './Container' import {TypedDependencyKey} from './types' /** * Base class for Injection-aware classes that automatically * pass along their configured container to instances created * via their `make` method. */ export class InjectionAware { private ci: Container constructor() { this.ci = Container.getContainer() } /** Set the container for this instance. */ public setContainer(ci: Container): this { this.ci = ci return this } /** Get the container for this instance. */ public getContainer(): Container { return this.ci } /** Instantiate a new injectable using the container. */ public make(target: TypedDependencyKey, ...parameters: any[]): T { const inst = this.ci.make(target, ...parameters) if ( inst instanceof InjectionAware ) { inst.setContainer(this.ci) } return inst } }