Open davidsun opened 3 years ago
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.
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?".