Skip to content
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

Closed
brookman opened this issue Jun 26, 2023 · 4 comments
Closed

Comments

@brookman
Copy link

brookman commented Jun 26, 2023

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).

@escamoteur
Copy link
Collaborator

escamoteur commented Jul 2, 2023 via email

@brookman
Copy link
Author

Looking at this code it seems like the scopes are already iterated in reverse order upon resetting:
image
(Unless I misunderstand something)

@escamoteur
Copy link
Collaborator

escamoteur commented Jul 10, 2023 via email

@escamoteur
Copy link
Collaborator

was implemented by #350

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants