import { Container as InversifyContainer , decorate , interfaces } from 'inversify' ; import { generateIdAndAddToCache } from './id.helper' ; import { injectable } from './inject.helper' ; import { Constructor , Id } from './inversify.types' ; function decorateCatchable ( decorator , constructor , parameterIndex ? ) { try { decorate ( decorator , constructor ) ; } catch ( e ) { if ( e . message !== 'Cannot apply @injectable decorator multiple times.' ) { throw e ; } } } /**
 * This class is the wrapper of inversify Container to add more functionalities.
 * The library exports an instance of the class but you can create your own instance
 */ export class Container extends InversifyContainer { public bindTo < T > ( constructor , customId ? ) { const id = generateIdAndAddToCache ( constructor , customId ) ; decorateCatchable ( injectable ( ) , constructor ) ; return super . bind < T > ( id ) . to ( constructor ) ; } public addTransient < T > ( constructor , customId ? ) { const id = generateIdAndAddToCache ( constructor , customId ) ; decorateCatchable ( injectable ( ) , constructor ) ; return super . bind < T > ( id ) . to ( constructor ) . inTransientScope ( ) ; } public addSingleton < T > ( constructor , customId ? ) { const id = generateIdAndAddToCache ( constructor , customId ) ; decorateCatchable ( injectable ( ) , constructor ) ; return super . bind < T > ( id ) . to ( constructor ) . inSingletonScope ( ) ; } public addRequest < T > ( constructor , customId ? ) { const id = generateIdAndAddToCache ( constructor , customId ) ; decorateCatchable ( injectable ( ) , constructor ) ; return super . bind < T > ( id ) . to ( constructor ) . inRequestScope ( ) ; } public get < T > ( serviceIdentifier ) { return super . get < T > ( serviceIdentifier ) ; } } let container ; export function getContainer ( ) { return container ; } export function setContainer ( options ? ) { return ( container = new Container ( options ) ) ; } export function resetContainer ( ) { getContainer ( ) . unbindAll ( ) ; }