Created
February 5, 2014 12:04
-
-
Save kalys/8822301 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
import com.escalatesoft.subcut.inject._ | |
import NewBindingModule._ | |
//... | |
trait SomeService { | |
def name:String | |
} | |
object RealService extends SomeService { | |
def name = "real" | |
} | |
object FakeService extends SomeService { | |
def name = "fake" | |
} | |
object MySingleton { | |
def someMethod(someArgument:String)(implicit bindingModule:BindingModule):String = { // implicit argument is passed | |
val service = bindingModule.inject[SomeService](None) // pay attention to None | |
val serviceName = service.name | |
s"This is $serviceName service" | |
} | |
} | |
object SomeConfigurationModule extends NewBindingModule(module =>{ | |
module.bind [SomeService] toSingle RealService | |
}) | |
// for use on production | |
MySingleton.someMethod("ololo")(SomeConfigurationModule) | |
// for testing | |
SomeConfigurationModule.modifyBindings { implicit bindingModule => | |
bindingModule.bind [SomeService] toSingle FakeService | |
MySingleton.someMethod("argument") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment