Cannot use modifyBindings in SubCut

140 views Asked by At

Would modifyBindings worked as promised this test should pass:

import org.scalatest.FunSuite
import org.scala_tools.subcut.inject.NewBindingModule
import org.scala_tools.subcut.inject.BindingModule
import org.scala_tools.subcut.inject.Injectable
import org.junit.Test

case class Resource1(name: String)

class ResourceClient(implicit val bindingModule: BindingModule) extends Injectable {
    val res1 = inject[Resource1]
}

object Config1 extends NewBindingModule(module => {
    module.bind[Resource1] toSingle new Resource1("name1")
})

class TestModifyBindings extends FunSuite {

@Test
def test1() {
    implicit val bindingModule = Config1
    val rc = new ResourceClient
    assert(rc.res1.name == "name1")
    Config1.modifyBindings { module =>
        module.bind[Resource1] toSingle new Resource1("name2")
        val rc2 = new ResourceClient //not sure if rc can be used here
        assert(rc2.res1.name == "name2") //FAILS
    }
}

}

Any ideas about what I missed?

1

There are 1 answers

1
danb On

If you make

    Config1.modifyBindings { module =>

into

    Config1.modifyBindings { implicit module =>

does that fix it?