import { Container , interfaces } from 'inversify' ; import { IDisposable } from '../util/types' ; import { ILogger } from '../logger' ; export interface IDisposableContainer extends interfaces . Container , IDisposable { } export default class DisposableContainer extends Container implements IDisposableContainer { private readonly disposables : IDisposable [ ] = [ ] ; constructor ( readonly name , options ? ) { super ( options ) ; } trackDisposableBinding = < T extends IDisposable > ( _context , injectable ) : T => { this . disposables . push ( injectable ) ; return injectable ; } ; dispose ( ) { this . get < ILogger > ( ILogger ) . info ( 'IoC' , `Dispose IoC Container "${ this . name }"` ) ; for ( const disposable of this . disposables ) { disposable . dispose ( ) ; } this . unbindAll ( ) ; } }