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]  | 
Friday, April 27, 2007
Tonight the Edmonton .NET User Group celebrated its one year anniversary with a presentation by Chistians Izquierdo at the Maverick Brewery. Looking back at a year ago I never would have dreamed that I would have changed this much professionally as a developer due to the efforts of this community and due to guidance of the quality speakers we have been fortunate enough to have.

There are probably 2 turning points in my professional career that made me strive to be better at my profession. The first, was a manager telling me "you don't know what you're doing" (I admit I didn't know what I was doing at the time).  After that managers words, I wanted to prove him wrong so I found the .NET Wizards and met other developers that could help me get better.

The second turning point was a car ride to the first meeting of the newly formed Edmonton .NET User Group where Jean-Paul Boodhoo stated to me "we are the next generation of software developers." Those words said to me that I could either choose to be more pragmatic about how I approached my career or I could be left in the dust, it was my choice.

If I can pass on anything that I learned from a year of the Edmonton .NET User Group, it is to strive to be the next generation of software developer. Don't let yourself be left in the dust and always look for ways to improve your skills. Never forget that if you look to the person on your left you may see someone who is better than you at software development, but if you look to your right there is someone striving to be you. Strive to be better than the person on your left and mentor the person on our right!

Cheers to another year of being the next generation of software developers and thanks to the community who has helped make the Edmonton .NET User Group a success.

Friday, April 27, 2007 5:16:52 AM (GMT Standard Time, UTC+00:00)  #    Comments [3]  | 
Saturday, April 21, 2007
Saturday, April 21, 2007 5:50:56 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  | 
Monday, April 16, 2007
Last year the Edmonton Developer Communty went down to Calgary Code Camp and won all the prizes. This year we are paying our dues and presenting. I will be presenting an Introduction to Windsor Container from the Castle Project.

Here is my abstract:

What if I told you that you never had to make an object instantiation again? Using an Inversion of Control container like Windsor Container from the Castle Project ( http://www.castleproject.org) will enable you to code to abstractions without worrying about wiring up your object dependencies. In this session I will take an example application built without using Windsor Container and refactor it toward a cleaner design utilizing Windsor Container and Inversion of Control. During the course of refactoring toward using Windsor Container, you will be introduced to some of the benefits that using an Inversion of Control container can bring to your project.


Last year the code camp was a lot of fun, if you are from Edmonton consider taking a trip down on Red Arrow, the trip is cheap and they have wireless.

Monday, April 16, 2007 5:47:11 PM (GMT Standard Time, UTC+00:00)  #    Comments [1]  | 
Sunday, April 15, 2007
After an unfortunate incident involving freshly brewed coffee and a curious puppy my laptop was fried. It came back for a week but only to say goodbye. At first I thought that my laptop dieing was a bad thing but then I realized that I could buy a new laptop!

Today I decided to join a elite group of people and buy a new MacBook Pro!

Here is a photoshopped representation of what I will look like in a couple months:

Dude

Sunday, April 15, 2007 12:08:07 AM (GMT Standard Time, UTC+00:00)  #    Comments [4]  | 
Thursday, April 05, 2007

   85 [TestMethod]

   86 public void ShouldEnumerateIntegers()

   87 {

   88     IEnumerable<int> multipleOfTwo = GetIntegerList();

   89 

   90     Assert.IsNotNull(multipleOfTwo);

   91 }

   92 

   93 public IEnumerable<int> GetIntegerList()

   94 {

   95     for(int i=0; i <= 10; i++)

   96     {

   97         if (i % 2 == 0)

   98             yield return i;

   99     }

  100 }

Thursday, April 05, 2007 5:16:16 PM (GMT Standard Time, UTC+00:00)  #    Comments [2]  | 

Theme design by Jelle Druyts

Pick a theme: