Aspect Oriented Programing in C#
-
I am trying to implement state verification as part of our automated testing framework. I want to use aspects to run a pre check and post check of any particular method call and only have an attribute indicating that that would be a verifiable method. This would be transparent to both the called and client code, performance is not an issue. There are two articles i have fond on the code project that touch on aspects in C#: http://www.codeproject.com/cs/design/aopsimplestscenario.asp?msg=2160427&mode=all&userid=3765364#xx2160427xx http://www.codeproject.com/csharp/aspectintercept.asp?msg=2145384&mode=all&userid=3765364#xx2145384xx Both use ContextBoundObject in their implementations. It seems that both solutions suffer from the same problem. Method injection does not work when a method is called from inside its own class. Something like this. /***Will properly call pre and post methods*****/ MyClass myClass = new MyClass(); myClass.CallMethod(); /***Will not call pre and post methods*****/ this.CallMethod() Has anyone else run into this problem? Am i going down the wrong path? Is there a better solution to the problem?
-
I am trying to implement state verification as part of our automated testing framework. I want to use aspects to run a pre check and post check of any particular method call and only have an attribute indicating that that would be a verifiable method. This would be transparent to both the called and client code, performance is not an issue. There are two articles i have fond on the code project that touch on aspects in C#: http://www.codeproject.com/cs/design/aopsimplestscenario.asp?msg=2160427&mode=all&userid=3765364#xx2160427xx http://www.codeproject.com/csharp/aspectintercept.asp?msg=2145384&mode=all&userid=3765364#xx2145384xx Both use ContextBoundObject in their implementations. It seems that both solutions suffer from the same problem. Method injection does not work when a method is called from inside its own class. Something like this. /***Will properly call pre and post methods*****/ MyClass myClass = new MyClass(); myClass.CallMethod(); /***Will not call pre and post methods*****/ this.CallMethod() Has anyone else run into this problem? Am i going down the wrong path? Is there a better solution to the problem?
Not sure if it's what you are looking for, but have you looked at the Policy Injection Block in the latest Enterprise Library release? http://www.codeplex.com/entlib[^]
only two letters away from being an asset