Friday, September 21, 2012

Switched to Blogger

I have just switched from my own custom blog engine to Blogger. Due to this most of the URLs pointing to this blog will be broken, but hopefully will Google and other search engines update their search index soon.

Friday, August 24, 2012

Slides from my talk on Application Architecture

Last week I gave a talk on Application Architecture. The slides are available below:

Friday, August 17, 2012

Slides from my presentation on The Fluent Interface Pattern

Yesterday I gave a presentation on the Fluent Interface Pattern for the Capgemini Microsoft User Group. The slides from presentation are available below:

Thursday, August 16, 2012

How to activate Windows 8 Enterprise RTM

When you install Windows 8 Enterprise RTM then the installer will never ask you for a product key, instead it will just use a default key from Microsoft which cannot be used to activate Windows. In order to successfully activate Windows then you need to replace this key with your own and the only way to do this is through the command line (it’s not possible to do this through the UI):

1) In the Metro UI, search for command prompt.
2) Right click command prompt and choose Run as Administrator from the menu.
3) Write: slmgr.vbs -ipk "your key goes here" and hit enter.

Windows should now be activated.

Wednesday, August 15, 2012

Windows 8 RTM and Visual Studio 2012 RTM are now available on MSDN!

Christmas came a bit early this year with Windows 8 RTM and Visual Studio 2012 RTM that are just made available on MSDN. If you have a MSDN subscription then go and grab them :)

Tuesday, July 31, 2012

Slides from my presentation on Layered Architecture

In June I gave a couple of presentations to the students who got the chance to work for Capgemini during the summer. One of the presentations was on layered architecture where I talked about logical layering, physical tiers and the difference between them. I also showed some example code. The slides from the presentation are available below:

Monday, May 28, 2012

Slides from my "Introduction to FluentData" presentation

Earlier this month I gave a presentation at the Capgemini Microsoft User Group with the title 'Introduction to FluentData'. In the presentation I talked about what FluentData is and why it was created, and I showed some sample code that gives a good overview of how to do common CRUD operations using FluentData.

Here are the slides from the presentation:

Slides from my presentation "Dependency Injection vs Service Locator - Best Practice"

Earlier this month I gave a presentation at the Capgemini Microsoft User Group with the title "Dependency Injection vs Service Locator - Best Practice". In the presentation I talked about Inversion of Control (IOC), the various IOC patterns that exists and when you should use them.

Here is the presentation:

Slides and summary from my presentation on Data Access - Best Practice

Earlier this month I gave a presentation at the Capgemini Microsoft User Group with the title 'Data Access - Best Practice'. In the presentation I went through why the data access blocks in an application are so important, common issues related to data access that you find in many code bases and how to solve these, and at the end a summary that wraps it all up into the following best practice principles:

  • Have small, simple classes that do only one thing.
  • Use the Criteria Pattern to decide what data to retrieve.
  • Use joins to retrieve as much data as needed in one query.
  • Avoid lazy loading.
  • Use parameters instead of concatenated strings.
  • Always check for permissions when retrieving, creating, updating or deleting data.
  • Use transactions to rollback when errors occur.
  • Use the Gateway Pattern to reduce ORM dependency.
  • Have a strict Frontend layer, Business layer, Data Access layer.
  • Verify quality through Integration Tests.

Here are the slides from the presentations:

Monday, March 26, 2012

Use the Facade Pattern to avoid code duplication and to simplify source code navigation

I'm a big fan of having small concrete classes that does one thing. This allows for easy testing and easy maintenance. However in larger codebases this can also give us a challenge. Due to the large number of classes it can be hard to get an overview of all the available operations and this might lead to code duplication.
Luckily we have design patterns for the most common problems, and a nice pattern to use in this scenario is the Facade Pattern. By creating a facade class per feature/module we can make all the public operations available through a single class, then this will help us to get a better overview of the codebase and help us to avoid code duplication:

What is important to notice is that whenever a class needs to go outside its boundary then the Facade class for the requested feature must be called. For instance if the CustomerUpdater class needs to get the customer then this should be done through the CustomerFacade and not through the CustomerFetcher class, and if it needs to get the employee assigned to the customer then this should be done through the EmployeeFacade.

Monday, March 19, 2012

FluentData is out on NuGet!

FluentData has now been added to NuGet. This makes it very easy to use FluentData in any new or existing project and also to stay up to date on new versions.

Check it out through the NuGet package explorer in Visual Studio by searching for FluentData or go to

Saturday, March 3, 2012

C# regions are code smells

If you find yourself adding #regions to your code to make it easier to read and understand then this is a sign of a class that have gotten too big. Personally I prefer classes to be around 1 screen in height, and anything above this is less optimal and should be refactored.

How can you refactor away from using regions? There are 2 ways:
1) Split the class into many partial classes. This will make the class easier to read but not necessarily easier to understand or maintain.
2) Split the class into many smaller classes. The Single Responsibility Principle is important here, if the class only does one thing then it will be smaller, easier to read, understand and maintain.

Should you refactor to partial classes or smaller classes?
Try to refactor to smaller classes, and where this is not possible such as in public APIs or facade classes then refactor to partial classes.

Thursday, February 23, 2012

Principles for writing testable code

In order to write code that are easy to test then there are a few principles that must be followed:

  • Dependencies must be injected, use property- or constructor injection or an injected service locator.
  • Avoid static variables.
  • Avoid calling static methods unless they are only doing in-memory operations.
  • Mark public methods as virtual or use interfaces.
  • Classes and methods should be small. Preferably not longer than one screen size. Use the single responsibility principle to achieve this - a class should only be responsible for doing one thing = one public method (except from method overloads and facade classes).

Sunday, February 19, 2012

FluentData version 1.1 is out with support for MySQL

FluentData version 1.1 is out on CodePlex with support for MySQL. MS SQL Server, MS SQL Server Compact 4.0, MS SQL Azure and Oracle is already supported. Download it from here.

Wednesday, February 15, 2012

FluentData version 1.0 is out on CodePlex!

FluentData is a new open source Micro ORM framework that makes it easier than ever to query a database.

The existing ORMs frameworks on the market such as Entity Framework and NHibernate are overly complex and difficult to learn. The generated SQL from those frameworks are poor due their own abstracted query language and mapping from the database to .NET objects is difficult.

FluentData takes a different approach by being a lightweight framework with a simple fluent API that is easy to learn. Mapping between the database and .NET objects are simple and by using SQL which is the best database query language around you get fast and efficient queries.

Read more, see some code samples and download FluentData from

Monday, January 30, 2012

How to unit test internal types and members

Internal types and members are by default not accessible from a separate unit test project. However this can be overcome by using something known as a Friend Assembly.

A Friend Assembly is an assembly that can access internal types and members of another assembly. So if you have a project A and a project B and you want B to access the internal members of A, then all you need do is to add the following line to the AssemblyInfo.cs file in A.

[assembly: InternalsVisibleTo("B")]