dickwall/subcut — Issue #9: Can SubCut do nested injections?
Author: btarbox
Created: 2011-12-27 20:21:19+00:00
State: open

The following code doesn't compile if I bind to Player2 but does compile if I bind to Player1. The only difference between the two is that Player2 is itself ready to get things injected to it. The error is that the it can't find the implicit value for bindingModule for Player2. I can understand that the configuration module is not passing an implicit to Player2 but I can't find a way to do so. Should I be able to do this sort of injection of thing-needing-injection?

import org.scala_tools.subcut.inject.{BindingModule, Injectable, NewBindingModule}

trait Player {
def play
}

class Player1 extends Player {
override def play = println("playing")
}

class Player2()(override implicit val bindingModule: BindingModule) extends Player with Injectable {
override def play = println("playing")
}

object Problem extends NewBindingModule({ module =>
import module._
bind[Player] toInstance new Player2()
})