Skip to content

Instantly share code, notes, and snippets.

@ayende
Created September 4, 2012 10:08
Show Gist options
  • Save ayende/3619470 to your computer and use it in GitHub Desktop.
Save ayende/3619470 to your computer and use it in GitHub Desktop.
public class RavenController : Controller
{
private static IDocumentStore documentStore;
public static IDocumentStore DocumentStore
{
get
{
if(documentStore == null)
{
lock(typeof(RavenController))
{
if(documentStore != null)
return documentStore;
documentStore = new DocumentStore
{
Url = "http://localhost:8080",
DefaultDatabase = "Nuget"
}.Initialize();
}
}
return documentStore;
}
}
public IDocumentSession DocumentSession { get; set; }
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
DocumentSession = DocumentStore.OpenSession();
base.OnActionExecuting(filterContext);
}
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
using(DocumentSession)
{
}
base.OnActionExecuted(filterContext);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment