Hi, is it possible to get factory pattern with Kto...
# ktor
l
Hi, is it possible to get factory pattern with Ktor DI?
b
It's generally made for singletons only, but you can use factory instances or lambdas like:
Copy code
dependencies {
    provide<() -> GreetingService> { ::GreetingServiceImpl }
}

val service: () -> GreetingService = dependencies.resolve()
assertEquals(HELLO, service().hello())
l
Hmm.. doesn't work for me
b
oh there's args there, so it'd be like
Copy code
provide<() -> RuBot> {{ RuBot(resolve(), resolve(), resolve()....) }}
which is not so attractive
better to create a factory type in these cases
👍 2
l
this trick worked
b
it'll still use a singleton instance in that case though...