<@U0NT624JZ> actually it's not really a dependency...
# ktor
@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
kotlin's type but It seems to us it was not so clean to extend it.
If I need to call a function
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.
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
. 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
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.
btw dagger requires calling
method too. at least on android components like activity or fragment
so dagger is service locator ­čžî