How to using wiring for Play controller

I am using a model similar to
https://alvinalexander.com/scala/how-to-implement-user-authentication-play-framework-application/
I defined a trait and wired CodingService
trait ServicesModule {
import com.softwaremill.macwire._
lazy val codingService = wire[CodingService]
}

I then defined a controller
class CodingCtrl @Inject()(cc: ControllerComponents,
authenticatedAction: AuthenticatedAction)
extends AbstractController(cc)
and it fails
If I use
class CodingCtrl(codingService:CodingService) (cc: ControllerComponents)
extends AbstractController(cc) {
It works.
How can I handle this so I can pull in AuthenticatedAction while wiring in CodingService as well ?
Thank you

I’m not sure what the error is that you are getting, but if CodingService requires an AuthenticatedAction, it needs to be in-scope when wiring.

For example:

trait ServicesModule {
import com.softwaremill.macwire._
lazy val codingService = wire[CodingService]

def authenticatedAction: AuthenticatedAction
}

And the concrete value for authenticatedAction would need to be provided by something that is mixed in with ServicesModule

The problem seems to be with
Cannot find a value of type: [play.api.mvc.BodyParsers.Default]
I am importing in
import play.api.mvc.BodyParsers._
import play.api.mvc.BodyParsers
and tried with LoggingAction to see it that works. Have the same issue - seems like an issue with BodyParsers ?

Hi Adam,
Thanks for your response I have the trait
trait CodingModule extends ServicesModule {

import com.softwaremill.macwire._

lazy val AuthenticatedAction = wire[AuthenticatedAction]
lazy val CodingCtrl = wire[CodingCtrl]

def controllerComponents: ControllerComponents
}
and AuhenticatedAction as

class AuthenticatedAction @Inject()(parser: BodyParsers.Default)
(implicit ec: ExecutionContext) extends ActionBuilderImpl(parser) {

I am trying to inject AuthenticatedAction into my controller and I get the following message when I compile
Cannot find a value of type: [play.api.mvc.BodyParsers.Default]
[error] lazy val AuthenticatedAction = wire[AuthenticatedAction]

Seems like it’s unable to wire play.api.mvc.BodyParsers.Default - Default ?
I did import - play.api.mvc.BodyParsers._
Not sure if the above information is sufficient to know the cause or you need more info.

Thank you,
Prasad

I am using macwire in a different app and it works fine,

It’s just when I try to inject something that seem to contains - Play BodyParsers.Default that it’s failing

I didn’t use Play for a long time, but looking at the code (the constructors), to create BodyParsers.Default), you need a PlayBodyParsers instance. To create that, you need to instantiate DefaultPlayBodyParsers, which has its own dependencies etc.

I think Play might come with these instance pre-defined, in the BuiltInComponentsFromContext trait. Maybe this example: play-samples/GreetingApplicationLoader.scala at 2.8.x · playframework/play-samples · GitHub will be helpful?

Thanks Adam. That was the problem I was having - creating an instance of BodyParsers, since there are many of them. Let me see if I can figure it out.