Hi guys, I posted a question on StackOverflow rega...
# kodein
y
Hi guys, I posted a question on StackOverflow regarding managing the lifecycle of Kodein context/container. Would be great if you guys have some thoughts on it. Thanks. https://stackoverflow.com/questions/50973181/shutting-down-closing-kodein-context
s
What about using `provider`s instead of `instance`s
Copy code
val kodein = Kodein {
    bind<SomeConnectionPool>() with provider { SomeConnectionPool.obtain() }  // closeables
     bind<SomeResource>() with provider { SomeResource.obtain() }  // closables

    bind<SomeService>() with singleton { SomeService(provider()) }
    bind<SomeOtherService>() with singleton { SomeOtherService(provider()) }
}
And the code of your
obtain()
methods will make sure that only non-closed connections and resources are returned, they'll manage the pool(s).
y
Thanks Anton.