Skip to content

Instantly share code, notes, and snippets.

@ilguzin
Created April 12, 2013 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilguzin/5370116 to your computer and use it in GitHub Desktop.
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.
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