0

Scaldi のドキュメントに記載されている手順に従っています。以下は私のコードです。

class Game(players: List[Player], currentPlayer: Player,
           board: Board, active: Boolean, gamePersistor: GamePersistor) extends Injectable {

  def this(players: List[Player], currentPlayer: Player,
           board: Board, active: Boolean)(implicit inj: Injector) {
    this(players, currentPlayer, board, active, inject[GamePersistor])
  }
}

次のコンパイル エラーが発生します。

Error:(11, 49) not found: value inject
    this(players, currentPlayer, board, active, inject[GamePersistor])
                                                ^

誰かがこの問題を解決するのを手伝ってくれますか?

4

1 に答える 1

1

ドキュメントから推測

inject のすべての形式は、Injector の暗黙的なインスタンスがスコープ内にあることを期待しています。もしも

モジュール定義に注入している場合、すでに提供されています。独自のクラスに注入する場合、上記の例に示すように、暗黙的なインジェクター インスタンスをコンストラクター引数として提供するのが最善の方法です。

したがって、コードは

class Game(players: List[Player], currentPlayer: Player,
           board: Board, active: Boolean, gamePersistor: GamePersistor)(implicit inj:Injector) extends Injectable {

  def this(players: List[Player], currentPlayer: Player,
           board: Board, active: Boolean)(implicit inj: Injector) {
    this(players, currentPlayer, board, active, inject[GamePersistor])
  }
}
于 2014-12-30T11:40:36.283 に答える