# How to using wiring for Play controller

**URL:** <https://softwaremill.community/t/how-to-using-wiring-for-play-controller/103>\
**Category:** macwire\
**Created:** [January 25, 2023, 6:52am UTC](https://softwaremill.community/t/how-to-using-wiring-for-play-controller/103 "2023-01-25T06:52:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasad\_mokkapati](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/prasad_mokkapati/32/83_2.png) [@prasad\_mokkapati](https://softwaremill.community/u/prasad_mokkapati)\
**Post date:** [January 25, 2023, 6:52am UTC](https://softwaremill.community/t/how-to-using-wiring-for-play-controller/103/1 "2023-01-25T06:52:58Z")

</div>

I am using a model similar to  
[https://alvinalexander.com/scala/how-to-implement-user-authentication-play-framework-application/](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

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [January 26, 2023, 8:30pm UTC](https://softwaremill.community/t/how-to-using-wiring-for-play-controller/103/2 "2023-01-26T20:30:39Z")

</div>

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:

```auto
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`

---

<div class="post-metadata">

**Author:** ![prasad\_mokkapati](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/prasad_mokkapati/32/83_2.png) [@prasad\_mokkapati](https://softwaremill.community/u/prasad_mokkapati)\
**Post date:** [January 26, 2023, 9:24pm UTC](https://softwaremill.community/t/how-to-using-wiring-for-play-controller/103/3 "2023-01-26T21:24:36Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![prasad\_mokkapati](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/prasad_mokkapati/32/83_2.png) [@prasad\_mokkapati](https://softwaremill.community/u/prasad_mokkapati)\
**Post date:** [January 30, 2023, 8:30pm UTC](https://softwaremill.community/t/how-to-using-wiring-for-play-controller/103/4 "2023-01-30T20:30:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![prasad\_mokkapati](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/prasad_mokkapati/32/83_2.png) [@prasad\_mokkapati](https://softwaremill.community/u/prasad_mokkapati)\
**Post date:** [February 3, 2023, 10:41pm UTC](https://softwaremill.community/t/how-to-using-wiring-for-play-controller/103/5 "2023-02-03T22:41:54Z")

</div>

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

> **[GitHub - pmokkapati/nettyapp: Application using Netty and Macwire](https://github.com/pmokkapati/nettyapp)**
>
> Application using Netty and Macwire. Contribute to pmokkapati/nettyapp development by creating an account on GitHub.

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

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [February 6, 2023, 4:53pm UTC](https://softwaremill.community/t/how-to-using-wiring-for-play-controller/103/6 "2023-02-06T16:53:18Z")

</div>

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](https://github.com/playframework/play-samples/blob/2.8.x/play-scala-macwire-di-example/app/GreetingApplicationLoader.scala) will be helpful?

---

<div class="post-metadata">

**Author:** ![prasad\_mokkapati](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/prasad_mokkapati/32/83_2.png) [@prasad\_mokkapati](https://softwaremill.community/u/prasad_mokkapati)\
**Post date:** [February 8, 2023, 6:19pm UTC](https://softwaremill.community/t/how-to-using-wiring-for-play-controller/103/7 "2023-02-08T18:19:38Z")

</div>

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.
