Closed derkalaender closed 2 years ago
Hello, and thanks for opening an issue! As this is the first time you've created an issue on this repository, we'd just like to offer you a warm welcome to the project, and the following pointers:
Please provide as much information as possible when asking a question, reporting a problem, or submitting a feature request. This will help us to address your issue quickly and efficiently. If you forgot to add some information, no worries - feel free to edit the issue and add anything you missed!
Thanks for contacting us! If you have any further questions, please feel free to join us on Discord in the #dev-kotdis
channel (or #kordex-discussion
for Kord Extensions projects), or to contact a staff member directly.
Hello, just getting around to this now!
Do you know if modules can be registered globally before startKoin
is called? I guess the implication here is that they can, but it'd be good to double-check whether getKoin
is safe to use that early.
I'll look into it.
Nope, loadKoinModules()
can't be called before startKoin
- any ideas?
Marking this stale as it hasn't been updated in 5 days.
This hasn't been updated for 10 days, and I'm at a loss as to how this could be implemented. As the reporter seems to have disappeared, I'll be closing this issue now - if you have any further ideas or a proof of concept, please feel free to open another issue or comment on this one.
Description
Creating a Koin module or definition inside of the
beforeKoinSetup
hook, thecreatedAtStart
flag gets ignored, as those modules/definitions do not in fact get instantiated at start. This flag is useful for Database connections for example, which need to be established directly at application start to do migrations etc.This might not be a deal-breaker at first, since you could just instantiate the object yourself (if it doesnt inject anything) and then create a
single
from that. However, things get difficult when that object itself has other dependencies. So you'd either need to use getKoin() manually or create those other dependencies outside of Koin as well, which might get ugly pretty quickly.Versions
Latest Kord Extensions
1.5.0-SNAPSHOT
Code Examples
No log can be seen (only once another object uses MyDatabase). MyDatabase can also not be instantiated externally because of the
inject
Suggestions
Here in setupKoin() the startKoin() is called before running the runBeforeKoinSetup hooks. This might be the culprit, because according to Koin docs, anything flagged with createdAtStart is executed once startKoin is called and at that point, the modules have not been registered yet.