-
-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getIt.reset() should dispose Singletons in reverse registration order #334
Comments
I wonder if that could also be important for resetting Scopes.
To store the registration order of all objects should be possible with an extra list
Thomas
Am 26. Juni 2023, 22:01 +0200 schrieb Beni Bachmann ***@***.***>:
… We are using get_it together with injectable to initialize a graph (DAG) of Singletons in our app. Injectable makes sure that the "parent" Singletons are initialized before its dependents.
Coming from other dependency injection frameworks/containers; when calling getIt.reset() upon shutting down the app I would expect the dispose process to work in reverse order. Starting at the "leaves" and continue with the parent dependencies so that a dependency is never disposed as long as there are others depending upon it. This would make it straight forward to dispose resources, like disconnecting from a socket.
Currently the order seems to be the same as how the Singletons are registered. I have tried both implementing Disposable and using the @disposeMethod annotation which automatically generates a dispose call-back.
Am I missing something?
After taking a look at the code, it seems like flipping the order how allFactories is iterated in _Scope.reset() might just do the trick - assuming Dart Maps keep their values ordered by insertion (which not be the case).
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Yeah, you are right, scopes are. I probably need to add another list to scopes to save the registration order
Am 10. Juli 2023, 11:32 +0200 schrieb Beni Bachmann ***@***.***>:
… Looking at this code it seems like the scopes are already iterated in reverse order upon resetting:
(Unless I misunderstand something)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
was implemented by #350 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We are using get_it together with injectable to initialize a graph (DAG) of Singletons in our app. Injectable makes sure that the "parent" Singletons are initialized before its dependents.
Coming from other dependency injection frameworks/containers; when calling getIt.reset() upon shutting down the app I would expect the dispose process to work in reverse order. Starting at the "leaves" and continue with the parent dependencies so that a dependency is never disposed as long as there are others depending upon it. This would make it straight forward to dispose resources, like disconnecting from a socket.
Currently the order seems to be the same as how the Singletons were registered. I have tried both implementing Disposable and using the
@disposeMethod
annotation which automatically generates a dispose call-back.Am I missing something?
After taking a look at the code, it seems like flipping the order how allFactories is iterated in _Scope.reset() might just do the trick - assuming Dart Maps keep their values ordered by insertion (which might not be the case).
The text was updated successfully, but these errors were encountered: