Created
October 21, 2011 10:02
-
-
Save rarous/1303490 to your computer and use it in GitHub Desktop.
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 System; | |
using System.Linq; | |
using System.Web.Mvc; | |
using Castle.DynamicProxy; | |
public abstract class ActionInterceptor : IInterceptor, IActionFilter, IResultFilter { | |
public void Intercept(IInvocation invocation) { | |
switch (invocation.Method.Name) { | |
case "OnActionExecuting": | |
Intercept(invocation, OnActionExecuting); | |
break; | |
case "OnActionExecuted": | |
Intercept(invocation, OnActionExecuted); | |
break; | |
case "OnResultExecuting": | |
Intercept(invocation, OnResultExecuting); | |
break; | |
case "OnResultExecuted": | |
Intercept(invocation, OnResultExecuted); | |
break; | |
} | |
invocation.Proceed(); | |
} | |
void Intercept<TContext>(IInvocation invocation, Action<TContext> action) { | |
action(invocation.Arguments.First() as TContext); | |
} | |
public virtual void OnActionExecuting(ActionExecutingContext filterContext) { | |
} | |
public virtual void OnActionExecuted(ActionExecutedContext filterContext) { | |
} | |
public virtual void OnResultExecuting(ResultExecutingContext filterContext) { | |
} | |
public virtual void OnResultExecuted(ResultExecutedContext filterContext) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment