Compilation error when using Scaldi

359 views Asked by At

I am following the steps mentioned in Scaldi documentaiton. Following is my code.

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])
  }
}

I get the following compilation error.

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

Can someone help me solve this issue?

1

There are 1 answers

0
Can't Tell On BEST ANSWER

Figured out from the documentation

All forms of inject expect and implicit instance of Injector to be in scope. If

you are injecting in the module definition, then it already provides one for you. If you are injecting in you own classes, then the best approach would be to provide the implicit injector instance as a constructor argument, as shown in the example above.

So the code should be

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])
  }
}