You can kinda-sorta fake this without too much effort.
First, create a Scala object that provides access to your DAO (this can contain as many things as you want, just repeat the pattern within the top-level object and the Implicits object).
package com.example.stuff
object ViewAccessPoint {
private[stuff] val myDaoCache = Application.instanceCache[MyDao]
object Implicits {
implicit def myDao(implicit application: Application): MyDao = myDaoCache(application)
}
}
In your view, you can then import the Implicits object into your template and get hold of the DAO created by Guice.
@import com.example.stuff.ViewAccessPoint.Implicits._
@import play.api.Play.current
myDao.whatever()
This works for both Java and Scala projects.
You can see this in practice here:
On a side note, I would consider if you really want to be doing data access in your template layer.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…