Containers - add ability to purge/release factories; override factories in scoped

This commit is contained in:
2021-06-04 01:03:10 -05:00
parent cd9bec7c5e
commit dab3d006c8
2 changed files with 100 additions and 5 deletions

View File

@@ -47,6 +47,25 @@ export class Container {
this.registerSingleton('injector', this)
}
/**
* Purge all factories and instances of the given key from this container.
* @param key
*/
purge(key: DependencyKey): this {
this.factories = this.factories.filter(x => !x.match(key))
this.release(key)
return this
}
/**
* Remove all stored instances of the given key from this container.
* @param key
*/
release(key: DependencyKey): this {
this.instances = this.instances.filter(x => x.key !== key)
return this
}
/**
* Register a basic instantiable class as a standard Factory with this container.
* @param {Instantiable} dependency