Created
December 4, 2012 14:30
-
-
Save SergeiGolos/4204499 to your computer and use it in GitHub Desktop.
[C#] Raven Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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