Created
April 12, 2013 07:12
-
-
Save ilguzin/5370116 to your computer and use it in GitHub Desktop.
Useful way of injecting implicits in the scope. We add here a companion object with implicits for mongo database requests. Then make the object nested in the desired class by importing.
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 UserDaoImpl { | |
object Implicits { | |
implicit object AccountWriter extends BSONDocumentWriter[Account] { | |
def write(acc: Account) = BSONDocument( | |
"email" -> acc.email) | |
} | |
implicit object AccountReader extends BSONDocumentReader[Account] { | |
def read(doc: BSONDocument) = Account( | |
doc.getAs[String]("email").get, | |
"", | |
"", | |
0) | |
} | |
} | |
} | |
class UserDaoImpl(db: DB) { | |
val collection = db("users") | |
import UserDaoImpl.Implicits._ | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment