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

RequireBinding? #427

Open
davidsun opened this issue Feb 27, 2021 · 1 comment
Open

RequireBinding? #427

davidsun opened this issue Feb 27, 2021 · 1 comment

Comments

@davidsun
Copy link
Contributor

davidsun commented Feb 27, 2021

https://google.github.io/guice/api-docs/4.2/javadoc/com/google/inject/AbstractModule.html#requireBinding-java.lang.Class- is a very nice feature in Guice. It allows the caller to be notified very early on that DI will fail. What's more helpful is if we can provide an error message such as "binding XXX isn't provided, did you forget to install XXXModule?".

@davidsun
Copy link
Contributor Author

Thinking more about it: one difficulty is when we should do such checks. For Guice, there is an explicit createInjector() call. That's the moment when the bindings can be checked. However, such moment doesn't exist for Toothpick: a developer can continuously add more modules to a scope after some instances are already fetched the scope.

I'm considering performing such checks during the getInstance() call: we maintain a list of unchecked required bindings and fails the injection if a requested binding isn't satisfied.

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