Stackoverflow exception if serverClient used in additionalRouter

I try to implement an additional router (with Play Actions), one of the actions calls another lagom service, so I use serviceClient.implement as a dependency for this router. But ApplicationLoader fails with StackOverflow exception. Is there any way to implement this?

hi @AndreyLadniy,

I don’t see anything wrong on the approach you described but devil is on the details. Can you share some code?

When I wrote example, I found problem in an other place.

class PlayRouter(playController: PlayController) extends SimpleRouter {
  override def routes: Routes = {
    case GET(p"/index") =>
  lazy val otherService: OtherService = serviceClient.implement[OtherService]

  override lazy val lagomServer: LagomServer = {
    serverFor[ExampleService](new ExampleServiceImpl())

  lazy val playController: PlayController = new PlayController(controllerComponents, otherService)

  lazy val playRouter: Router = new PlayRouter(playController)

but without PlayRouter class

  lazy val playRouter: Router = {
      case GET(p"/index") =>

all is fine

Maybe problem is in

trait LagomServiceRouter extends Router {
  final def additionalRouter(router: Router): LagomServiceRouter

router dependencies instantiation started on additionalRouter call in contrast to main server service

protected def serverFor[T <: Service](serviceFactory: => T): LagomServer = macro ScaladslServerMacroImpl.simpleBind[T]