I am new to the Play and scala platforms and I am trying to inject dependency inside a companion object.
I have a simple case class, for example:
case class Bar(foo: Int) {}
With a companion object like:
object Bar {
val myDependency =
if (isTest) {
}
else
{
}
val form = Form(mapping(
"foo" -> number(0, 100).verifying(foo => myDependency.validate(foo)),
)(Bar.apply)(Bar.unapply))
}
This works great, but it is not a completely clean way to do this. I would like to be able to introduce dependencies during assembly, so that I can introduce various mock objects during testing and various real implementations during development and production.
What is the best way to achieve this?
Any help really appreciated. Thank!
source
share