<@U0BLRBFMM> I'm not a huge fan of this `direct` t...
# kodein
a
@salomonbrys I'm not a huge fan of this
direct
thing, making a bunch of my injection via default constructor parameters really long for no added value.
s
I think Kodein is trying to guides us to provide a
KodeinAware
to our constructors (and maybe making our constructor's classes
KodeinAware
as well). Then you can use
by kodein.instance()
or
by instance()
to define class' properties.
a
Well, our model differs. We use constructor default parameters because it allows or dependencies to be declarative, classes to be used without an injection module, and still have full dependency injection. We only inject two things from inside the class itself and that is logging and typically Jackson which most of our code uses in some place or another. We don't want our dependencies hidden inside the class, we don't want to create a model in ever test case , and we surely don't want long
kodein.direct.instance()
in the middle of everything, including the bindings themselves which now get hit by this. Sure, we can create a new extension function to put this method back on top, .... we'll work around it.
s
@apatrida You can use a
DKodein
in the entire application and never have to use
direct
, simply create the Kodein object as such:
val kodein = Kodein.direct { /* bindings */ }
Or, if you use injection via constructor parameter, I'd encourage you to use this syntax:
val myValue = kodein.newInstance { Whatever(instance(), instance()) }
a
thanks @salomonbrys, I'm less grumpy today so this helps!