0

I've followed the instructions in https://stackoverflow.com/a/9115510/1170932 and have "before" method invocation logging working. However, rather than add the [SetMethodInfoAsMessage] annotation at every method, I'd rather add it at the controller/class level if possible. Can anyone point me at an example of this?

Also, I realise that all the controller's methods will have to be made virtual but I figure that 1 change per method (adding virtual) is better than 2 (adding [SetMethodInfoAsMessage] and virtual).

Many thanks. Pete

Community
  • 1
  • 1
sming
  • 801
  • 2
  • 12
  • 25

1 Answers1

1

Instead of using an attribute pointcut, you can specify another type of pointcut. For instance a regular expression pointcut.

You could also define your own pointcut, for instance one that use the asp.net infrastructure to determine if the current method invocation is an action method.

Making your methods virtual is something that is easily forgotten. If it's really important to you that all methods are intercepted, I suggest you write a unit tests that uses reflection to iterate over all controller methods and checks for the virtual access modifier (using MethodInfo.IsVirtual).

Marijn
  • 10,367
  • 5
  • 59
  • 80