Aop, Unity, Interceptors and ASP.NET MVC Controller Action Methods

Posted by Richard Ev on Stack Overflow See other posts from Stack Overflow or by Richard Ev
Published on 2009-08-27T13:36:02Z Indexed on 2012/07/11 9:16 UTC
Read the original article Hit count: 271

Filed under:
|
|
|

Using log4net we would like to log all calls to our ASP.NET MVC controller action methods.

The logs should include information about any parameters that were passed to the controller.

Rather than hand-coding this in each action method we hope to use an AoP approach with Interceptors via Unity.

We already have this working with some other classes that use interfaces (using the InterfaceInterceptor). However, we're not sure how to proceed with our controllers. Should we re-work them slightly to use an interface, or is there a simpler approach?

Edit

The VirtualMethodInterceptor seems to be the correct approach, however using this results in the following exception:

System.ArgumentNullException: Value cannot be null.
Parameter name: str
   at System.Reflection.Emit.DynamicILGenerator.Emit(OpCode opcode, String str)
   at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context)
   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)

© Stack Overflow or respective owner

Related posts about .NET

Related posts about log4net