I have an domain object:
case class User(val id: Long, username: String)
I don't want to follow service-repository approach (like typical spring applications, where entities are just data holders), I want to put functionality related to user into User object.
But I don't want to tie User object to concrete infrastructure implementations, so I want to pass interfaces (traits) instead.
I'm trying do this by following way:
case class User(val id: Long, val username: String, implicit val userRepository: IUserRepository)
And somewhere in application (controller, or somewhere else), I want to inject (with @Inject()) concrete implementation of IUserRepsoitory and want it to implicitly passed to constructor of User.
Question 1: case class User(val id: Long, val username: String, implicit val userRepository: IUserRepository) - this doesn't work, it is not compiled
Question 2: Is it correct approach to decouple infrastructure implementation from object domain in play? are they some best practices?
Thanks.