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
Calling container.clearInstances() does not clear instances created by instanceCachingFactory. If this is not a bug, but by design, what is the correct way of achieving this behaviour?
To Reproduce
import"reflect-metadata";import{container}from"tsyringe";functionmain(){container.register('port',{useFactory: instanceCachingFactory(()=>process.env.PORT),})process.env.PORT='1234'assert(container.resolve('port')==='1234')process.env.PORT='5678'// Still resolves to '1234' (OK)assert(container.resolve('port')==='1234')container.clearInstances()// Should run factory again and resolve to '5678'assert(container.resolve('port')==='5678')// Error! It is still resolving to '1234'}main()
Expected behavior
After clearInstances, the instanceCachingFactory should run again - at least this is what I expect since it is what happens with @singleton, registerSingleton and { lifecycle: Lifecycle.Singleton } and the README says that instanceCachingFactory is very similar to singleton.
johan13 has created a good alternative here: #140 (comment)
But shouldn't this be supported by the library?
Version: 4.6.0
The text was updated successfully, but these errors were encountered:
Describe the bug
Calling
container.clearInstances()
does not clear instances created byinstanceCachingFactory
. If this is not a bug, but by design, what is the correct way of achieving this behaviour?To Reproduce
Expected behavior
After
clearInstances
, theinstanceCachingFactory
should run again - at least this is what I expect since it is what happens with@singleton
,registerSingleton
and{ lifecycle: Lifecycle.Singleton }
and the README says thatinstanceCachingFactory
is very similar tosingleton
.johan13 has created a good alternative here: #140 (comment)
But shouldn't this be supported by the library?
Version: 4.6.0
The text was updated successfully, but these errors were encountered: