Is it possible to load/add DI.Module dynamically t...
# kodein
z
Is it possible to load/add DI.Module dynamically to the graph(container?)? Let’s say I already have DI instance and I would like to load/add some additional dependencies to it. Before I was using Koin and there is a function on Koin instance to
loadModule/unloadModule
, what’s the Kodein way for it? 🙂
s
Hi @zalewski.se. There are two solutions for that: • You can create a new DI container by extending the previous one. See https://docs.kodein.org/kodein-di/7.1/core/modules-inheritance.html#extension-composition. This is the cleanest approach but limits overriding (you should read carefully the "Overriding" section of the documentation in the above link. Also, the new modules will only appear in the new DI container, not the previous one. • You can use `ConfigurableDI`: have a look at https://docs.kodein.org/kodein-di/7.1/extension/configurable.html#_configurabledi. Note that, unless specifically set, a
ConfigurableKodein
is not mutable after first retrieval. You should read carefully the "Mutating" section of the documentation in the above link.
🙏 1
z
@salomonbrys I see! So with the 1st method it’s all about extending but you can’t really remove it later 🤔. I gotta investigate the 2nd option more but looks somehow dangerous after reading the docs