January 2009 Entries
In the last part of the tutorial we created a method GetInterceptedMethodsCountFor that I promised I’ll talk about soon. While we’re at it, we’re going to fix another design flaw of our Freezable class.
To do its work, it holds a hard reference to each and every freezable object it creates. This is obviously not a big deal if you create only a handful of freezable objects that are we want to be alive for the entire time the application is running.
private static readonly IDictionary<object, IFreezable> _freezables = new Dictionary<object, IFreezable>();
However, in most cases the objects we create are transient,...
I’ve been working a little bit with dynamic code generation at runtime (classes in Reflection.Emit namespace, collectively referred to as Reflection.Emit). It’s a low level API, that requires you to work with IL operations, keep track of what is on the stack, and requires quite a bit of knowledge about IL and CLR. I’m no expert in IL, as probably most of developers, but there are ways to make this things easier. To work my way through generating code, I use iterative approach. Write a class/method in C# that exactly (or as closely as...
Welcome to the 3rd part of my Dynamic Proxy tutorial.
If you’re new here, you may take a look at previous parts first
Castle DynamicProxy tutorial part I: Introduction
Castle Dynamic Proxy tutorial part II: The what, why and how
We’ll start by updating our CallLoggingInterceptor class, so that we can use it in tests. What we need from it, is to enhance its functionality, so that it not only logs (to the Console) the calls, but also keeps a count of calls. To do that we add a property called Count, which gets incremented each...
After my first attempt at making IInterceptorSelector support in DynamicProxy actually work, there has been a discussion on castle-dev discussion group, about the implementation, its implication and features. To make long story short (find and read the thread if you’re interested) I set up to redo the implementation, moving most of the code that was generated at runtime into another, statically compiled class. Finally yesterday I had some time to actually start working on the implementation, but fixing bugs with code-gen at 1am proved to not be my strongest skill, so I finished the implementation today. Funny thing is, I...
It took quite longer than I had expected, but by the end of the year I bought few books from Amazon, and finally, they’re here. (HINT: You can use the link to see some more books I'd love to have... and then buy some for me ). Anyway, here’s what I bought: After I placed the order, I noticed that I have very similar taste to Casey Charlton, but I digress.
Patterns of Enterprise Application Architecture (Addison-Wesley Signature Series): Martin Fowler: BooksISBN: 0321127420ISBN-13: 9780321127426
...