Dependency injection with abstract class and object in Play Framework 2.5

前端 未结 2 1078
不思量自难忘°
不思量自难忘° 2020-12-24 14:23

I\'m trying to migrate from Play 2.4 to 2.5 avoiding deprecated stuff.

I had an abstract class Microservice from which I created some objects. Some func

2条回答
  •  忘掉有多难
    2020-12-24 15:12

    In scala,

    -> If you do not want to explicitly forward all the injected parameters to the base constructor, you can do it like that :

    abstract class Base {
      val depOne: DependencyOne
      val depTwo: DependencyTwo
      // ...
    }
    
    case class Child @Inject() (param1: Int,
                                depOne: DependencyOne,
                                depTwo: DependencyTwo) extends Base {
      // ...
    }
    

提交回复
热议问题