【发布时间】:2017-03-21 05:13:45
【问题描述】:
语言:斯卡拉; 框架:玩2.5; 库:Silhouette 4.0、Guice、scala-guice。
官方的 Silhouette 种子项目之一使用 guice 和 scala-guice (net.codingwell.scalaguice.ScalaModule) 编写 DI 配置。代码如下所示:
import net.codingwell.scalaguice.ScalaModule
class Module extends AbstractModule with ScalaModule{
/**
* Configures the module.
*/
def configure() {
bind[Silhouette[MyEnv]].to[SilhouetteProvider[MyEnv]]
bind[SecuredErrorHandler].to[ErrorHandler]
bind[UnsecuredErrorHandler].to[ErrorHandler]
bind[IdentityService[User]].to[UserService]
我想知道,如果没有来自 net.codingwell.scalaguice 库的魔法,这段代码会是什么样子。有人可以仅使用原始 guice 重写这些绑定吗?
另外我还有这个代码:
@Provides
def provideEnvironment(
userService: UserService,
authenticatorService: AuthenticatorService[CookieAuthenticator],
eventBus: EventBus
): Environment[MyEnv] = {
Environment[MyEnv](
userService,
authenticatorService,
Seq(),
eventBus
)
}
提前致谢。
【问题讨论】:
标签: scala guice silhouette