Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 1st, 2012  |  syntax: None  |  size: 0.77 KB  |  hits: 4  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /// <summary>
  2. /// This filter will manage the session for all of the controllers that needs a Raven Document Session.
  3. /// It does so by automatically injecting a session to the first public property of type IDocumentSession available
  4. /// on the controller.
  5. /// </summary>
  6. public class RavenActionFilterAttribute : ActionFilterAttribute {
  7.         public override void OnActionExecuting(HttpActionContext filterContext) {
  8.  
  9.                 filterContext.Request.Properties["RavenDocumentStore"] =
  10.                         DocumentStoreHolder.TryAddSession(filterContext.ControllerContext.Controller);
  11.         }
  12.  
  13.  
  14.         public override void OnActionExecuted(HttpActionExecutedContext filterContext)
  15.     {
  16.         DocumentStoreHolder
  17.                         .TryComplete(filterContext.ActionContext.ControllerContext.Controller,                          filterContext.Exception == null);
  18.     }
  19. }