Created
July 3, 2013 16:54
-
-
Save tkellogg/5920447 to your computer and use it in GitHub Desktop.
Demonstrating use of implicit parameters for dependency injection
This file contains hidden or 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
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