Skip to content

Instantly share code, notes, and snippets.

@BillKeenan
Created September 25, 2012 13:57
Show Gist options
  • Save BillKeenan/3782072 to your computer and use it in GitHub Desktop.
Save BillKeenan/3782072 to your computer and use it in GitHub Desktop.
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