Monthly Archives: December 2009

Refactoring to Patterns

Earlier this month i ordered my copy of Refactoring to Patterns. This books has two parts: the first part describes patterns and code smells (anti-patterns) and the second part is a catalog of refactorings. The first part is not bad, but i appreciated the second part much more. I did not read the book from front to cover and skipped the ‘mechanics’ sections (abstract steps to take in order to accomplish a particular refactoring). I focussed on the ‘example’ sections instead which demonstrate the application of the previously mentionned mechanics.

During the reading of this book i had a couple of ‘aha’ moments which gave me the feeling that i understood (appreciated) a certain pattern better. All in all a good book to read.

Ninject: connect an IProxyFactory component to the kernel

Because it’s the second time that i run into this i will post the solution here so that i (and all the other people that run into the same issue) can easily solve it next time. Anyway, i was playing with Ninject and ran into the following exception:

Error activating XXX: the implementation type YYY requests static interceptors, or dynamic interceptors have been defined.
In order to provide interception, you must connect an IProxyFactory component to the kernel.

If you search for implementations of IProxyFactory you will find the DynamicProxy2ProxyFactory and the LinFuProxyFactory classes. But how can you tell your kernel to use them? This is pretty simple (but hard to find on the web):

Kernel.Components.Connect<iproxyFactory>(new DynamicProxy2ProxyFactory());

Instead of writing this code to connect the ProxyFactory implementation you can also use the XXX module (which does it for you) as following:

var kernel = new StandardKernel(new DynamicProxy2Module(), new BusinessModule());

The Nomadic Developer: Surviving and Thriving in the World of Technology Consulting

This is probably one of the shortest book reviews ever, but there is not much to say about The Nomadic Developer: Surviving and Thriving in the World of Technology Consulting. Just read it if you are (or considering to become) an IT-consultant because it really covers both good and bad aspects in depth.

Bing vs Google in 5 seconds

A while ago i sat in a meeting and some ms-fanboy used Bing to find out how much 60 inches were in meters. The first page had pages with conversion factors but none of them contained the actual answer. I suggested that he’d use Google instead and while he was keying in the question the answer already appeared.

Today i wanted to make a screencast of this difference in experience but it seems that bing has the ‘conversion’ feature now too. Wondering about what would make me switch search engines…

In case you really have to Append one array to another

Here is another problem i’ve seen people solve once too many: Append one array to another. STOP. Revisit the problem. Can’t you simply use List<T> and move on to solving actual business problems? In case you really can’t get rid of the arrays read the following:

Given()
{
 source = new[] { SourceElement };
 destination = new[] { DestinationElement };
}


When()
{
 source.AppendTo(ref destination);
}


ThenTheDestinationShouldStillHaveTheDestinationElement()
{
 Assert.AreEqual(DestinationElement, destination[0]);
}


ThenTheDestinationShouldHaveBeenExtendedWithTheSourceElement()
{
 Assert.AreEqual(SourceElement, destination[1]);
}

And here is the code which satisfies the requirements:

public static class Extensions
{
 public static void AppendTo<t>(this T[] sourceArray, ref T[] destinationArray)
 {
  var sourceLength = sourceArray.Length;
  var destinationLength = destinationArray.Length;
  var extendedLength = destinationLength + sourceLength;
  Array.Resize(ref destinationArray, extendedLength);
  Array.Copy(sourceArray, 0, destinationArray, destinationLength, sourceLength);
 }
}

Perhaps it’s time to start (or does it exist already, cause i can’t find it) an open-source project with extension methods.