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.
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
ApiRouterclass directly in application.conf in theplay.http.routerkey.That being said, there's no reason to necessary use DI. You could also define everything in an
object.