Should i use singleton pattern for MongoDB. I'm currently building an Game Server for turnbase game using Photon Engine and MongoDB.
public sealed class GSEntities
{
#region Fields
public IMongoClient Client;
public IMongoDatabase Database;
private static GSEntities _instance;
private static readonly Object sync = new object();
public static GSEntities Instance
{
get
{
if (_instance == null)
{
lock (sync)
{
if (_instance == null)
_instance = new GSEntities();
}
}
return _instance;
}
}
}
It's good or should i use other pattern like Repository ?
Thanks for your helps ! :)