Skip to content

Instantly share code, notes, and snippets.

@BillKeenan
Last active October 11, 2015 01:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BillKeenan/3782439 to your computer and use it in GitHub Desktop.
Save BillKeenan/3782439 to your computer and use it in GitHub Desktop.
public static class RavenStore
{
private static readonly ConcurrentDictionary<string, DocumentStore> _Instance;
private static readonly object Padlock = new object();
static RavenStore()
{
_Instance = new ConcurrentDictionary<string, DocumentStore>();
}
public static DocumentStore Instance(string database)
{
DocumentStore store;
if (_Instance.TryGetValue(database, out store))
{
return store;
}
lock (Padlock)
{
if (!_Instance.TryGetValue(database, out store))
{
var thisInstance = new DocumentStore
{ConnectionStringName = "raven", DefaultDatabase = database};
thisInstance.Initialize();
_Instance[database] = thisInstance;
return thisInstance;
}
return store;
}
}
public static void Dispose()
{
if (_Instance == null) return;
foreach (var documentStore in _Instance)
{
documentStore.Value.Dispose();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment