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
I’ve been struggling to find a way to gracefully shut down my Node.js application after adopting TSyringe, since there appears to be no way to get existing instances without creating a new one.
…if no instances of the (singleton) CassandraClient exists, TSyringe instantiates a new one. Since I’m trying to shut down, that is counter-productive, and leads to problems trying to shut something down that hasn’t really started yet.
Solutions
I don’t really have a preference here, but I imagine one of these could solve the problem:
A container.hasInstances() check that only returns true if a token has been instantiated, not just registered.
A variant of (or parameter to) container.resolveAll() that only returns existing instances, instead of creating new ones.
The text was updated successfully, but these errors were encountered:
@Xapphire13 just instantiating the class starts it. I even tried subclassing the container to try to get at the existing instances without creating new ones, but since everything has private visibility, that’s not an option either :(
Another option would be to make some of the internal methods protected instead, so it would be possible to customise the container.
I’ve been struggling to find a way to gracefully shut down my Node.js application after adopting TSyringe, since there appears to be no way to get existing instances without creating a new one.
Description
For example, I have a database client defined as
and a shutdown function (using the global container) looking like this:
…if no instances of the (singleton) CassandraClient exists, TSyringe instantiates a new one. Since I’m trying to shut down, that is counter-productive, and leads to problems trying to shut something down that hasn’t really started yet.
Solutions
I don’t really have a preference here, but I imagine one of these could solve the problem:
container.hasInstances()
check that only returns true if a token has been instantiated, not just registered.container.resolveAll()
that only returns existing instances, instead of creating new ones.The text was updated successfully, but these errors were encountered: