How to share an instance between advices #234
Unanswered
dilandau2001
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I was planning to use the Aspect Injector mainly for logging.
My purpose is to add logs for all methods of a class with the less work possible.
The log should print method name with current parameters, Start and Finish.
When it finish and result is not void, Finish trace should print also method returned value.
Up to this point, your LoggingAspect is more than enough.
But now I wanted to add in the Finish trace, how long it took the method to be done.
As long as OnEntry and OnExit have no way to share information, no method context expose through arguments. Then there is not nice way to do it.
I tried with an Around aspect, but it does not work fine when methods contain ref or out parameters.
I cannot use a global variable because it will be overriden by succesive calls.
Using a dictionary, or a ThreadCall Stack is possible but very ugly too and also it has problems when dealing with async methods or multiple threads.
Is there any way to somehow create and instance of a StopWatcher inside the OnEntry and use that instance in the OnExit?
Beta Was this translation helpful? Give feedback.
All reactions