Skip to content

Instantly share code, notes, and snippets.

@tkellogg
Created July 3, 2013 16:54
Show Gist options
  • Save tkellogg/5920447 to your computer and use it in GitHub Desktop.
Save tkellogg/5920447 to your computer and use it in GitHub Desktop.
Demonstrating use of implicit parameters for dependency injection
object People {
implicit val columnFamily: ColumnFamily = getColumnFamily
def getPersonByName(name: String)(implicit cf: ColumnFamily) = ...
}
class ProdUsage {
// uses ColumnFamily from object People
def foo = People.getPersonByName("Jordan")
}
class PeopleSpec extends FunSpec {
it("can use a different C* column family than the default one") {
implicit val testCF = getTestColumnFamily
// uses ColumnFamily from local scope, testCF
People.getPersonByName("James")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment