0

I have just started using Play 2.0 with Scala and Casbah for connecting to MongoDB. I have been able to connect to my MongoDB instance but what I am looking for is a way to be able to access the MongoClient from all my model classes.

Is there any DependencyInjection way to inject mongoClient in all Scala models ? or

Should I have one Scala object which initialises the MongoClient and use that object to refer to MongoClient in all my models ? or

Is there a more better way to do this ?

GTY
  • 417
  • 4
  • 15

1 Answers1

0

As MongoClient uses a connection pool internally, its optimal to only have a single instance for your application and that single object can then be used by all your models.

Also, you could look at Salat which might do what you require or give you an idea on how best to implement your own models.

Ross
  • 17,861
  • 2
  • 55
  • 73