-
-
Notifications
You must be signed in to change notification settings - Fork 734
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
Module.verify() failing due to overloaded constructor #2029
Comments
I have a similar problem, I try to run verifyAll() on all my app modules.
And it fails on missing definition, and the missing definition is : io.ktor.client.engine.HttpClientEngine This is because I use Ktor client, and I am providing the definition of the HttpClient throughout the app, which is constructed like so:
So the HttpClient is constructed and provided when I run the app. But verifyAll complains on missing io.ktor.client.engine.HttpClientEngine which is a dependency of HttpClient constructor which I never call, because the HttpClient is constructed through Ktor DSL. The code from Ktor library So during verify koin somehow tries to invoke this constructor for some reason and I get a failure on missing definition. koin: 4.0.0 I know this versions do not fully work together, but for me it otherwise works. |
The problem of the design of this current tool is to inventory about type's constructor to check. Here we don't have data on a potential constructor you don't want to be checked. |
Thanks @arnaudgiuliani for the response. I'm sure there is a lot of hidden complexity here.. Ideally I would like a lightweight solution to ensure that DI for my application is runtime-safe with minimal boilerplate. Would it be technically feasible to add a method that looks at each bound key in a list of modules and attempts to resolve each of them as if it was resolving them at runtime? something like verifyBoundKeys(moduleA, moduleB) It just needs to install the modules and attempt to inject all top-level bound keys. |
it was what was doing CheckModules, trying to sandbox the modules and run them. But it requires to cover all side effect of dynamic behavior. Verify tries to go over static types, but then here we lack of support for dynamic behavior thing 🤔 |
The idea of using constructors at all for this kind of check is inherently flawed. Since the declaration of components through Below are some examples of component declarations where relying on constructors might either cause // DepB is explicitly created, not requested through get()
factory { DepA(DepB()) }
// DepC is created using a (static) factory method
factory { DepC.createInstance(get()) }
// DepD is created using a builder
factory {
DepD.Builder()
.depB(get())
.create()
}
// DepE is an interface and has no constructor.
factory<DepE> { DepA(get()) } |
sure, this is why we are iterating over the design to try find best compromise. Ideas are welcome 👍 |
Describe the bug
I'm trying to use the Module.verify() method to validate a module, but it seems to fail if a constructor is overloaded (even if it never has to invoke the constructor because I'm passing an instance of it myself).
To Reproduce
Here's a full simplified example with comments on the code:
Expected behavior
verify()
should pass. I am initializing the bound instance ofDog
myself, soDog
's constructors should not be relevant to the DI graph.I see that #1538 recommends using
checkModules()
, but that is now deprecated. Is there a different "recommended" way to bind instances or test modules that I should be using?Koin module and version:
The text was updated successfully, but these errors were encountered: