Reputation: 776
I'm looking at some code we have in a particular library in our project. This library contains API calls that may or may not come from MVC. Many of them start with the exact same code... save the current lazy loading value and then turn it off. At the end of these methods, the lazy loading is restored to its original value.
What I am wanting to do is add some sort of attribute on these methods to handle this. Since it is a library rather than MVC code, ActionFilterAttributes are not available, and adding a reference to MVC seems architecturally rather inappropriate in this library. Is there something else I can use to behave similarly (i.e., add an attribute to a method so that code associated with the attribute runs at the beginning and at the end of the method)?
Upvotes: 0
Views: 227
Reputation: 887443
You want AOP.
Look at PostSharp.
In particular, action filters are implemented within the MVC pipeline, and wouldn't work at all for you.
Upvotes: 2