<@U0NT624JZ> actually it's not really a dependency...
# ktor
l
@rocketraman actually it's not really a dependency. I guess you're talking about KoinComponent interface ? It's just a maker interface on which we are providing functions extensions. We could have done theses extensions on the
Any
kotlin's type but It seems to us it was not so clean to extend it.
r
If I need to call a function
inject
in my code, then my code has a dependency does it not? This means I can't, for example, test that component, without my test also needing the DI machinery.
2
The approach mentioned by @orangy of an annotation is better because my component is still usable without the DI framework.
l
In fact, Koin has been designed to be as small as possible, with no scan mechanism, no code generation and no compilation required. Its philosophy is : declare statically your context, start it and use DSL to do the injection. It is only for this last step you need to have function extension available on your class to be able to use
inject
. If you are extending Ktor Application functions, it's already available out-of-the-box. If you are developing Android App, it's again already available out-of-the-box inside Activities, Fragments and Services. In the general case, since we can be aware of your code, you have to mark your class with KoinComponent on which we are providing
inject
function extension.
Now about testing, just like Spring development or any context aware framework, you have to initialize your context or mock it to do your tests on context dependent classes. With Koin it's the same. Static declaration of the context, start Koin and do your test.
d
btw dagger requires calling
inject
method too. at least on android components like activity or fragment
so dagger is service locator 🧌