Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.