Created
September 25, 2012 13:57
-
-
Save BillKeenan/3782072 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Raven.Client.Document; | |
namespace OurNamespace | |
{ | |
public sealed class RavenStore :IDisposable | |
{ | |
private static Dictionary<string, DocumentStore> _Instance; | |
private static readonly object Padlock = new object(); | |
// Explicit static constructor to tell C# compiler | |
// not to mark type as beforefieldinit | |
static RavenStore() | |
{ | |
} | |
private RavenStore() | |
{ | |
} | |
public static DocumentStore Instance(string database) | |
{ | |
if (_Instance == null) | |
{ | |
lock (Padlock) | |
{ | |
_Instance = new Dictionary<string, DocumentStore>(); | |
} | |
} | |
if (!_Instance.ContainsKey(database)) | |
{ | |
lock (Padlock) | |
{ | |
var thisInstance = new DocumentStore {ConnectionStringName = "raven", DefaultDatabase = database}; | |
thisInstance.Initialize(); | |
_Instance[database] = thisInstance; | |
} | |
} | |
return _Instance[database]; | |
} | |
public 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