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

ProvisionListeners API for closing injected resources #36

Open
vemana opened this issue Oct 21, 2024 · 0 comments
Open

ProvisionListeners API for closing injected resources #36

vemana opened this issue Oct 21, 2024 · 0 comments

Comments

@vemana
Copy link

vemana commented Oct 21, 2024

Would it be possible to add something like Guice's ProvisionListeners 1?

Context: I use one injector per test. I want to clean up resources used by injected instances after the test completes.

Prior art: I have seen some notions like AutoDispose by other Dart-land injectors but they didn't look appealing to me. I am familar with and use Guice's ProvisionListener API for the same purpose in Java - via a Junit rule that creates the injector, listens to provisions and triggers Closeable.close() upon teardown. This is particularly handy for Singleton instances (like say ConnectionPools) which don't typically expect their close() to be triggered during the application's lifetime, but will need to be closed during tests.

I also did not consider any specific solution just to close resources. A general solution like a ProvisionListener seems easier to maintain than a specific solution that imposes a certain convention on users.

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

1 participant