Skip to content

Instantly share code, notes, and snippets.

@johnlcox
Last active August 29, 2015 13:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
class MyInjectable() {
val myString = "my String"
}
trait MyTrait {
@Inject
val myInjectable: MyInjectable = null // Initialize to null so that it isn't abstract and will be injected by guice. Is there a better way to do this though?
}
class MyObject extends Controller with MyTrait {}
@RunWith(classOf[JUnitRunner])
class MixinInjectionSpec extends Specification {
"Guice" should {
"inject the mixin trait" in {
val injector = Guice.createInjector()
val myObject = injector.getInstance(classOf[MyObject])
myObject.myInjectable.myString must equalTo("my String")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment