there are a sufficient number of DI frameworks in Kotlin's world that pursue one goal - to introduce dependency into the class. More to the point, my question is: why are these frameworks better than just doing this:
// UserService.kt
interface UserService {
fun getUserById(id: String): User
}
// UserServiceImpl.kt
class UserServiceImpl : UserService {
override fun getUserById(id: String): User = TODO()
}
// Components.kt
fun userService(): UserService = UserServiceImpl()
// UserOfUserService.kt
class UserOfUserService {
private val userService = userService()
}
This is the most common example that came to my mind.
I know that DI frameworks offer more features than the example above. But in the term of an application with non-complex dependencies - is it possible to use this approach?
Thank you.