如何在编译时注入中传递ControllerComponents

How to pass ControllerComponents in compile time injection

我的控制器定义如下

class UserController @Inject()(userRepo: Repository[UUID, User],cc:
    ControllerComponents)(implicit exec: ExecutionContext) extends
    AbstractController(cc)

我想将 Repository[UUID, User] 注入到这个组件中。我想我必须创建一个应用程序加载器并扩展 BuiltInComponentsFromContext 并定义我的路由。

class AppComponents(context: Context) extends (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
  )
}

我的代码没有编译,因为我在 lazy val applicationController = new controllers.UserController(userRepository) 中创建 UserController 时必须传递 ComponentController。但我不知道从哪里得到这个 ComponentController。我该怎么办?

BuiltInComponentsFromContextComponentController

的实例
class AppComponents (context: Context) extends BuiltInComponentsFromContext(context)
  with CassandraRepositoryComponents
  with HttpFiltersComponents
  with controllers.AssetsComponents
  with CSRFComponents{

  //TODOM - check if userRepository will be a singleton. Don't want new connection for each request.

  lazy val userRepositoryController = new controllers.UserController(userRepository, controllerComponents) //controllerComponents is defined in BuiltInComponentsFromContext

...
}