Monday, May 21, 2007

One thing that makes me a better developer is keyboard shortcuts, the problem is that they aren't very discoverable and you usually have to download a keymap for each application.

After using my Mac for awhile I really missed the alt key from Windows to pull down menus. Jonas introduced me to Keycue for Mac OSX, it is a utility that shows all keyboard shortcuts for the application that you are using after you hold down a hotkey (the Apple key) for a certain amount of time.

Now I am left wondering why Windows doesn't have something like this!

Monday, May 21, 2007 9:36:07 PM (GMT Standard Time, UTC+00:00)  #    Comments [2]  | 
Wednesday, May 16, 2007

I have been looking for a quick and easy way to implement logging into our application while writing tests. The problem is that logging is a cross cutting concern and I feel dirty adding logging code into every class.

I originally started looking at a number of Aspect Oriented Frameworks with grand plans to use them for other concerns, then I ran into this comment from Hammett on the Castle Project forums:

 "Honestly, the interception capabilities that Windsor provide is enough for me, that's why I havent searched for a full-fledged AOP tool yet."

It turns out that the interception capabilities of Windsor solve my logging problems as well.

Here is a simple example that demonstrates the Interceptor capabilities of Windsor.

I have a ICalculator interface with one method named Calc that takes the parameters x and y of type int.

public interface  ICalculator
{
int Calc(int x, int y);
}

I have a concrete class that implements that interface. Notice that my concrete class does one thing well (adding two numbers) it does not add two numbers and log well.

public class Calculator : ICalculator
{
public int Calc(int x, int y)
{
return x + y;
}
}
Our Windsor configuration looks like this:
<component id="calculator"
           service="MyAssembly.ICalculator, MyAssembly"
           type="MyAssembly.Calculator, MyAssembly" />

Now we can create a logging interceptor to log calculations:

public class LogInterceptor : IMethodInterceptor
{
public object Intercept(IMethodInvocation invocation, params object[] args)
{
Console.WriteLine("Invocaton Method: " + invocation.Method.Name);

foreach (object o in args)
{
Console.WriteLine("Args: " + o);
}

object retValue = invocation.Proceed(args);

return retValue;
}
}

This class will log the method name that was called and the arguments that were passed to it to the console and then proceed with the method that it intercepted (Calc in our case). Now using Windsor we can add logging to any class that needs it, all we need to do is add the InterceptorAttribute to the Calculator class that needs logging and to modify our Windsor configuration file:

<component id="log.interceptor"
             type="MyAssembly.LogInterceptor, MyAssembly" />
        
        <component id="calculator"
             service="MyAssembly.ICalculator, MyAssembly"
             type="MyAssembly.Calculator, MyAssembly">

            <interceptors>
                <interceptor>${log.interceptor}</interceptor>
            </interceptors>

        </component>

Anytime we call Calculator its values will get logged to the console without modifying the intent of the calc method. Very cool!

Wednesday, May 16, 2007 5:52:11 AM (GMT Standard Time, UTC+00:00)  #    Comments [1]  | 
Thursday, May 10, 2007
Mark off September 1st, 2007 on your development calendar with the help of Edmug, i've managed to secure a bigger spot for Edmonton Code Camp 2007 at the Fantasyland Hotel. Stay tuned to the Edmonton Code Camp website and the EDMUG meetings for information on how to be a presenter at the code camp, how to be a contributor to the code camp or to register to attend the code camp. This year we are hoping to add an additional track for a grand total of 3!

Wednesday, May 09, 2007 11:37:54 PM (GMT Standard Time, UTC+00:00)  #    Comments [1]  | 
Thursday, May 03, 2007

I'm finally recovering from the 2007 Calgary Code Camp. It seemed like every presenter I talked to, including myself had very little sleep all weekend. A big thanks go out to James Kovacs and the organizing committee of the code camp, it was tons of fun and I am already looking forward to next year.

My presentation on Windsor Container went well. I am unsure if I am going to talk over screencasts during my presentations anymore as it is to slow and I am more confident in my typing and presenting abilities.

For now I am going to release a screencast on setting up a simple component that was intended for the code camp attendees. You can download it here you can download the code for my presentation here. I am open to any feedback or questions that anyone has on Windsor Container, please contact me and I will do my best to answer.

A couple of attendees at my presentation asked if Windsor Container supported constructor based dependency injection and the answer is absolutely! I will be coming out with another screencast soon that will explain inversion of control more in depth and show how you can refactor towards using Windsor Container.

Thursday, May 03, 2007 3:20:40 AM (GMT Standard Time, UTC+00:00)  #    Comments [2]  | 

Theme design by Jelle Druyts

Pick a theme: