Last active
October 11, 2015 01:38
-
-
Save BillKeenan/3782439 to your computer and use it in GitHub Desktop.
This file contains 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
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