[Play 2.4 scala] I am facing issues getting messages implicit in my code.

439 views
Skip to first unread message

Abhijit Singh

unread,
Jun 8, 2015, 12:27:12 PM6/8/15
to play-fr...@googlegroups.com
I am noob in scala so may be question is basic. I am trying to migrate my app from 2.3 to 2.4.
In our code base we have used Messages extensively, so any way to remove that will also help.
Currently our code is like this

class MyController @Inject() (val messagesApi: MessagesApi) extends Controller  with I18nSupport{
def methodA() = {
new MyControllerService.doSomething()
}

class MyControllerService{
def doSomething()(implicit messages:Messages){
messages(any_key)
}
}



When compiling this code i am getting Error:(31, 84) Play 2 Compiler:  could not find implicit value for parameter messages: play.api.i18n.Messages compile time error message.

Please help to resolve this issue, any suggestions to improve this kind of problem in better way is most welcome.

Will Sargent

unread,
Jun 10, 2015, 9:26:58 AM6/10/15
to play-fr...@googlegroups.com
You want to pass through the request implicitly, and that should take care of it:
class MyController @Inject() (val messagesApi: MessagesApi, service: MyControllerService) extends Controller  with I18nSupport{
def methodA() = Action { implicit request =>
service.doSomething()
}
}

class MyControllerService{
def doSomething[A}(implicit messages:Messages){
messages(any_key)
}
}

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/8314ded4-3408-4deb-81d6-eb8fedafdd9a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages