Skip to content

Instantly share code, notes, and snippets.

@SergeiGolos
Created December 4, 2012 14:30
Show Gist options
  • Save SergeiGolos/4204499 to your computer and use it in GitHub Desktop.
Save SergeiGolos/4204499 to your computer and use it in GitHub Desktop.
[C#] Raven Controller
using Microsoft.Practices.Unity;
using Raven.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace BeerPad.Controllers
{
public class RavenController : Controller
{
protected IDocumentStore _dstore { get; set; }
protected IDocumentSession _session { get; set; }
public RavenController(IDocumentStore ds)
{
_dstore = ds;
}
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
_session = _dstore.OpenSession();
base.OnActionExecuting(filterContext);
}
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
using (_session)
{
if (_session != null && filterContext.Exception == null)
{
_session.SaveChanges();
}
}
base.OnActionExecuted(filterContext);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment