Mike Pakhomov Mike Pakhomov - 1 month ago 33
Scala Question

Play 2.5.X: method current in object Play is deprecated: This is a static reference to application, use DI instead

I'm new to PlayFramework.

Please give me a sample how to access Configuration parameters from my view. I'm using PlayFramework 2.5.3

Old way (@current is deprecated):


New way (as far as I understand, Configuration should be injected):

I know how to access it from controller.

@Inject() (val messagesApi: MessagesApi, configuration: Configuration)

How do I use it from my view?


Sadly there isn't much you can do about it. It is just how it is when DI was introduced to Play, not much was discussed in regard to templates. One possible solution could be:

  1. Inject Configuration in controller
  2. Send it as implicit to your view/template

    class Application @Inject() (implicit val config: Configuration) extends Controller {
        def index = Action {

And your template will look like:

@(myParam1: Any)(implicit config: Configuration)
<h2>Some HTML here @myParam1 @config.getString("environment.param")</h2>

I am totally aware that this somehow defeats the purpose of DI but this is just how it is right now.