Use tapir router with play-framework without jsr330

87 Views Asked by At

I use play framework with tapir. My usage similar to sample https://github.com/gaeljw/tapir-play-sample

And we define router like this:

@Singleton
class ApiRouter @Inject() (apiController: BookController, apiDocumentation: ApiDocumentation, bookEndpoints: BookEndpoints)(implicit
    val materializer: Materializer,
    ec: ExecutionContext
) extends SimpleRouter {
  
  ...

  override def routes: Routes = {

    openApiRoute
      .orElse(booksListingRoute)
      .orElse(booksStreamingRoute)
      .orElse(oneOfStreamingRoute)
      .orElse(addBookRoute)
      .orElse(getBookRoute)
  }

routes

->         /        routers.ApiRouter

Promblem, that our implementation of @Singleton is scaldi jsr330, that has some problems

How can I remove dependency on jsr330 (@Singleton) and use router as singleton without it? Note that just not using singleton leaves to performance problem.

1

There are 1 best solutions below

0
Gaël J On

If you don't need the routes file at all as all your routes are defined as code, you can get rid of the routes file and declare the ApiRouter class directly in application.conf in the play.http.router key.


That being said, there's no reason to necessary use DI. You could also define everything in an object.