Get Social With Facebook

At the Norwegian Developer Conference 2012 (NDC) in Oslo, I did a talk on how you can get social with Facebook. By that, I mean that you, as a developer, should get into the Facebook Developer Platform.

You can view a recording of the whole talk and my slides are also available below here.

And my slides, which are a bit off due to custom fonts.

Source Code

I have built a basic solution with some projects that does a basic Facebook integration for user authentication. In the example provided here, I’m doing synchronous loading of the Facebook API. This is preferable if you are building a web application which relies on the Facebook API for authentication. If you are loading asynchronously, which is preferable for a regular website, it will only take a longer time for the users to be automatically logged into to your app.

Source code is based on my open source project, InTheBoks. The previous beta version currently in production, was built on Silverlight and not open source.  The new version is built on HTML 5 and will be licensed under the MIT license.

The sample has an improved implementation of logon status check and visual updates of the current authentication state. Feel free this use it as a better starting point to building Facebook apps.

Browse the source on GitHub

Download ZIP with source code


Technology Predictions for 2012

It’s that time of year again, where you start contemplating on the year that has gone by and the new year that is about to start. As a tradition on my blog, I will make my technology predictions for the next year. As it happens, I forgot to do predictions for last year, but I want to review my predictions for 2010 and see how they was realized, or if my predictions was a total miss.

Previous predictions: 2008, 2009, 2010.

Since last time I did these predictions, I have moved away from Oslo, the capital of Norway, to a small place called Vennesla. Vennesla is just outside of Kristiansand, in the southern parts of Norway. Here I work for a consulting company called Deepmind, where I work as a senior solutions architect.


“A lot of movie and game predictions for The Tens evolve around misery of all forms: World Wars, famine, terror, death and global disasters from natural disasters, the creation of intelligent machines and whatnot. I predict that very little of the movies and games mentioned above will come true”

Already in the introduction, I was very wrong. There are wars all over the world, and I live in a country that is part of the crimes against humanity. We sent fighter planes and bombed Libya. We have lots of military forces in Afghanistan. While these efforts will come to an end, the people of these areas will never receive an apology from our governments. They will be left to their own, after we have helped destroy their countries. I hope for better times for these people, but when they lack even the most basic human needs, it is going to take a long while before they can reap any benefits from technological developments.

We still have famine in some parts of the world. It’s incredible and unbelievable that this is still happening. It’s something we could have gotten rid of easily, with minimal efforts. Yet, it’s not going to happen. Politicians and world leaders are responsible for holding the poorest down in the mud and keeping them there. There won’t be any real peace in the world, unless people are free from their leaders, including “democratic” countries in the west.

When disasters happens somewhere today, it is on the local news within hours. While the news media reports on more global disasters than ever before, it doesn’t mean that more bad things are happening. We get fed up with the media from time to time, they are a huge source for negative input and can be exhausting for any adult individual, let alone how our kids are bombarded with negative news from around the world. Is there not a great marked for positive and good news?


“My main major prediction for The Tens is that it will represents a dramatic shift towards subscription based models for everything.”

With the launch of Spotify in the USA and Amazon in talks with book publishers on e-book subscriptions, I can safely say that this is the future. Still, many publishers, authors and artists have started to air their negative feelings around these services and withdrawn their products. It would had been very interesting to see how much artists such as Lacuna Coil have earned or lost from going away from Spotify in the last year. Will our kids even know about great bands such as AC/DC and Metallica, when their albums are unavailable on popular services such as Spotify? Do they really think that parents will go out and buy CDs for their kids, when they already pay a monthly subscription to millions of other songs?


“Television sets will include support for streaming videos over the Internet.”

Most new flat-screen TVs comes packaged with features, streaming over the network and Internet is just basic functionality today. YouTube is a must for any TV or TV-connected device, such as AppleTV and Blu-ray players.


Since this was for 2010, the iPad had not yet been announced…


“Apple will release an incredible, amazing, awesome tablet computing device. Google will continue to develop Google Wave and their OS will be largely ignored by the market”

Other predictions I made has more or less come true. Not exactly rocket science to predict what I did, so for next year I will make a quick list of my most important predictions.

My Top List of 2012 Technology Predictions

  1. Quad-HD TVs will start to be available for consumers.
  2. NASA will find further proof of water (and previous life) on Mars, with the event of Curiosity rover landing in August 2012.
  3. Large Hadron Collider will make the Higgs boson particle no longer a hypothetical particle.
  4. Microsoft releases Windows 8 and Windows Phone 8.
  5. The biggest websites will all be HTML 5 based.
  6. Apps (and games) built on HTML 5 will see exponential growth.
  7. Millions more will play Massive Online Multiplayer Games.
  8. Commercialization of space will take a giant leap forward.
  9. Prototypes of robots that will “eat” our garbage to improve recycling of important metal and other materials.
  10. New and improved humanoid robots will mimic human behavior – still years away from commercial use.
  11. Global disasters due to weather changes.
  12. Iran will be attacked.
  13. Next generation of (Xbox) Kinect is announced.
  14. I hope the first free-state is founded (Seasteading, Free State Initiative), but I doubt it.
  15. More electric cars will see the day, resulting in loss of income to big oil and big government.
  16. New buildings will become more and more self contained, producing it’s own power and potentially reusing/recycle some materials, such as water.
  17. Many big and important online services will be hacked and have their customer details leaked.
That’s it for my 2012 list! There are plenty more in my head, but that’s what I wanted to put down on the list. Feel free to leave a comment with your own predictions and good luck in the next year!

(Photo by Marc Dalio)


Moving to Kristiansand

After 4 great years in Oslo, having worked at two great companies: Capgemini and Steria – it is time to move back to southern Norway. Earlier this year, I became the father of a beautiful little girl. Unfortunately there are no relatives living in or around Oslo, family lives in Vennesla.

Therefor I’m looking for new job opportunities in and around Kristiansand. Make sure you check out my résumé, which has all my contact details.

(Photo by Germán Póo-Caamaño)


Preparing for Windows 8

This post is written without any special knowledge about the upcoming release of Windows 8. I’m relying on the already publicly known details that Windows 8 will support tablet devices to the full and enable developers to utilize their web skills building rich applications.

A very good friend of mine, Ingo Rammer, did a talk at NDC 2011 on HTML 5. One of the best tip I got from his talk, was to start using Adobe AIR as the shell for your HTML 5 applications. As you might not be aware of, Adobe AIR includes the WebKit browser engine which more or less supports some of the HTML 5 features.

That means you can build a rich desktop application in HTML 5 which have access to local resources, such as the file system. Another neat feature is the cross-platform support between Windows and Mac. Unfortunately Adobe has quit their support for Linux.

Get the Adobe AIR SDK

First thing first, get the Adobe AIR SDK. After downloading and unpacking, you should add the path to the bin folder to your paths environment variable. this makes it quicker to build your application.

Building your first application

Create a new folder for your application on your computer, preferably you should use a source control, such as Mercurial. This makes it easier to recover from human errors.

To start off, I suggest using the HTML 5 boilerplate. I suggest going through the custom build and remove all the backwards compatibility features, as you are only going to be building for the WebKit browser.

In this folder, you can add your stylesheets, graphics, html, javascript and other resources you will be using in your application.

I suggest creating a file named Launch.bat which can be used during development and testing to launch your application.

Content of Launch.bat: adl.exe “MyIncredibleApp-app.xml”

Then you need to create your MyIncredibleApp-app.xml file, which is the manifest definition for your application. All this really needs, is the default HTML page it should render when starting up. Here is an example from one of my own applications:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="">
    <filename>Flickr Downloadr</filename>
        <content>Flickr Downloadr.html</content>
  <copyright>Copyright (c) 2006-2011 Sondre Bjellås.</copyright>

The next very important step, is to copy the Adobe AIR JavaScript files into your folder. Depending on your installation path, you should find the AIRAliases.js and AIRIntrospector.js files located here: AdobeAIRSDK\frameworks\libs\air. Copy these two files into your project and make sure you reference the AIRAliases.js in your web page. The AIRIntrospector you won’t be needing unless you are doing advanced debugging.

<script src=”AIRAliases.js”></script>

Make a wrapper around the JavaScript API

Going forward, with advances in browsers such as Internet Explorer, Chrome, FireFox and Opera – you might see that some actually already today – will support access to local resources. That means you can build web applications that doesn’t required Adobe AIR as a delivery mechanism.

For this reason, I suggest writing your own wrapper around the JavaScript API included with Adobe AIR. That means you won’t be directly dependent on Adobe AIR and it will make the transition to support other platforms and browser much smoother.

Here is an example on how to show a folder dialog using the Adobe AIR JavaScript SDK:

    var file = new air.File();
    file.addEventListener(air.Event.SELECT, dirSelected);
    file.browseForDirectory("Select a directory where you want to save photos.");

Launching your rich desktop web application

Next step is to complete your HTML page, I would suggest downloading libraries such as jQuery UI to add animations and other great features. While this post does not explain how to go from a development environment to releasing your app, I suggest referring to the Adobe AIR SDK documentation for additional features.

This is a starting point on how to get started and possibly preparing for a possible future of building great Windows 8 web applications.

Here is a screenshot of one of my own web based rich desktop applications:


Configurable Service Routes

configurationOne of the things I don’t like about the default way of working with (URL) routes in ASP.NET MVC, is code in the Global.asax. While this is fine for simple MVC-routing, you don’t want to hard-code all your WCF endpoints inside that class, instead you want to configure using the web.config.

The first part of this code example is based upon code from one of my colleagues (thanks Roy Tore), it’s basically a custom configuration element for your web.config, which allows you to define a list of services and the route it should be registered on.

Second element of this sample, is how the types are defined in the serviceType proprety in the web.config, which does not require a specific type, but support the use of interfaces. There is additional code in the example, which extends the WebServiceHostFactory with support for dependency injection using Autofac.


Here is a walkthrough on how you can do this from scratch.

  1. Create a new ASP.NET MVC 3 Web Application.
  2. Install the Autofac.MVC3 NuGet package.
  3. Add a reference to System.ServiceModel.dll, System.ServiceModel.Activation and System.ServiceModel.Web.dll
  4. Download the and unpack this into your web project.
  5. Modify the global.asax.cs, inside the Application_Start handler, add the following code in the beginning of the method:
    DependencyResolver.SetResolver(new AutofacDependencyResolver(CreateContainer()));

    And on the bottom of the method, after the ASP.NET MVC routes (RegisterRoutes):


  6. Modify the same file, but this time inside the RegisterRoutes method. We need to make sure the regular ASP.NET MVC routing will ignore our special services URI. See the full example below, and here is the modified default route:

       new { controller = "Home", action = "Index", id = UrlParameter.Optional },
       new { controller = "^(?!services).*" } // Important for WCF services to work.
  7. Create a new method called CreateContainer inside global.asax.cs, which creates your inversion of control container. Preferbly this should be placed somewhere else in a separate class. The first 3 registrations is to enable Autofac-support for your regular ASP.NET MVC controllers. After the changes, your global.asax.cs should look similar to this:
    public static void RegisterRoutes(RouteCollection routes)
            "", // Route name
         new { controller = "Home", action = "Index", id = UrlParameter.Optional },
         new { controller = "^(?!services).*" }

    protected void Application_Start() { // Set the MVC IOC resolver to our Autofac resolver. DependencyResolver.SetResolver(
    new AutofacDependencyResolver(CreateContainer())); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); // Map all the routes configured in web.config. RouteTableManager.MapRoutes(
    DependencyResolver.Current.GetService<DynamicWebServiceHostFactory>()); } private IContainer CreateContainer() { var builder = new ContainerBuilder(); builder.RegisterControllers(typeof(MvcApplication).Assembly); builder.RegisterModule(new AutofacWebTypesModule()); builder.RegisterModelBinderProvider(); builder.RegisterType<DynamicWebServiceHostFactory>(); // Register all the WCF (REST) services. builder.RegisterType<ItemService>().As<IItemService>(); var container = builder.Build(); return container; }

  8. Create your WCF (REST) Services (and modify the CreateContainer).
  9. Modify your web.config with the example below and you are done!

Add the following to your web.config, right after the configuration elemenet:

    <section name="routingExtention" type="
ConfigurableServiceRoutes.Routing.RouteTableSection, ConfigurableServiceRoutes, 
Version=, Culture=neutral" />

      <add route="services/items" serviceType="
ConfigurableServiceRoutes.Services.IItemService, ConfigurableServiceRoutes, 
Version=, Culture=neutral" />

If you need more services, just keep adding into the routes collection with more add elements.

Next part of the config change, is to enable the ASP.NET Compatability. This is important for the sample to work.

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />

That’s it!


There are multiple benefits from this sample.

  • Service Routing are configured, not compiled in code.
  • Services does no longer require an empty constructor.
  • Services supports dependency injection.
  • WCF Services works fine together with ASP.NET MVC.

And that’s basically it, I hope you enjoy this for your own projects.

Source Code

You can download a fully working sample here:

When you run the sample, you will get a 404 on the root as it’s based on an empty ASP.NET MVC 3 Web App. If you access the URL with /services/items, you should see the WCF REST Service initialize correctly.

Notes of caution

There is one place in the code, inside the DynamicWebServiceHostFactory where I override the CreateServiceHost method. The logic that replaces the base here, I don’t know what the original code was and there might be special instances where your service instance won’t work properly. It works on my machine!


Database Provider Factories: EF + SQL Compact

Now that Entity Framework 4.1 has been released and SQL Compact Edition 4.0 was released a while back, you can start using those technologies in your projects. I was working on a MVC 3 project when I discovered a NuGet package for SQL Compact Edition.

You have three option to install SQL Server Compact 4.0, using the Web Platform Installer, direct download, or you can add it as a NuGet package. I would suggest using the NuGet option, as that includes the required files with your source code. Make sure you get the documentation as well.

SqlServerCompact package:

With this package, you can start building code that queries and stores data in a file-based database. Yet, you still need one more package to make it work properly together with Entity Framework 4.1. Luckily, there is another NuGet package for this, EntityFramework.SqlServerCompact.

The SqlServerCompact package will try to modify your web.config/app.config with the following keys:

      <remove invariant="System.Data.SqlServerCe.4.0" />
      <add name="Microsoft SQL Server Compact Data Provider 4.0" 
  description=".NET Framework Data Provider for Microsoft SQL Server Compact" 
  type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, 
  Version=, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />

Also included in the package is the binaries for SQL Server Compact 4.0, located at the same level as your Visual Studio solution file, you should find this folder and within it all the assemblies needed to run: packages\SqlServerCompact.4.0.8482.1. Inside the lib folder is the System.Data.SqlServerCe.dll, which is the .NET assembly you need to work against SQL Server Compact.

The other package includes the assembly System.Data.SqlServerCe.Entity.dll, which contains code that generates proper queries against the SQL Server Compact. Additionally, it will add a source code file to your project inside the App_Start folder, that contains this code:

using System.Data.Entity;
using System.Data.Entity.Infrastructure;

[assembly: WebActivator.PreApplicationStartMethod(

namespace InTheBoks.Test.Integration.App_Start {
    public static class EntityFramework_SqlServerCompact {
        public static void Start() {
            Database.DefaultConnectionFactory = 
              new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");

What happens here is that the default connection factory of the Entity Framework is changed to the provider specified in the web.config/app.config. While I was working on the previous builds of SQL Server Compact 4 and Entity Framework 4.1 CTPs, I did not have the provider changed in the web.config. The new key in the config made me wonder for what reasons it removed and added the provider again. So I investigated with an integration test project to see what really happens.

The default connection factory is SqlConnectionFactory. That means that we need to change the connection factory in the start up of our application, which is done with the code inside the Start method displayed above, which changes it to SqlCeConnectionFactory.

To investigate what the default configuration is, I had to access a list of factories using the API: DbProviderFactories.GetFactoryClasses(). This will give you a data table with rows for all the factories. I did this to figure out why the NuGet package made the changes to my web.config/app.config and to see if there was any difference to my already installed factory and the one added in the config. Conclusion was, there is no difference. The reason why the package adds the provider, is probably because the factory is not registered on the computer if you don’t install using the manual or Web Platform Installer – so it have to add it manually in the config. My suggestion is to keep the configuration key in place, this ensures that your application will work without the need to install SQL Server Compact.

Reference Table for DbProviderFactory Classes.

Name Description Invariant
Odbc Data Provider .Net Framework Data Provider for Odbc System.Data.Odbc
Type System.Data.Odbc.OdbcFactory, System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089
OleDb Data Provider .Net Framework Data Provider for OleDb System.Data.OleDb
Type System.Data.OleDb.OleDbFactory, System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089
OracleClient Data Provider .Net Framework Data Provider for Oracle System.Data.OracleClient
Type System.Data.OracleClient.OracleClientFactory, System.Data.OracleClient, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089
SqlClient Data Provider .Net Framework Data Provider for SqlServer System.Data.SqlClient
Type System.Data.SqlClient.SqlClientFactory, System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089
Microsoft SQL Server Compact Data Provider .NET Framework Data Provider for Microsoft SQL Server Compact System.Data.SqlServerCe.3.5
Type System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=, Culture=neutral, PublicKeyToken=89845dcd8080cc91
SQLite Data Provider .Net Framework Data Provider for SQLite System.Data.SQLite
Type System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=, Culture=neutral, PublicKeyToken=db937bc2d44ff139
Microsoft SQL Server Compact Data Provider 4.0 .NET Framework Data Provider for Microsoft SQL Server Compact System.Data.SqlServerCe.4.0
Type System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=, Culture=neutral, PublicKeyToken=89845dcd8080cc91

(Foto by Tim Morgan)


InTheBoks v2 Preview

I’m currently working hard on the next version of InTheBoks. I wrote about it earlier on my blog, at which time I built it using Silverlight.

New version is being built entirely on HTML 5 and is using the latest of technologies available.

Here is a video preview of the new version, which demonstrates how I’m using AJAX to call the REST API to delete items in your movie catalog.

This new version will be released as open source and be a hosted service, that means you could build your own service just like InTheBoks and there are plenty of good code examples on how you can build modern HTML 5 applications on ASP.NET MVC 3.

Technologies and libraries in use:

  • Entity Framework 4.1 RTW (Code First)
  • SQL Server Compact Edition 4
  • ASP.NET MVC 3 (Razor syntax)
  • WCF 4 REST
  • jQuery
  • jQuery UI
  • jQuery Templating
  • Knockout JS
  • Facebook SDK

You can follow the progress on the Facebook page:

Remember to also check out the official website where the new version will be released, hopefully sometime in 2011.


Try Windows Azure for free

You can now try out Windows Azure for free, without credit card. Head over to and signup for a 30 day pass. This should get you started on developing cloud apps and you’ll quickly realize just how easy it is, if you already know how to develop web apps.

Use the promotion code: CRMIKEA

If you have any questions regarding Windows Azure, please feel free to leave a comment. Additionally, if you live in Norway and have a interest in cloud computing, have a look at the Cloud Computing group at The Norwegian Computer Association:


Microsoft Office 365

Microsoft is about to release it’s latest Office product, the Microsoft Office 365, which is a cloud-based solution that delivers some of the integrated Microsoft Office tools with their server product offerings, such as Microsoft SharePoint and Microsoft Lync.

For small businesses and new startups this is a great product, which gets you started with collaboration tools within minutes, as oppose to expensive investement in servers, software, installation and maintenance. It even integrates

Go and visit the website to signup for the beta!


Blogging with WordPress

WordPress logo

Recently I started using WordPress for my blogs and today I launched this blog on WordPress, and all my blogs will soon be running on WordPress. It’s a decent blog engine that has been around for a while and is pretty stable. It takes some work to import all your existing items, ensuring permalinks are intact and that photos still works. I imported 77 blog posts from the older blog and I hope all photos should work properly.

Recently I have been using Microsoft WebMatrix for some of my web development needs and for all new WordPress site I’m building, I start out with WebMatrix. It’s simply the easiest and fastest way to get started building your own custom blogs on WordPress.

Unfortunlately the FeedBurner service doesn’t link back to the permalinks but a combination that uses the GUIDs. Unfortunlately that means all the old links in my old feed URL won’t work, but the feed contained the full posts so it shouldn’t really matter much. The new feed URL will be

Importing from BlogEngine.NET using the BlogML format does not do categories properly, but it does import comments. Unfortunlately I had to use the RSS import and thus all my old comments on this blog are now gone. I might consider writing a script that imports them sometime in the future, but there was a majority of spam comments so hopefully it’ll be alright.

Until next time, you can take a look at my new front page which is also running on WordPress,