我有一个控制器。我想将 DAO 组件传递userRepo
给它
class UserController @Inject()(userRepo: Repository[User,Integer],cc: ControllerComponents)(implicit exec: ExecutionContext) extends AbstractController(cc){...}
我将编译时 DI 挂钩如下:
class AppComponents(context: Context) extends BuiltInComponentsFromContext(context) with CassandraRepositoryComponents {
lazy val applicationController = new controllers.UserController(userRepository)
lazy val assets = new controllers.Assets(httpErrorHandler)
override def router: Router = new Routes(
httpErrorHandler,
applicationController,
assets
)
}
问题 1 - 我的问题是我不知道该怎么传递ControllerComponent
问题 2 - 我收到以下missing parameter meta:AssetsMetaData
错误lazy val assets = new controllers.Assets(httpErrorHandler)
问题 3 - 我想我也没有正确使用 Routes。我可以看到 IDE 显示潜在错误cannot resolve constructor
override def router: Router = new Routes(
httpErrorHandler,
applicationController,
assets
)
我正在关注以下教程,但由于它基于Play 2.4
,它可能不会在 2.6 中运行。我怎样才能使上面的代码工作Play 2.6
?
http://manuel.kiessling.net/2016/01/17/compile-time-cassandra-injection-in-play-2-4/