Skip to content

Instantly share code, notes, and snippets.

@AlexZeitler
Created March 5, 2012 22:45
Show Gist options
  • Select an option

  • Save AlexZeitler/1981708 to your computer and use it in GitHub Desktop.

Select an option

Save AlexZeitler/1981708 to your computer and use it in GitHub Desktop.
/// <summary>
/// This filter will manage the session for all of the controllers that needs a Raven Document Session.
/// It does so by automatically injecting a session to the first public property of type IDocumentSession available
/// on the controller.
/// </summary>
public class RavenActionFilterAttribute : ActionFilterAttribute {
public override void OnActionExecuting(HttpActionContext filterContext) {
filterContext.Request.Properties["RavenDocumentStore"] =
DocumentStoreHolder.TryAddSession(filterContext.ControllerContext.Controller);
}
public override void OnActionExecuted(HttpActionExecutedContext filterContext)
{
DocumentStoreHolder
.TryComplete(filterContext.ActionContext.ControllerContext.Controller, filterContext.Exception == null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment