Geeks With Blogs
Greg Young Greg.ToString()

I have been thinking lately about delegates and their possible use for interceptors.


One really cool thing that they could provide for me with a trivial amount of code is the ability to define a give interceptor as being asynchronous. The code generated for this is rather trivial and I think it is a rather cool functionality (especially when considerring things like logging). Roger pointed out a good gotcha with this in that one could quite easily context switch themselves to death but in the case of people using it wisely (interceptors logging service calls within a domain to a database sounds like a wonderful case) it could offer huge performance benefits as the aspects would be nearly transparent.

The worst case I can possibly think of for asynchronous aspects is transaction management (aka UOW extensions) :) ah beatiful non-deterministic behaviors in my transaction management, this could make for some err interesting debugging fun!

Another “neatity“ of using the delegates lies in the fact that the delegates can actually be held externally. I could actually add and remove interceptions without regenerating the type but instead simply adding/removing from the delegate.

The other reason why this idea is very interesting to me is that it is very clear in it's intentions. For those who do not know I have been writing a book on AOP in C#. Delegates would be far easier to understand in an example than the IL generation used in order to direct call the methods, this level of clarity may be beneficial for people reading the book.

My favorite thought in looking at externalized delegates is that one can show a clear refactorring process in manually generated code to reach the point. This again may be beneficial for very selfish reasons.



Posted on Wednesday, February 1, 2006 7:37 PM AOP | Back to top

Comments on this post: Delegates and the dynamic decortor

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Greg Young | Powered by: