Skip to content

Instantly share code, notes, and snippets.

@bradoyler
Created November 24, 2012 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradoyler/4138561 to your computer and use it in GitHub Desktop.
Save bradoyler/4138561 to your computer and use it in GitHub Desktop.
RavenDB setup for MVC controller
public IDocumentSession session { get; protected set; }
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
session = MvcApplication.Store.OpenSession();
}
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
if (filterContext.IsChildAction)
return;
using (session)
{
if (filterContext.Exception != null)
return;
if (session != null)
session.SaveChanges();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment