言語: スカラ; フレームワーク: Play 2.5; ライブラリ: Silhouette 4.0、Guice、scala-guice。
公式の Silhouette シード プロジェクトの 1 つは、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 ライブラリの魔法がなければ、このコードはどのように見えるのだろうか。誰かが元の装いだけを使ってこれらのバインディングを書き直すことはできますか?
さらに、次のコードもあります。
@Provides
def provideEnvironment(
userService: UserService,
authenticatorService: AuthenticatorService[CookieAuthenticator],
eventBus: EventBus
): Environment[MyEnv] = {
Environment[MyEnv](
userService,
authenticatorService,
Seq(),
eventBus
)
}
前もって感謝します。