diff --git a/di/src/global.ts b/di/src/global.ts index 34639bd..e68b2d1 100644 --- a/di/src/global.ts +++ b/di/src/global.ts @@ -2,6 +2,15 @@ import { Container } from './Container.ts' import Instantiable from './type/Instantiable.ts' import { DependencyKey } from './type/DependencyKey.ts' -const container = new Container() -const make = (target: Instantiable|DependencyKey, ...parameters: any[]) => container.make(target, ...parameters) +declare global { + var container: Container + interface Window { container: any } +} + +if ( !window.container ) { + window.container = new Container() +} + +const container = window.container +const make = (target: Instantiable|DependencyKey, ...parameters: any[]) => window.container.make(target, ...parameters) export { container, make }