我想知道是否可以使用以下语法绑定依赖项:
bind [Environment[User, Authenticator]] to FakeEnvironment[User, SessionAuthenticator](testUser)
(这是从测试中获取的,模块中的实际绑定稍微冗长一些)
其中SessionAuthenticator具有以下签名:
case class SessionAuthenticator(val loginInfo : com.mohiva.play.silhouette.api.LoginInfo, ...)
extends scala.AnyRef
with com.mohiva.play.silhouette.api.Authenticator
with scala.Product
with scala.Serializable {...}
和身份验证器:
trait Authenticator extends scala.AnyRef {...}
但我得到的只是编译期间的以下堆栈跟踪:
[error] /home/mironor/projects/livrarium/test/controllers/CloudSpec.scala:22: overloaded method value to with alternatives:
[error] [T <: com.mohiva.play.silhouette.api.Environment[services.User,com.mohiva.play.silhouette.api.Authenticator]](fn: => T)(implicit evidence$2: reflect.runtime.universe.TypeTag[T])scaldi.BoundHelper[T] <and>
[error] (none: None.type)scaldi.BoundHelper[com.mohiva.play.silhouette.api.Environment[services.User,com.mohiva.play.silhouette.api.Authenticator]]
[error] cannot be applied to (com.mohiva.play.silhouette.test.FakeEnvironment[services.User,com.mohiva.play.silhouette.impl.authenticators.SessionAuthenticator])
[error] bind [Environment[User, Authenticator]] to FakeEnvironment[User, SessionAuthenticator](user)
这样我可以选择在应用程序中只Authenticator
使用一次Module
并像这样注入它:
implicit val env = inject[Environment[User, Authenticator]]
代替:
implicit val env = inject[Environment[User, SessionAuthenticator]]
我有哪些选择?