In typical first example about using the reader monad for dependency injection we have:
this like the classic https://github.com/hermannhueck/composing-functions/blob/master/src/main/scala/demo/Demo08bDbReader.scala
Generally at the core of it is the idea of returning a function that takes as parameter the very thing we want to inject e.g.
trait UserService {
def getUserbyId(id: String): UserRepo => User
}
I have seen several baby example here and there and they all work proper for the purpose of explaining the main idea.
However i am having a hard time translating that for a real world example where you actually have a Repo that actually connect to a DB.
Indeed, in that scenario, the Account Repo itself depend on something else which is either a DB Connection or an Emvconfig from which the DB connection is created.
This also means that every method of the UserRepo will depend on that DB connection or EnvConfig. If a constructor injection is not used for that repo, then all the methods of the UserRepo will need it too which can escalate back to to whatever Service that call the UserRepo.
Am I missing something here ? I must be otherwise i do not understand the all buzz around it.
Can someone explain what i am missing here ?