You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Disposing container does not dispose singleton resolved from child container.
See reproduction for details:
To Reproduce
import"reflect-metadata";import{container,Disposable,injectable,Lifecycle,scoped,singleton,}from"tsyringe";
@singleton()
@injectable()classFooimplementsDisposable{constructor(){console.log("making foo!");}dispose(): void|Promise<void>{console.log("disposing foo!");}}
@scoped(Lifecycle.ContainerScoped)
@injectable()classBar{constructor(privatereadonlyfoo: Foo){console.log("making bar!");}}constchildA=container.createChildContainer();constchildB=container.createChildContainer();/** * making foo! * making bar! * making bar! */childA.resolve(Bar);childB.resolve(Bar);/** * no output, container already has a Foo */container.resolve(Foo);/** * no output, is not disposing of Foo... */awaitcontainer.dispose();/** * disposing foo! */awaitchildA.dispose();
Expected behavior
I expect singletons to always execute their dispose function even when calling dispose on a container which wasn't used when they where first resolved.
i.e. I expect the same behavior of first resolving the singleton from the root container and then resolving it from child containers:
import{container,Disposable,injectable,Lifecycle,scoped,singleton,}from"tsyringe";
@singleton()
@injectable()classFooimplementsDisposable{constructor(){console.log("making foo!");}dispose(): void|Promise<void>{console.log("disposing foo!");}}
@scoped(Lifecycle.ContainerScoped)
@injectable()classBar{constructor(privatereadonlyfoo: Foo){console.log("making bar!");}}/** * making foo! */container.resolve(Foo);constchildA=container.createChildContainer();constchildB=container.createChildContainer();/** * making bar! * making bar! */childA.resolve(Bar);childB.resolve(Bar);/** * disposing foo! */awaitcontainer.dispose();
Version: 4.8.0
The text was updated successfully, but these errors were encountered:
Describe the bug
Disposing container does not dispose singleton resolved from child container.
See reproduction for details:
To Reproduce
Expected behavior
I expect singletons to always execute their dispose function even when calling
dispose
on a container which wasn't used when they where first resolved.i.e. I expect the same behavior of first resolving the singleton from the root container and then resolving it from child containers:
Version: 4.8.0
The text was updated successfully, but these errors were encountered: