<@U0BLRBFMM> Can one imported `Kodein.Module` acce...
# kodein
d
@salomonbrys Can one imported
Kodein.Module
access the bindings in another imported module, or only the importing
Kodein
has access to all the module's bindings? If the latter then a module will have to be a
fun
that accepts all dependencies needed from other modules, or does it also have to import the module to use it...?
s
@dave08 Modules aren't segmented, Kodein instances are. This means that 2 modules can access each other's bindings as long as they are imported in the same Kodein (careful:
extend
works differently than
import
).
d
Thanks, I guess that means that if I want to seperate the layers of my application, I need to use
extend
, whereas to create re-usable modules, it's
import
. Although, I think it would have been nice to have some kind of
bindInternal
or
bind(internal=true)
to avoid pollution of the global dependency map in the
Kodein
instance, some deps are only needed in their respective module...
Am I right? Also, what do you think of the idea @salomonbrys?
s
If you really want to separate layers, you need to
extend(parent, copy = Copy.None)
. I understand the need for
bindInternal
but it is not possible in the current modeling. Module instances have no state (Kodein instances do). A
Kodein.Module
is a glorified function that will declare its bindings to each importing Kodein builder, the binding tree is associated to a Kodein instance, not a Module.
👍🏼 1
d
Thanks alot for answering! That might be important to mention in the docs, I think it's common to use DI's to seperate layers... also is there alot of extra overhead of having a Kodein instance for each layer @salomonbrys?
s
No, there's little to no overhead. You should read this section of the doc: http://kodein.org/Kodein-DI/?5.0/core#_overridden_access_from_parent
d
A bit complex, and not really oriented to my use case.. overriding might be more for unit testing... wouldn't it be better to have an easier, more understandable shortcut for this usecase? Or at least another section in the documentation using current functionality?