<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Technology &#38; Robotics</title>
	<atom:link href="http://sondreb.com/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://sondreb.com/blog</link>
	<description>software development, gadgets, robots, cloud and microsoft</description>
	<lastBuildDate>Thu, 29 Dec 2011 12:29:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Technology Predictions for 2012</title>
		<link>http://sondreb.com/blog/post/technology-predictions-for-2012.aspx</link>
		<comments>http://sondreb.com/blog/post/technology-predictions-for-2012.aspx#comments</comments>
		<pubDate>Thu, 29 Dec 2011 12:28:21 +0000</pubDate>
		<dc:creator>SondreB</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Future]]></category>
		<category><![CDATA[Predictions]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[Windows Phone]]></category>

		<guid isPermaLink="false">http://sondreb.com/blog/?p=461</guid>
		<description><![CDATA[It&#8217;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 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sondreb.com/blog/wp-content/uploads/2011/12/speed.jpg"><img class="alignleft size-thumbnail wp-image-465" style="margin-right: 10px; margin-left: 10px; margin-top: 0px; margin-bottom: 0px;" title="speed" src="http://sondreb.com/blog/wp-content/uploads/2011/12/speed-150x150.jpg" alt="" width="150" height="150" /></a>It&#8217;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.</p>
<p>Previous predictions: <a href="http://sondreb.com/blog/post/Technology-in-2008-and-Beyond.aspx" target="_blank">2008</a>, <a href="http://sondreb.com/blog/post/Technology-Prediction-for-2009.aspx" target="_blank">2009</a>, <a href="http://sondreb.com/blog/post/technology-predictions-for-2010.aspx" target="_blank">2010</a>.</p>
<p>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 <a href="http://www.deepmind.no/" target="_blank">Deepmind</a>, where I work as a senior solutions architect.</p>
<p>&nbsp;</p>
<blockquote><p>&#8220;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&#8221;</p></blockquote>
<p>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.</p>
<p>We still have famine in some parts of the world. It&#8217;s incredible and unbelievable that this is still happening. It&#8217;s something we could have gotten rid of easily, with minimal efforts. Yet, it&#8217;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&#8217;t be any real peace in the world, unless people are free from their leaders, including &#8220;democratic&#8221; countries in the west.</p>
<p>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&#8217;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?</p>
<p>&nbsp;</p>
<blockquote><p>&#8220;My main major prediction for The Tens is that it will represents a dramatic shift towards subscription based models for everything.&#8221;</p></blockquote>
<p>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?</p>
<p>&nbsp;</p>
<blockquote><p>&#8220;Television sets will include support for streaming videos over the Internet.&#8221;</p></blockquote>
<p>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.</p>
<p>&nbsp;</p>
<p>Since this was for 2010, the iPad had not yet been announced&#8230;</p>
<p>&nbsp;</p>
<blockquote><p>&#8220;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&#8221;</p></blockquote>
<p>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.</p>
<h2>My Top List of 2012 Technology Predictions</h2>
<ol>
<li>Quad-HD TVs will start to be available for consumers.</li>
<li><a href="http://mars.jpl.nasa.gov/" target="_blank">NASA</a> will find further proof of water (and previous life) on Mars, with the event of Curiosity rover landing in August 2012.</li>
<li><a href="https://en.wikipedia.org/wiki/Large_Hadron_Collider" target="_blank">Large Hadron Collider</a> will make the <a href="https://en.wikipedia.org/wiki/Higgs_boson" target="_blank">Higgs boson</a> particle no longer a hypothetical particle.</li>
<li>Microsoft releases Windows 8 and Windows Phone 8.</li>
<li>The biggest websites will all be HTML 5 based.</li>
<li>Apps (and games) built on HTML 5 will see exponential growth.</li>
<li>Millions more will play Massive Online Multiplayer Games.</li>
<li>Commercialization of space will take a giant leap forward.</li>
<li>Prototypes of robots that will &#8220;eat&#8221; our garbage to improve recycling of important metal and other materials.</li>
<li>New and improved humanoid robots will mimic human behavior &#8211; still years away from commercial use.</li>
<li>Global disasters due to weather changes.</li>
<li>Iran will be attacked.</li>
<li>Next generation of (Xbox) Kinect is announced.</li>
<li>I hope the first free-state is founded (<a href="http://seasteading.org/" target="_blank">Seasteading</a>, <a href="http://freestateinitiative.org/" target="_blank">Free State Initiative</a>), but I doubt it.</li>
<li>More electric cars will see the day, resulting in loss of income to big oil and big government.</li>
<li>New buildings will become more and more self contained, producing it&#8217;s own power and potentially reusing/recycle some materials, such as water.</li>
<li>Many big and important online services will be hacked and have their customer details leaked.</li>
</ol>
<div></div>
<div>That&#8217;s it for my 2012 list! There are plenty more in my head, but that&#8217;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!</div>
<p>(Photo by <a href="https://secure.flickr.com/photos/marcdalio/5311567178/" target="_blank">Marc Dalio</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://sondreb.com/blog/post/technology-predictions-for-2012.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving to Kristiansand</title>
		<link>http://sondreb.com/blog/post/moving-to-kristiansand.aspx</link>
		<comments>http://sondreb.com/blog/post/moving-to-kristiansand.aspx#comments</comments>
		<pubDate>Mon, 22 Aug 2011 07:50:43 +0000</pubDate>
		<dc:creator>SondreB</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sondreb.com/blog/?p=452</guid>
		<description><![CDATA[After 4 great years in Oslo, having worked at two great companies: Capgemini and Steria &#8211; 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&#8217;m looking for new job opportunities [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sondreb.com/blog/wp-content/uploads/2011/08/Kristiansand.jpg"><img class="alignleft size-thumbnail wp-image-454" style="margin-left: 0px; margin-right: 10px;" title="Kristiansand" src="http://sondreb.com/blog/wp-content/uploads/2011/08/Kristiansand-150x150.jpg" alt="" width="150" height="150" /></a>After 4 great years in Oslo, having worked at two great companies: <a href="http://www.no.capgemini.com/" target="_blank">Capgemini</a> and <a href="http://www.steria.no/" target="_blank">Steria</a> &#8211; 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.</p>
<p>Therefor I&#8217;m looking for <strong>new job opportunities</strong> in and around Kristiansand. Make sure you <strong>check out my <a href="http://sondreb.com/about/resume" target="_blank">résumé</a></strong>, which has all my contact details.</p>
<p>(Photo by <a href="http://www.flickr.com/photos/gpoo/290036363/" target="_blank">Germán Póo-Caamaño</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://sondreb.com/blog/post/moving-to-kristiansand.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preparing for Windows 8</title>
		<link>http://sondreb.com/blog/post/preparing-for-windows-8.aspx</link>
		<comments>http://sondreb.com/blog/post/preparing-for-windows-8.aspx#comments</comments>
		<pubDate>Sat, 13 Aug 2011 08:00:55 +0000</pubDate>
		<dc:creator>SondreB</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[Windows 8]]></category>

		<guid isPermaLink="false">http://sondreb.com/blog/?p=445</guid>
		<description><![CDATA[This post is written without any special knowledge about the upcoming release of Windows 8. I&#8217;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 [...]]]></description>
			<content:encoded><![CDATA[<p>This post is written without any special knowledge about the upcoming release of Windows 8. I&#8217;m relying on the already <a href="http://news.cnet.com/8301-30685_3-20067859-264/web-apps-get-the-ultimate-endorsement-windows-8/" target="_blank">publicly known details that Windows 8</a> will support tablet devices to the full and enable developers to utilize their web skills building rich applications.</p>
<p>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.</p>
<p>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.</p>
<h2>Get the Adobe AIR SDK</h2>
<p>First thing first, get the <a href="http://www.adobe.com/products/air/sdk/" target="_blank">Adobe AIR SDK</a>. 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.</p>
<p><a href="http://sondreb.com/blog/wp-content/uploads/2011/08/Environment_Variables.jpg"><img class="alignnone size-medium wp-image-446" title="Environment_Variables" src="http://sondreb.com/blog/wp-content/uploads/2011/08/Environment_Variables-300x219.jpg" alt="" width="300" height="219" /></a></p>
<h2>Building your first application</h2>
<p>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.</p>
<p>To start off, I suggest using the <a href="http://html5boilerplate.com/" target="_blank">HTML 5 boilerplate</a>. 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.</p>
<p>In this folder, you can add your stylesheets, graphics, html, javascript and other resources you will be using in your application.</p>
<p>I suggest creating a file named <strong>Launch.bat</strong> which can be used during development and testing to launch your application.</p>
<p>Content of Launch.bat: adl.exe &#8220;MyIncredibleApp-app.xml&#8221;</p>
<p>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:</p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;application xmlns="http://ns.adobe.com/air/application/2.7"&gt;
    &lt;id&gt;FlickrDownloadr&lt;/id&gt;
    &lt;versionNumber&gt;0.1&lt;/versionNumber&gt;
    &lt;filename&gt;Flickr Downloadr&lt;/filename&gt;
    &lt;initialWindow&gt;
        &lt;content&gt;Flickr Downloadr.html&lt;/content&gt;
        &lt;visible&gt;true&lt;/visible&gt;
        &lt;width&gt;800&lt;/width&gt;
        &lt;height&gt;600&lt;/height&gt;
    &lt;/initialWindow&gt;
  &lt;copyright&gt;Copyright (c) 2006-2011 Sondre Bjellås.&lt;/copyright&gt;
  &lt;icon&gt;
    &lt;image16x16&gt;icons/Flickr-Downloadr-16x16.png&lt;/image16x16&gt;
    &lt;image32x32&gt;icons/Flickr-Downloadr-32x32.png&lt;/image32x32&gt;
    &lt;image48x48&gt;icons/Flickr-Downloadr-48x48.png&lt;/image48x48&gt;
    &lt;image128x128&gt;icons/Flickr-Downloadr-128x128.png&lt;/image128x128&gt;
  &lt;/icon&gt;
&lt;/application&gt;</pre>
<p>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&#8217;t be needing unless you are doing advanced debugging.</p>
<p>&lt;script src=&#8221;AIRAliases.js&#8221;&gt;&lt;/script&gt;</p>
<h2>Make a wrapper around the JavaScript API</h2>
<p>Going forward, with advances in browsers such as Internet Explorer, Chrome, FireFox and Opera &#8211; you might see that some actually already today &#8211; will support access to local resources. That means you can build web applications that doesn&#8217;t required Adobe AIR as a delivery mechanism.</p>
<p>For this reason, I suggest writing your own wrapper around the JavaScript API included with Adobe AIR. That means you won&#8217;t be directly dependent on Adobe AIR and it will make the transition to support other platforms and browser much smoother.</p>
<p>Here is an example on how to show a folder dialog using the Adobe AIR JavaScript SDK:</p>
<pre>    var file = new air.File();
    file.addEventListener(air.Event.SELECT, dirSelected);
    file.browseForDirectory("Select a directory where you want to save photos.");</pre>
<pre></pre>
<h2>Launching your rich desktop web application</h2>
<p>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.</p>
<p>This is a starting point on how to get started and possibly preparing for a possible future of building great Windows 8 web applications.</p>
<p>Here is a screenshot of one of my own web based rich desktop applications:</p>
<p><a href="http://sondreb.com/blog/wp-content/uploads/2011/08/Flickr_Downloadr_birds_of_prey.jpg"><img class="alignnone size-medium wp-image-447" title="Flickr_Downloadr_birds_of_prey" src="http://sondreb.com/blog/wp-content/uploads/2011/08/Flickr_Downloadr_birds_of_prey-300x150.jpg" alt="" width="300" height="150" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://sondreb.com/blog/post/preparing-for-windows-8.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configurable Service Routes</title>
		<link>http://sondreb.com/blog/post/configurable-service-routes.aspx</link>
		<comments>http://sondreb.com/blog/post/configurable-service-routes.aspx#comments</comments>
		<pubDate>Wed, 08 Jun 2011 23:23:23 +0000</pubDate>
		<dc:creator>SondreB</dc:creator>
				<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://sondreb.com/blog/?p=432</guid>
		<description><![CDATA[One 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 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sondreb.com/blog/wp-content/uploads/2011/06/configuration.png"><img style="margin: 0px 8px 0px 0px; display: inline; float: right" title="configuration" alt="configuration" align="right" src="http://sondreb.com/blog/wp-content/uploads/2011/06/configuration_thumb.png" width="320" height="125" /></a>One 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.</p>
<p>The first part of this code example is based upon code from one of my colleagues (<em>thanks</em> <a href="http://www.linkedin.com/in/roytore" target="_blank">Roy Tore</a>), 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.</p>
<p>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.</p>
<h2>Walkthrough</h2>
<p>Here is a walkthrough on how you can do this from scratch.</p>
<ol>
<li>Create a new ASP.NET MVC 3 Web Application. </li>
<li>Install the <a href="http://nuget.org/List/Packages/Autofac.Mvc3" target="_blank">Autofac.MVC3</a> NuGet package. </li>
<li>Add a reference to System.ServiceModel.dll, System.ServiceModel.Activation and System.ServiceModel.Web.dll </li>
<li><a href="http://sondreb.com/pub/Routing_20110609.zip" target="_blank">Download the Routing.zip</a> and unpack this into your web project. </li>
<li>Modify the global.asax.cs, inside the Application_Start handler, add the following code in the beginning of the method:     <br /> 
<pre class="csharpcode">DependencyResolver.SetResolver(<span class="kwrd">new</span> AutofacDependencyResolver(CreateContainer()));</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>And on the bottom of the method, after the ASP.NET MVC routes (RegisterRoutes):</p>
<p></p>
<pre class="csharpcode">RouteTableManager.MapRoutes(DependencyResolver.Current.GetService&lt;DynamicWebServiceHostFactory&gt;());
</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</li>
<li>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:<br />
    </p>
<pre class="csharpcode">routes.MapRoute(
    <span class="str">&quot;&quot;</span>,
    <span class="str">&quot;{controller}/{action}/{id}&quot;</span>,
   <span class="kwrd">new</span> { controller = <span class="str">&quot;Home&quot;</span>, action = <span class="str">&quot;Index&quot;, </span>id = UrlParameter.Optional },
   <span class="kwrd">new</span> { controller = <span class="str">&quot;^(?!services).*&quot;</span> } <span class="rem">// Important for WCF services to work.</span>
    );</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<pre>&#160;</pre>
</li>
<li>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:
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute(<span class="str">&quot;{resource}.axd/{*pathInfo}&quot;</span>);

    routes.MapRoute(
        <span class="str">&quot;&quot;</span>, <span class="rem">// Route name</span>
        <span class="str">&quot;{controller}/{action}/{id}&quot;</span>,
     <span class="kwrd">new</span> { controller = <span class="str">&quot;Home&quot;</span>, action = <span class="str">&quot;Index&quot;</span>, id = UrlParameter.Optional },
     <span class="kwrd">new</span> { controller = <span class="str">&quot;^(?!services).*&quot;</span> }
        );
}

<span class="kwrd">protected</span> <span class="kwrd">void</span> Application_Start()
{
    <span class="rem">// Set the MVC IOC resolver to our Autofac resolver.</span>
    DependencyResolver.SetResolver(<span class="kwrd">new</span> AutofacDependencyResolver(CreateContainer()));

    AreaRegistration.RegisterAllAreas();

    RegisterGlobalFilters(GlobalFilters.Filters);
    RegisterRoutes(RouteTable.Routes);

    <span class="rem">// Map all the routes configured in web.config.</span>
    RouteTableManager.MapRoutes(      DependencyResolver.Current.GetService&lt;DynamicWebServiceHostFactory&gt;());
}

<span class="kwrd">private</span> IContainer CreateContainer()
{
    var builder = <span class="kwrd">new</span> ContainerBuilder();
    builder.RegisterControllers(<span class="kwrd">typeof</span>(MvcApplication).Assembly);
    builder.RegisterModule(<span class="kwrd">new</span> AutofacWebTypesModule());
    builder.RegisterModelBinderProvider();

    builder.RegisterType&lt;DynamicWebServiceHostFactory&gt;();

    <span class="rem">// Register all the WCF (REST) services.</span>
    builder.RegisterType&lt;ItemService&gt;().As&lt;IItemService&gt;();

    var container = builder.Build();
    <span class="kwrd">return</span> container;
}
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

</pre>
</li>
<li>Create your WCF (REST) Services (and modify the CreateContainer). </li>
<li>Modify your web.config with the example below and you are done!</li>
</ol>
<p>Add the following to your web.config, right after the configuration elemenet:</p>
<pre class="csharpcode">  <span class="kwrd">&lt;</span><span class="html">configSections</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">section</span> <span class="attr">name</span><span class="kwrd">=&quot;routingExtention&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;</span></pre>
<pre class="csharpcode"><span class="kwrd">ConfigurableServiceRoutes.Routing.RouteTableSection, ConfigurableServiceRoutes, </span></pre>
<pre class="csharpcode"><span class="kwrd">Version=1.0.0.0, Culture=neutral&quot;</span> <span class="kwrd">/&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">configSections</span><span class="kwrd">&gt;</span>

  <span class="kwrd">&lt;</span><span class="html">routingExtention</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">routes</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">route</span><span class="kwrd">=&quot;services/items&quot;</span> <span class="attr">serviceType</span><span class="kwrd">=&quot;</span></pre>
<pre class="csharpcode"><span class="kwrd">ConfigurableServiceRoutes.Services.IItemService, ConfigurableServiceRoutes, </span></pre>
<pre class="csharpcode"><span class="kwrd">Version=1.0.0.0, Culture=neutral&quot;</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">routes</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">routingExtention</span><span class="kwrd">&gt;</span></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>If you need more services, just keep adding into the routes collection with more add elements.<br />
  <br />Next part of the config change, is to enable the ASP.NET Compatability. This is important for the sample to work.</p>
<p></p>
<pre class="csharpcode">  <span class="kwrd">&lt;</span><span class="html">system.serviceModel</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">serviceHostingEnvironment</span> <span class="attr">aspNetCompatibilityEnabled</span><span class="kwrd">=&quot;true&quot;</span> <span class="kwrd">/&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">system.serviceModel</span><span class="kwrd">&gt;</span></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>That’s it!</p>
<h2>Benefits</h2>
<p>There are multiple benefits from this sample.</p>
<ul>
<li>Service Routing are configured, not compiled in code. </li>
<li>Services does no longer require an empty constructor. </li>
<li>Services supports dependency injection. </li>
<li>WCF Services works fine together with ASP.NET MVC.</li>
</ul>
<p>And that’s basically it, I hope you enjoy this for your own projects.</p>
<h2>Source Code</h2>
<p>You can download a fully working sample here: <a href="http://sondreb.com/pub/ConfigurableServiceRoutes_20110609.zip" target="_blank">ConfigurableServiceRoutes.zip</a></p>
<p>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.</p>
<h2>Notes of caution</h2>
<p>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!</p>
]]></content:encoded>
			<wfw:commentRss>http://sondreb.com/blog/post/configurable-service-routes.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Database Provider Factories: EF + SQL Compact</title>
		<link>http://sondreb.com/blog/post/database-provider-factories-ef-sql-compact.aspx</link>
		<comments>http://sondreb.com/blog/post/database-provider-factories-ef-sql-compact.aspx#comments</comments>
		<pubDate>Sun, 22 May 2011 13:42:44 +0000</pubDate>
		<dc:creator>SondreB</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[SQL Compact]]></category>

		<guid isPermaLink="false">http://sondreb.com/blog/?p=421</guid>
		<description><![CDATA[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, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sondreb.com/blog/wp-content/uploads/2011/05/database.png"><img class="alignright size-medium wp-image-427" title="database" alt="" src="http://sondreb.com/blog/wp-content/uploads/2011/05/database-300x300.png" width="300" height="300" /></a>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.</p>
<p>You have three option to install SQL Server Compact 4.0, using the <a href="http://www.microsoft.com/web/downloads/platform.aspx" target="_blank">Web Platform Installer</a>, <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=033cfb76-5382-44fb-bc7e-b3c8174832e2" target="_blank">direct download</a>, or you can add it as a <a href="http://www.nuget.org/" target="_blank">NuGet package</a>. I would suggest using the NuGet option, as that includes the required files with your source code. Make sure you <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=dda9dc83-f59a-4eca-b792-dd1d9629b6e7" target="_blank">get the documentation</a> as well.</p>
<p>SqlServerCompact package: <a href="http://nuget.org/List/Packages/SqlServerCompact" target="_blank">http://nuget.org/List/Packages/SqlServerCompact</a></p>
<p>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, <a href="http://nuget.org/List/Packages/EntityFramework.SqlServerCompact" target="_blank">EntityFramework.SqlServerCompact</a>.</p>
<p>The SqlServerCompact package will try to modify your web.config/app.config with the following keys:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">configuration</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">system.data</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">DbProviderFactories</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">remove</span> <span class="attr">invariant</span><span class="kwrd">=&quot;System.Data.SqlServerCe.4.0&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;Microsoft SQL Server Compact Data Provider 4.0&quot;</span> </pre>
<pre class="csharpcode"><span class="attr">  invariant</span><span class="kwrd">=&quot;System.Data.SqlServerCe.4.0&quot;</span> </pre>
<pre class="csharpcode"><span class="attr"></span><span class="attr">  description</span><span class="kwrd">=&quot;.NET Framework Data Provider for Microsoft SQL Server Compact&quot;</span> </pre>
<pre class="csharpcode"><span class="attr">  type</span><span class="kwrd">=&quot;System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, </span></pre>
<pre class="csharpcode"><span class="kwrd">  Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91&quot;</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">DbProviderFactories</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">system.data</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">configuration</span><span class="kwrd">&gt;</span></pre>
<p>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.</p>
<p>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:</p>
<pre class="csharpcode"><span class="kwrd">using</span> System.Data.Entity;
<span class="kwrd">using</span> System.Data.Entity.Infrastructure;

[assembly: WebActivator.PreApplicationStartMethod(</pre>
<pre class="csharpcode"><span class="kwrd">typeof</span>(InTheBoks.Test.Integration.App_Start.EntityFramework_SqlServerCompact), </pre>
<pre class="csharpcode"><span class="str">&quot;Start&quot;</span>)]

<span class="kwrd">namespace</span> InTheBoks.Test.Integration.App_Start {
    <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> EntityFramework_SqlServerCompact {
        <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> Start() {
            Database.DefaultConnectionFactory = </pre>
<pre class="csharpcode">              <span class="kwrd">new</span> SqlCeConnectionFactory(<span class="str">&quot;System.Data.SqlServerCe.4.0&quot;</span>);
        }
    }
}</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<pre>&#160;</pre>
<p>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.</p>
<p>The default connection factory is <strong>SqlConnectionFactory</strong>. 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 <strong>SqlCeConnectionFactory</strong>.</p>
<p>To investigate what the default configuration is, I had to access a list of factories using the API: <strong>DbProviderFactories.GetFactoryClasses()</strong>. 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&#8217;t install using the manual or Web Platform Installer &#8211; 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.</p>
<h2>Reference Table for DbProviderFactory Classes.</h2>
<table width="567">
<tbody>
<tr>
<th>Name</th>
<th>Description</th>
<th>Invariant</th>
</tr>
<tr>
<td>Odbc Data Provider</td>
<td>.Net Framework Data Provider for Odbc</td>
<td>System.Data.Odbc</td>
</tr>
<tr>
<td><strong>Type</strong></td>
<td colspan="2">System.Data.Odbc.OdbcFactory, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</td>
</tr>
<tr>
<td>OleDb Data Provider</td>
<td>.Net Framework Data Provider for OleDb</td>
<td>System.Data.OleDb</td>
</tr>
<tr>
<td><strong>Type</strong></td>
<td colspan="2">System.Data.OleDb.OleDbFactory, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</td>
</tr>
<tr>
<td>OracleClient Data Provider</td>
<td>.Net Framework Data Provider for Oracle</td>
<td>System.Data.OracleClient</td>
</tr>
<tr>
<td><strong>Type</strong></td>
<td colspan="2">System.Data.OracleClient.OracleClientFactory, System.Data.OracleClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</td>
</tr>
<tr>
<td>SqlClient Data Provider</td>
<td>.Net Framework Data Provider for SqlServer</td>
<td>System.Data.SqlClient</td>
</tr>
<tr>
<td><strong>Type</strong></td>
<td colspan="2">System.Data.SqlClient.SqlClientFactory, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</td>
</tr>
<tr>
<td>Microsoft SQL Server Compact Data Provider</td>
<td>.NET Framework Data Provider for Microsoft SQL Server Compact</td>
<td>System.Data.SqlServerCe.3.5</td>
</tr>
<tr>
<td><strong>Type</strong></td>
<td colspan="2">System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91</td>
</tr>
<tr>
<td><a href="http://system.data.sqlite.org" target="_blank">SQLite Data Provider</a></td>
<td>.Net Framework Data Provider for SQLite</td>
<td>System.Data.SQLite</td>
</tr>
<tr>
<td><strong>Type</strong></td>
<td colspan="2">System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139</td>
</tr>
<tr>
<td>Microsoft SQL Server Compact Data Provider 4.0</td>
<td>.NET Framework Data Provider for Microsoft SQL Server Compact</td>
<td>System.Data.SqlServerCe.4.0</td>
</tr>
<tr>
<td><strong>Type</strong></td>
<td colspan="2">System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91</td>
</tr>
</tbody>
</table>
<p>(Foto by <a href="http://www.flickr.com/photos/timothymorgan/75294154/" target="_blank">Tim Morgan</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://sondreb.com/blog/post/database-provider-factories-ef-sql-compact.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>InTheBoks v2 Preview</title>
		<link>http://sondreb.com/blog/post/intheboks-v2-preview.aspx</link>
		<comments>http://sondreb.com/blog/post/intheboks-v2-preview.aspx#comments</comments>
		<pubDate>Sat, 21 May 2011 20:36:15 +0000</pubDate>
		<dc:creator>SondreB</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[InTheBoks]]></category>

		<guid isPermaLink="false">http://sondreb.com/blog/?p=415</guid>
		<description><![CDATA[I&#8217;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 [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently working hard on the next version of InTheBoks. I wrote about it <a href="http://sondreb.com/blog/post/boks-organize-your-stuff.aspx" target="_blank">earlier on my blog</a>, at which time I built it using Silverlight.</p>
<p>New version is being built entirely on HTML 5 and is using the latest of technologies available.</p>
<p>Here is a video preview of the new version, which demonstrates how I&#8217;m using AJAX to call the REST API to delete items in your movie catalog.</p>
<p><object width="480" height="390"><param name="movie" value="http://www.youtube.com/v/lLq7B4YKwLU?fs=1&amp;hl=en_US&amp;rel=0&amp;hd=1" /><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><embed type="application/x-shockwave-flash" width="480" height="390" src="http://www.youtube.com/v/lLq7B4YKwLU?fs=1&amp;hl=en_US&amp;rel=0&amp;hd=1" allowfullscreen="true" allowscriptaccess="always"></embed></object></p>
<p>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.</p>
<p>Technologies and libraries in use:</p>
<ul>
<li>Entity Framework 4.1 RTW (Code First)</li>
<li>SQL Server Compact Edition 4</li>
<li>ASP.NET MVC 3 (Razor syntax)</li>
<li>WCF 4 REST</li>
<li>jQuery</li>
<li>jQuery UI</li>
<li>jQuery Templating</li>
<li>Knockout JS</li>
<li>Facebook SDK</li>
</ul>
<p>You can follow the progress on the Facebook page: <a href="http://www.facebook.com/InTheBoks">http://www.facebook.com/InTheBoks</a></p>
<p>Remember to also check out the official website where the new version will be released, hopefully sometime in 2011.</p>
<p><a href="http://www.intheboks.com/">http://www.intheboks.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sondreb.com/blog/post/intheboks-v2-preview.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Try Windows Azure for free</title>
		<link>http://sondreb.com/blog/post/try-windows-azure-for-free.aspx</link>
		<comments>http://sondreb.com/blog/post/try-windows-azure-for-free.aspx#comments</comments>
		<pubDate>Fri, 06 May 2011 07:00:58 +0000</pubDate>
		<dc:creator>SondreB</dc:creator>
				<category><![CDATA[Cloud Computing]]></category>

		<guid isPermaLink="false">http://sondreb.com/blog/?p=408</guid>
		<description><![CDATA[You can now try out Windows Azure for free, without credit card. Head over to http://windowsazurepass.com/ and signup for a 30 day pass. This should get you started on developing cloud apps and you&#8217;ll quickly realize just how easy it is, if you already know how to develop web apps. Use the promotion code: CRMIKEA If you [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-409 alignright" style="margin-left: 6px; margin-right: 0px;" title="azureAdvert" src="http://sondreb.com/blog/wp-content/uploads/2011/05/azureAdvert.png" alt="" width="334" height="202" />You can now try out Windows Azure for free, without credit card. Head over to <a href="http://windowsazurepass.com/">http://windowsazurepass.com/</a> and signup for a 30 day pass. This should get you started on developing cloud apps and you&#8217;ll quickly realize just how easy it is, if you already know how to develop web apps.</p>
<p>Use the promotion code: <strong>CRMIKEA</strong></p>
<p>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: <a href="https://www.dataforeningen.no/cloud-computing.160488.no.html">https://www.dataforeningen.no/cloud-computing.160488.no.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sondreb.com/blog/post/try-windows-azure-for-free.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft Office 365</title>
		<link>http://sondreb.com/blog/post/microsoft-office-365.aspx</link>
		<comments>http://sondreb.com/blog/post/microsoft-office-365.aspx#comments</comments>
		<pubDate>Thu, 05 May 2011 12:31:52 +0000</pubDate>
		<dc:creator>SondreB</dc:creator>
				<category><![CDATA[Cloud Computing]]></category>

		<guid isPermaLink="false">http://sondreb.com/blog/?p=403</guid>
		<description><![CDATA[Microsoft is about to release it&#8217;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 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sondreb.com/blog/wp-content/uploads/2011/05/Microsoft_Office_365.png"><img class="alignleft size-medium wp-image-404" style="margin-left: 0px; margin-right: 10px;" title="Microsoft_Office_365" src="http://sondreb.com/blog/wp-content/uploads/2011/05/Microsoft_Office_365-300x96.png" alt="" width="300" height="96" /></a>Microsoft is about to release it&#8217;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.</p>
<p>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</p>
<p>Go and visit the website to <a href="http://www.microsoft.com/en-us/office365/online-software.aspx" target="_blank">signup for the beta</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://sondreb.com/blog/post/microsoft-office-365.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blogging with WordPress</title>
		<link>http://sondreb.com/blog/post/blogging-with-wordpress.aspx</link>
		<comments>http://sondreb.com/blog/post/blogging-with-wordpress.aspx#comments</comments>
		<pubDate>Sun, 06 Feb 2011 12:28:04 +0000</pubDate>
		<dc:creator>SondreB</dc:creator>
				<category><![CDATA[Digital Lifestyle]]></category>
		<category><![CDATA[Social Media]]></category>

		<guid isPermaLink="false">http://sondreb.com/blog/?p=394</guid>
		<description><![CDATA[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&#8217;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 [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-397" title="WordPress logo" src="http://sondreb.com/blog/wp-content/uploads/2011/02/wordpress-logo-hoz-rgb.png" alt="WordPress logo" width="499" height="113" /></p>
<p>Recently I started using <a href="http://wordpress.com/" target="_blank">WordPress</a> for my blogs and today I launched this blog on WordPress, and all my blogs will soon be running on WordPress. It&#8217;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.</p>
<p>Recently I have been using <a href="http://www.microsoft.com/web/webmatrix" target="_blank">Microsoft WebMatrix</a> for some of my web development needs and for all new WordPress site I&#8217;m building, I start out with WebMatrix. It&#8217;s simply the easiest and fastest way to get started building your own custom blogs on WordPress.</p>
<p>Unfortunlately the FeedBurner service doesn&#8217;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&#8217;t work, but the feed contained the full posts so it shouldn&#8217;t really matter much. The new feed URL will be <a href="http://sondreb.com/blog/feed">http://sondreb.com/blog/feed</a></p>
<p>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&#8217;ll be alright.</p>
<p>Until next time, you can take a look at my new front page which is also running on WordPress, <a href="http://sondreb.com/">sondreb.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://sondreb.com/blog/post/blogging-with-wordpress.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Doing Web Development Better Part 2</title>
		<link>http://sondreb.com/blog/post/doing-web-development-better-part-2.aspx</link>
		<comments>http://sondreb.com/blog/post/doing-web-development-better-part-2.aspx#comments</comments>
		<pubDate>Sun, 19 Dec 2010 18:47:39 +0000</pubDate>
		<dc:creator>SondreB</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sondreb.com/blog/post.aspx?id=3ca8b56b-dbeb-478e-a536-5e5ab8360d9d</guid>
		<description><![CDATA[Since last time, I have come further in the research on how to have more dynamic loading of entities using reflection and I’m displaying the different actions using partial views from my themes folder. That makes it possible for individual themes to override the layout of the generated pages. Current Status So the current status [...]]]></description>
			<content:encoded><![CDATA[<p>Since last time, I have come further in the research on how to have more dynamic loading of entities using reflection and I’m displaying the different actions using partial views from my themes folder. That makes it possible for individual themes to override the layout of the generated pages.</p>
<h2>Current Status</h2>
<p>So the current status is that I have fully dynamic rendering for list of items and details on individual items. I have not yet added support for editing. The end results of what I’m working on, might be somewhat similar to the <a href="http://weblogs.asp.net/scottgu/archive/2007/12/14/new-asp-net-dynamic-data-support.aspx" target="_blank">ASP.NET Dynamic Data</a> technology from Microsoft. It does scaffolding of your data automatically. The difference obviously will be that mine are built on ASP.NET Web Pages and next version of Entity Framework. Other than sharing some general concepts, there are no similarities between my code and ASP.NET Dynamic Data.</p>
<h2>Status Quo</h2>
<h4>Mikael Söderström made a good example on how you can combine Entity Framework and ASP.NET Web Pages, so I won’t bother doing the same. Check a bit down on this thread: <a href="http://forums.asp.net/t/1580303.aspx">http://forums.asp.net/t/1580303.aspx</a></h4>
<p>What I want to avoid is the specific repositories, I want a single repository that is dynamic and can handle any entity type. I also want to avoid any logic inside the .cshtml that relates to the creation/reading of the entities. His example is still decent for those who want to go the “new, old route” of doing web development with Web Matrix. I’m on a mission to simplify this pattern.</p>
<h2>Get Started</h2>
<p>What I want to show today is how to dynamically create an instance of your entity and return that from your database. Create a new empty WebMatrix website and start writing some code.</p>
<p>Before we begin, make sure you have the latest version of Microsoft WebMatrix, SQL Server Compact Edition and Entity Framework CTP.</p>
<p>First you need to go through the example by Mikael that I linked too earlier, but you can replace the GuestbookRepository.cs with the code below and the default.cshtml will be different as well.</p>
<p>1. Create a new interface and call it <strong>IEntity</strong>. Just keep this empty for now.</p>
<p>2. Create a new class and call it <strong>Repository</strong>. Copy the code below:</p>
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Collections.Generic;
<span class="kwrd">using</span> System.Linq;
<span class="kwrd">using</span> System.Web;
<span class="kwrd">using</span> System.Data.Entity;
<span class="kwrd">using</span> System.Web.Helpers;

<span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// Generic repository for all of your entity types.</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="kwrd">public</span> <span class="kwrd">class</span> Repository&lt;TContext&gt; <span class="kwrd">where</span> TContext : DbContext
{
    <span class="kwrd">private</span> TContext _context;
    <span class="kwrd">private</span> <span class="kwrd">string</span> _entityTypeName;
    <span class="kwrd">private</span> Type _entityType;

    <span class="kwrd">public</span> Repository(<span class="kwrd">string</span> entityTypeName)
    {
        _entityTypeName = entityTypeName;
    }

    <span class="kwrd">public</span> TContext Context
    {
        get
        {
            <span class="kwrd">if</span> (_context == <span class="kwrd">null</span>)
            {
                _context = CreateContext();
            }

            <span class="kwrd">return</span> _context;
        }
    }

    <span class="kwrd">private</span> TContext CreateContext()
    {
        _entityType = Type.GetType(_entityTypeName);

        <span class="rem">// Make sure that only IEntity objects are returned for security reasons. You don't want</span>
        <span class="rem">// code that allows users to initiate any objects on the server.</span>
        <span class="kwrd">if</span> (!_entityType.Implements(<span class="kwrd">typeof</span>(IEntity)))
        {
            <span class="kwrd">throw</span> <span class="kwrd">new</span> ApplicationException(<span class="str">&quot;The specified entity does not implement the required IEntity interface.&quot;</span>);
        }

        <span class="rem">// Create an instance of the DbContext.</span>
        var context = Activator.CreateInstance&lt;TContext&gt;();

        <span class="kwrd">return</span> context;
    }

    <span class="kwrd">private</span> dynamic GetSet()
    {
        <span class="rem">// Get an instance of the DbSet.</span>
        var set = Context.Set(_entityType);

        <span class="rem">// Load all the values.</span>
        set.Load();

        <span class="rem">// Get the query values.</span>
        <span class="kwrd">return</span> set.Local;
    }

    <span class="kwrd">public</span> <span class="kwrd">void</span> Load(IEntity entity)
    {

    }

    <span class="kwrd">public</span> <span class="kwrd">void</span> Add(IEntity entity)
    {

    }

    <span class="kwrd">public</span> dynamic LoadAll()
    {
        <span class="kwrd">return</span> GetSet();
    }

    <span class="kwrd">public</span> <span class="kwrd">void</span> Delete(IEntity entity)
    {

    }
}</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Unfortunately this code only does listing of all the entities, through the LoadAll method. In one of my later blog posts, I will provide example that does all the normal CRUD operations for your entities.</p>
<p>3. Create a new .cshtml file and call it what you want. Paste the following code into the new file:</p>
<pre class="csharpcode">@{
    <span class="kwrd">var</span> entityType = UrlData[0];
    <span class="kwrd">var</span> action = UrlData[1];
    <span class="kwrd">var</span> id = UrlData[2];

    <span class="kwrd">if</span> (<span class="kwrd">string</span>.IsNullOrEmpty(entityType))
    {
        Response.Write(<span class="str">&quot;There is nothing to see here... - Jim Carrey, \&quot;Lifeguard on Duty\&quot;&quot;</span>);
        Response.End();
    }

    <span class="kwrd">var</span> repository = <span class="kwrd">new</span> Repository&lt;BlogCatalog&gt;(entityType);
    <span class="kwrd">var</span> result = repository.LoadAll();
    Page.Model = result;

    <span class="kwrd">var</span> grid = <span class="kwrd">new</span> WebGrid(Page.Model);
}

@grid.GetHtml()</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>The code has been simplified a bit, it doesn’t handle multiple types of listing. The “BlogCatalog” is the DbContext you created in the example by Mikael. Change that to whatever your own context is named.</p>
<p>Screenshot of the end result, this is the listing of my Author table.</p>
<p><img style="display: inline" title="Result" alt="Result" src="http://sondreb.com/blog/files/Windows-Live-Writer/Doing-Web-Development-Better-Part-2/38021C7D/Result.png" width="498" height="240" /></p>
<h2>The Beginning of By Convention</h2>
<p>That’s the early beginning of the framework that will make it even easier and better to develop web apps using Microsoft WebMatrix and ASP.NET Web Pages. The combination of ASP.NET Web Pages with Entity Framework and doing the code by convention, gives us a powerful tool where we avoid duplicate code and we don’t have to repeat yourselves too often.</p>
]]></content:encoded>
			<wfw:commentRss>http://sondreb.com/blog/post/doing-web-development-better-part-2.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Doing Web Development Better Part 1</title>
		<link>http://sondreb.com/blog/post/doing-web-development-better-part-1.aspx</link>
		<comments>http://sondreb.com/blog/post/doing-web-development-better-part-1.aspx#comments</comments>
		<pubDate>Mon, 13 Dec 2010 21:45:58 +0000</pubDate>
		<dc:creator>SondreB</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sondreb.com/blog/post.aspx?id=fbef539b-60d5-44b9-9abb-059ed753a29f</guid>
		<description><![CDATA[For a while now, I have been developing my own blogging framework using Microsoft WebMatrix and ASP.NET Web Pages. As these technologies are still in beta releases, I’m not prepared to release any beta version of my own blogging framework. What I would like to do, is share some of my experience writing the web [...]]]></description>
			<content:encoded><![CDATA[<p>For a while now, I have been developing my own blogging framework using <a href="http://www.microsoft.com/web/webmatrix/" target="_blank">Microsoft WebMatrix</a> and ASP.NET Web Pages. As these technologies are still in beta releases, I’m not prepared to release any beta version of my own blogging framework. What I would like to do, is share some of my experience writing the web app on this new platform. This is the first post in a series where I will explain some of my experience and hopefully give some pointers and hints.</p>
<h2>In The Beginning</h2>
<p>Initially I was amazed with the incredible speed and power of the ASP.NET Web Pages Razor syntax and the Microsoft WebMatrix editor, in combination with the new IIS Express. Modifications was super quick to do, no compilation involved, it just worked and it rendered fast. I started out prototyping the web app and wrote lots of code inside the .cshtml files. Even included SQL code straight in the view files, this was the beginning of web development for me when I started out on classic ASP (Active Server Pages). After a while, I moved most of my SQL queries into classes that I kept in my App_Code folder. The Microsoft Data Helpers relied heavily upon the new dynamic type. All methods returned just a dynamic type, which I initially consider to be great and powerful, I could easily extend my types with any additional properties.</p>
<p>It was both easy and powerful to build my web app in this manner, but as my web app kept growing I realized I needed to make some improvements. From early on, I made a very conscious decision to not rely on any ORM (Object Relational Mapping). I didn’t want the requirement to compile or generate any code. Generated code is always bad. So there was no LINQ to SQL or Entity Framework for me… but that was until…</p>
<h2>A New Beginning</h2>
<p>… Microsoft released a CTP (Customer Technology Preview) for the next version of Entity Framework (EF). And off I went refactoring my code into relying on the Code-First capabilities of EF CTP. Instead of manually writing my SQL scripts, which I had done up until now, I relied on the Entity Framework to generate my tables automatically. Instead of writing SQL statements, I now wrote entity types, just simple Plain Old CLR Objects (POCO). For me, it’s much more natural to write simple C# objects than SQL statements and I get better type safety which avoids some bugs, but obviously removes the benefits of working with dynamic types as I did earlier.</p>
<p>Here is a typical example of one of my earlier entity types:</p>
<p><img style="display: inline" title="Author" alt="Author" src="http://sondreb.com/blog/files/Windows-Live-Writer/0a40b3098c73/1C2DB3A7/Author.png" width="403" height="400" /></p>
<p>As I continued with my refactoring, a pattern started to emerge in my code base. I had my entity types, I had my catalog objects (DbContext), I had my static helper methods for all my entities and I still had a bunch of logic inside my .cshtml files to handle new elements, editing of existing elements, deletion of elements, validation of the model (user input) and often some other parts, such as the notification text to display when a save succeeded.</p>
<p>I started thinking that this is pointless, no developer should ever be put to write tedious repetitive code. I have lots of entities that I need the standard CRUD (Create, Read, Update, Delete) actions for and there is no chance I’m willingly going to write every single page for all of my entities. There is not legacy database, no legacy object types and no legacy requirement of any sort in my blogging framework, so I figured it was time to do more by-convention.</p>
<h2>Don’t Repeat Yourself</h2>
<p>So I started out thinking about how I could avoid repeating myself. I needed a convention for URLs, I came up with this current solution, will possibly change in the future, but for now it sticks:</p>
<p>http://url/Admin/EntityTypeName/View/FriendlyNameOrId</p>
<p>One example then, would be for the authors:</p>
<p>http://url/Admin/Author/View/admin</p>
<p>The type of actions I added was View, Edit, Delete, Create. View was planned to be used in the future if I add permission control that disabled the ability to edit the entity, but it’s not used much in the administration interface. Some of the guidance from REST is added here, but not all the concepts. The Delete action is only possible to do when you do a POST (or HTTP DELETE).</p>
<p>Here is a really simple example on how you can get the 3 input values from the URLs. All you have to do is create an Admin.cshtml file and then the above URL pattern will work just fine. UrlData won’t throw exceptions when you try to access index values that doesn’t exists, so there is no need to validate before you read the URL input.</p>
<p><img style="display: inline" title="Url" alt="Url" src="http://sondreb.com/blog/files/Windows-Live-Writer/0a40b3098c73/3B042785/Url.png" width="253" height="172" /></p>
<h2>Final Thoughts</h2>
<p>One obvious question would be why I didn’t choose to do this in ASP.NET MVC 3? It already supports the HTTP verbs, good separation of views, models, etc. The simple answer is that I think ASP.NET Web Pages in combination with WebMatrix is simpler and I wanted to do this project to learn the new technologies. I’m already doing lots of ASP.NET MVC development on my daily job, so this was a fun experience to learn something new.</p>
<p>I’m currently researching how I can automate the views for all my entities, by configuration or simply by reflecting over my DbContexts? Right now, I’m investigating with reflection over my DbContext types, I’ll keep you updated in the next part on this blog series.</p>
]]></content:encoded>
			<wfw:commentRss>http://sondreb.com/blog/post/doing-web-development-better-part-1.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Like A Girl</title>
		<link>http://sondreb.com/blog/post/code-like-a-girl.aspx</link>
		<comments>http://sondreb.com/blog/post/code-like-a-girl.aspx#comments</comments>
		<pubDate>Wed, 08 Sep 2010 11:01:45 +0000</pubDate>
		<dc:creator>SondreB</dc:creator>
				<category><![CDATA[Complexity]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://sondreb.com/blog/post.aspx?id=29c9da3d-b345-4ee0-b117-84e5f06d701c</guid>
		<description><![CDATA[It’s a well established fact that our industry (software development) has a majority of male programmers. I think it’s important that we all promote the software engineering field towards girls, ensuring the future will have a higher percentage of girls who write code. Today, the majority of software are developed by 20+ year old boys [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sondreb.com/blog/files/WindowsLiveWriter/CodeLikeAGirl/6FD12289/code_like_a_girl.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="code_like_a_girl" border="0" alt="code_like_a_girl" align="right" src="http://sondreb.com/blog/files/WindowsLiveWriter/CodeLikeAGirl/462D3189/code_like_a_girl_thumb.jpg" width="180" height="240" /></a></p>
<p>It’s a well established fact that our industry (software development) has a majority of male programmers. I think it’s important that we all promote the software engineering field towards girls, ensuring the future will have a higher percentage of girls who write code.</p>
<p>Today, the majority of software are developed by 20+ year old boys who develops software used by approx. 50% female users, often at twice the age of the developers. It’s one of the root causes of a lot of user frustration.</p>
<h2>Writing Beautiful Code</h2>
<p>Software developers care to little about beauty and elegance. We often stretch ourselves towards writing good unit tests and follow established object oriented best-practices. But we rarely think about how to make our architecture, design and code look beautiful. It’s not exactly in our nature, sort of speak.</p>
<p>As you can read in the excellent post on the same topic on the <a href="http://headrush.typepad.com/creating_passionate_users/2006/03/code_like_a_gir.html" target="_blank">Creating Passionate Users blog</a>:</p>
<p class="quote">“Because caring about things like beauty makes us better programmers and engineers. We make better things. Things that aren&#8217;t just functional, but easy to read, elegantly maintainable, easier&#8211;and more joyful&#8211;to use, and sometimes flat-out sexy. “</p>
<p>We should never forget that we rarely look at our own code more than once or twice, but eventually the code we write will be read by many others. It’s important to always recognize this fact and position ourselves in the minds of our fellow programmer.</p>
<h2>Simplicity and Beauty</h2>
<p>One of my mantra’s whenever I communicate with people through presentations and in my daily job, is to focus on simplicity. Making things simple is important, as a means to reduce complexity and improve communication.</p>
<p>Though it’s important to not forget about beauty and making things beautiful is similarly as hard as making things simple.</p>
<p>If you achieve simplicity and beauty you will be successful.</p>
<p>So from now on, try more to <strong>Code Like A <font color="#ff00ff">Girl</font></strong>!</p>
<p>(<em>This post is not meant to be sexist in any way, it’s a natural fact that females have a genetic advantage on beauty, one which we can learn from.</em>)</p>
<p>Get your Code Like A Girl stuff from <a href="http://www.zazzle.com/code+like+a+girl+gifts">http://www.zazzle.com/code+like+a+girl+gifts</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://sondreb.com/blog/post/code-like-a-girl.aspx/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simplifying Text Resources in Silverlight</title>
		<link>http://sondreb.com/blog/post/simplifying-text-resources-in-silverlight.aspx</link>
		<comments>http://sondreb.com/blog/post/simplifying-text-resources-in-silverlight.aspx#comments</comments>
		<pubDate>Sun, 15 Aug 2010 13:54:08 +0000</pubDate>
		<dc:creator>SondreB</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sondreb.com/blog/post.aspx?id=4383b068-01b4-420f-884c-1976556be96b</guid>
		<description><![CDATA[Here is how you can simplify the way you work with resources in Silverlight 4. The normal procedure to bind against resources is writing an binding statement in the .Content or .Text property of your elements. I will explain how you can use a dependency property to extend your Silverlight controls with an Resource.Key (ResourceKey) [...]]]></description>
			<content:encoded><![CDATA[<p>Here is how you can simplify the way you work with resources in Silverlight 4. The normal procedure to bind against resources is writing an binding statement in the .Content or .Text property of your elements. I will explain how you can use a dependency property to extend your Silverlight controls with an Resource.Key (<em>ResourceKey</em>) property and one for Resource.Tooltip.</p>
<p>The sample also includes a way to <strong>enable live language switching</strong> in your application, enabling the user to see language-change effects in real-time without restarting the application.</p>
<h2>Markup differences</h2>
<p>The binding syntax in XAML is somewhat awkward and it uses a lot of bracket ({&#160; }). I wanted to avoid this and make it cleaner and more understandable. Have a look at this example on how you normally bind the content of a button to a static resource, which should be your generated resources class that the .resx file generates.</p>
<pre>Content=&quot;{Binding About, Source={StaticResource Resources}}&quot;</pre>
<p>What this does is bind against the resource property About. You register the Resources property in your App.xaml file like this.</p>
<pre>&lt;resources:ApplicationStrings x:Key=&quot;Resources&quot; /&gt;</pre>
<p>What we want to do instead, is a syntax like the following example.</p>
<pre>cirium:Resource.Key=&quot;About&quot;</pre>
<p>This is obviously much cleaner and communicates better than the first example. Resource.Key is a dependency property defines in the <a href="http://cirium.net/" target="_blank">Cirium Application Framework</a>. You don’t need to use Cirium to achieve this behavior, I have included the source-code below.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="SimplifyResources_source" border="0" alt="SimplifyResources_source" src="http://sondreb.com/blog/files/WindowsLiveWriter/SilverlightResourceKey/7A3847DB/SimplifyResources_source.png" width="634" height="349" /></p>
<h2>What’s the catch?</h2>
<p>Obviously there are some small issues. The current implementation does not support resource text with format parameters (eg. <em>“Welcome {0}”</em>), I’m considering adding this in a future update.</p>
<p><strong>Important:</strong> For this behavior and sample to work, you are<strong> required to modify the generated code-behind</strong> for your .resx file. You need to modify the constructor of your class and <strong>make it public</strong>, by default it becomes internal. You also need to modify the class to be partial, for the auto-magic update of all bindings to work properly. If you don’t do this, you can’t register your resource directly in the App.xaml.</p>
<p>You also need to manually add support for any controls I have not added in the dependency property class, currently it supports Button, TextBlock, TextBox and CheckBox. If you use any Silverlight Toolkit/SDK controls, you need to modify to specify which dependency property to bind against.</p>
<h2>How does it work?</h2>
<p>There is a simple class named Resource that handles the binding of controls with your resources. It’s important to notice that we use binding of the property instead of just setting the content directly from the resource. You might want to reconsider changing this if your application is not going to support multiple languages, but mine required to support multiple languages and be able to dynamically and quickly change between them without restarting the application or reloading the views.</p>
<p>There is one single requirement and that is that you register all your resources in the applications static resources collection under the name “Resources”. You can obviously change this in the class file as you see fit for your own project. Here is a screenshot that shows the sample application running, with localized content and tooltip.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="SimplifyResources_screenshot" border="0" alt="SimplifyResources_screenshot" src="http://sondreb.com/blog/files/WindowsLiveWriter/SilverlightResourceKey/70FC0C9A/SimplifyResources_screenshot.png" width="420" height="220" /></p>
<h2>Enabling your project for localization</h2>
<p>When I first starting localizing my Silverlight application I was surprised how hard it was to figure it all out. It’s not enough to simply add the different .resx files to your project, you need to manually (even in Silverlight 4 with Visual Studio 2010) edit your project file with the proper languages you want to support. Unload your project, edit the content of it, locate the SupportedCulture XML element and add the languages you want to support. This example is for English and Norwegian.</p>
<pre>&lt;SupportedCultures&gt;en-US;nb-NO&lt;/SupportedCultures&gt;</pre>
<p>To add multiple languages to your application, start by adding one .resx file to your project if you don’t have one. Fill it out with some values. Copy the .resx file to the same location in your project, and rename by adding the language (culture) code before the .resx file-ending. E.g. ApplicationStrings.nb-NO.resx or ApplicationStrings.en-US.resx.</p>
<p><strong>Tip:</strong> You can localize the Out-of-browser settings by making multiple OUtOfBrowserSettings.xml files, just name them in the same way as your .resx files.</p>
<p><strong>Tip:</strong> You can disable the code generation for your extra languages, Visual Studio won’t generate any content in your code-behind when you have multiple languages, only for the main language, so disabling the code generation in the extra .resx files will avoid generating empty files in your project.</p>
<h2>Source Code</h2>
<p>Below is the source code, it’s a simple working application in Silverlight 4, configured to run out-of-browser. It’s important to notice that you need to manually configure SupportedCultures if you need more languages than what’s in the sample.</p>
<p><font size="4">Download the </font><a href="http://sondreb.com/pub/SimplifyResources.zip" target="_blank"><font size="4">SimplifyResources sample project</font></a><font size="4">.</font></p>
<p>Here is the full source-code of the Resource.cs:</p>
<p>namespace SimplifyResources<br />
  <br />{</p>
<p>&#160;&#160;&#160; using System.Windows;</p>
<p>&#160;&#160;&#160; using System.Windows.Controls;</p>
<p>&#160;&#160;&#160; using System.Windows.Data;</p>
<p>&#160;&#160;&#160; using System;</p>
<p>&#160;&#160;&#160; public static class Resource<br />
  <br />&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// &lt;summary&gt;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// A dependency property for attaching a resource key to the element.</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// &lt;/summary&gt;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public static readonly DependencyProperty KeyProperty =</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DependencyProperty.RegisterAttached(</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &quot;Key&quot;,</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; typeof(string),</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; typeof(string),</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; new PropertyMetadata(OnKeyChanged)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; );</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public static string GetKey(DependencyObject obj)<br />
  <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return (string)obj.GetValue(KeyProperty);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public static void SetKey(DependencyObject obj, string value)<br />
  <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; obj.SetValue(KeyProperty, value);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// &lt;summary&gt;<br />
  <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// A dependency property for attaching a resource key to the element used in the tooltip.</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// &lt;/summary&gt;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public static readonly DependencyProperty TooltipProperty =</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DependencyProperty.RegisterAttached(</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &quot;Tooltip&quot;,</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; typeof(string),</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; typeof(string),</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; new PropertyMetadata(OnTooltipChanged)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; );</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public static string GetTooltip(DependencyObject obj)<br />
  <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return (string)obj.GetValue(TooltipProperty);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public static void SetTooltip(DependencyObject obj, string value)<br />
  <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; obj.SetValue(TooltipProperty, value);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; private static void OnKeyChanged(DependencyObject targetLocation, DependencyPropertyChangedEventArgs args)<br />
  <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SetupBinding(targetLocation, args, false);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; private static void OnTooltipChanged(DependencyObject targetLocation, DependencyPropertyChangedEventArgs args)<br />
  <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SetupBinding(targetLocation, args, true);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; private static void SetupBinding(DependencyObject targetLocation, DependencyPropertyChangedEventArgs args, bool isTooltip)<br />
  <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (args.OldValue == args.NewValue) return;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; FrameworkElement element = targetLocation as FrameworkElement;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (element == null)<br />
  <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; throw new Exception(&quot;Resource.Key can only be set on framework elements.&quot;);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Load the resources source from the application&#8217;s StaticResources collection.<br />
  <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // This will only work if you have added it to your App.xaml.</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var dataSource = Application.Current.Resources[&quot;Resources&quot;];</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Binding binding = new Binding((string)args.NewValue);<br />
  <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; binding.Source = dataSource;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (isTooltip)<br />
  <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; element.SetBinding(ToolTipService.ToolTipProperty, binding);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; element.SetBinding(FindDependencyProperty(element), binding);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; private static DependencyProperty FindDependencyProperty(DependencyObject control)<br />
  <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DependencyProperty property = null;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (control is Button)<br />
  <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; property = Button.ContentProperty;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else if (control is TextBlock)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; property = TextBlock.TextProperty;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else if (control is TextBox)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; property = TextBox.TextProperty;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else if (control is CheckBox)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; property = CheckBox.ContentProperty;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return property;<br />
  <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160; }</p>
<p>}</p>
<p></p>
<h2>Notes</h2>
<p>If you get exception similar to this one, you need to modify the generated resources class.</p>
<p><em>No matching constructor found on type &#8216;SimplifyResources.Assets.Resources.ApplicationStrings&#8217;. [Line: 9 Position: 46]</em></p>
]]></content:encoded>
			<wfw:commentRss>http://sondreb.com/blog/post/simplifying-text-resources-in-silverlight.aspx/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Trying to understand Microsoft.Data.dll</title>
		<link>http://sondreb.com/blog/post/trying-to-understand-microsoft-data-dll.aspx</link>
		<comments>http://sondreb.com/blog/post/trying-to-understand-microsoft-data-dll.aspx#comments</comments>
		<pubDate>Tue, 10 Aug 2010 19:00:00 +0000</pubDate>
		<dc:creator>SondreB</dc:creator>
				<category><![CDATA[Complexity]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Software Patterns]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://sondreb.com/blog/post.aspx?id=e0c0436e-019b-4c5e-827f-1a2cdb1a0ea4</guid>
		<description><![CDATA[Here is my analysis of the recently &#8220;released&#8221; (embedded) Microsoft.Data.dll assembly, the namespace and the types it includes. It&#8217;s been the topic of a lot of heated debate recently, with viewpoints I&#8217;m unable to relate to and understand just from reading, so I needed to understand. The debate is stemming from a blog post by [...]]]></description>
			<content:encoded><![CDATA[<p>
Here is my analysis of the recently &ldquo;released&rdquo; (embedded) Microsoft.Data.dll assembly, the namespace and the types it includes. It&rsquo;s been the topic of a lot of heated debate recently, with viewpoints I&rsquo;m unable to relate to and understand just from reading, so I needed to understand.
</p>
<p>
The debate is stemming from a <a href="http://weblogs.asp.net/davidfowler/archive/2010/08/02/introduction-to-microsoft-data-dll.aspx" target="_blank">blog post by David Fowler</a> and his example that shows how some data-related tasks have a simpler syntax with Microsoft.Data and the ASP.NET WebPages with Razor Syntax.
</p>
<h2>What is inside the Microsoft.Data namespace?</h2>
<p>
There is very little code inside the namespace and the assembly. It&rsquo;s simply some helper types that makes life&#39;s a little bit easier. It&rsquo;s not a new data access framework, like Linq to SQL or Entity Framework.
</p>
<p>
It contains the following classes: ConfigurationManagerWrapper, ConfigurationConfiguration, <strong>Database</strong>, DbProviderFactoryWrapper, <strong>DynamicRecord</strong>, IConfigurationManager, IDbFileHandler, IDbProviderFactory, SqlCeDBFileHandler and SqlServerDbFileHandler. Of which only Database and DynamicRecord are public available, the others are internal.
</p>
<p>
All data access inside the Microsoft.Data types are using the <strong>common ADO.NET types</strong>, not the providers specific for any SQL platform. This means it&rsquo;s not restricted to SQL Compact Edition nor SQL Server. It relies on DbConnection, DbTransaction, DataTable, etc.
</p>
<h2>Microsoft.Data on ASP.NET Web Forms</h2>
<p>
While Microsoft.Data.dll is currently not accessible in the Add References dialog, you can find it by looking on your computer, it&rsquo;s located in the Global Assembly Cache (GAC). Microsoft probably don&rsquo;t want us to use it outside of WebMatrix in the current release&hellip; but if you just take a copy of the assembly out of the GAC, then you can reference the assembly in any .NET project and it will load it from the GAC (you just need the file so you can add a reference).
</p>
<p>
In my project I added a database to my App_Data folder (which you normally would never do, unless you are working with a local read-only cache in a large-distributed system or working with SQL Compact Edition) and added the following code to my web form, to make it render the Name column of my Users table.
</p>
<blockquote>
<pre>
	var db = Database.OpenFile(&quot;Database1.mdf&quot;);
	var users = db.Query(&quot;SELECT Id, Name FROM Users&quot;);
	foreach (var user in users)
	{
	Response.Write(user[&quot;Name&quot;]);
	}
	</pre>
</blockquote>
<p>
Take notice of the OpenFile parameter, it&rsquo;s simply the filename on disk. I don&rsquo;t have to care about any specific details of the connection string, nor how to figure out where the App_Data folder is.
</p>
<p>
Obviously though, if you added an entity framework (EF) model of your database, you would have very similar example to achieve the same and you don&rsquo;t have to care about the connection string, at least not in theory.
</p>
<blockquote>
<pre>
	using (var db = new Database1Entities())
	{
	var users = db.Users;
	foreach (var user in users)
	{
	Response.Write(user.Name);
	}
	}
	</pre>
</blockquote>
<p>
The two big distinctions betweens these examples is that the <strong>first one is dynamic</strong>, I can modify the database schema whenever I want and it won&rsquo;t (necessarily) break my web app, while the latter example with EF will need to refresh the entity types based on the database model.
</p>
<p>
The other distinctions is that the first example <strong>doesn&rsquo;t require a connection string</strong>, while the latter generates one for you automatically, a rather cryptic looking one.
</p>
<pre>
&lt;add name=&quot;Database1Entities&quot; connectionString=&quot;metadata=
</pre>
<pre>
res://*/Model1.csdl|
</pre>
<pre>
res://*/Model1.ssdl|
</pre>
<pre>
res://*/Model1.msl;
</pre>
<pre>
provider=System.Data.SqlClient;
</pre>
<pre>
provider connection string=&amp;quot;
</pre>
<pre>
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;
</pre>
<pre>
Integrated Security=True;
</pre>
<pre>
User Instance=True;
</pre>
<pre>
MultipleActiveResultSets=True&amp;quot;&quot; providerName=&quot;System.Data.EntityClient&quot; /&gt;
</pre>
<p>
&nbsp;
</p>
<p>
While all of this are peanuts for me and anyone who&rsquo;s been developing on .NET for a while, I think that making things simple where possible is positive, rather than negative. It doesn&rsquo;t mean we will stop using NHibernate, do proper n-tier and layered architectures just because Microsoft makes some tasks simpler for beginners. It also means some of us probably will eventually have to maintain and possibly migrate solutions built on Microsoft WebMatrix, but does that give us any right to restrict beginners the privilege of building their own solutions and feeling the immense joy of <strong>realizing their dreams</strong>?
</p>
<h2>Other&rsquo;s feedback and comments</h2>
<p>
Ayende Rahien <a href="http://ayende.com/Blog/archive/2010/08/03/microsoft.data-because-the-90s-were-so-good-we-want-to.aspx" target="_blank">comments on his blog</a> on the example, where he mentions the use Response.Write within the loop. Understandable this is probably not the best way to do this, but it&rsquo;s understandable with the sample in question, which was already using Response.Write. There are slightly better examples available out there. He also points out that having the SQL queries directly in the view code is an open invitation for SQL injection. Using proper <strong>parameterized queries will reduce this potential security</strong> problem. Looks like David updated the sample to use parameters after the initial reactions. After the security push at Microsoft some years back, they really cleaned up their practices with examples in the MSDN documentations, I think we should expect the same level of security thinking on employee blogs as well.
</p>
<p>
Ayende quotes David, which (David) made the assumption that Microsoft.Data is tied to Sql Server in any way, which my investigations has shown is <strong>not correct</strong>.
</p>
<p>
<a href="http://weblogs.asp.net/davidfowler/archive/2010/08/04/dynamic-linq-a-little-more-dynamic.aspx" target="_blank">David tried to respond</a> to some of the feedback on embedding SQL directly in the view, with hacking around to get the new dynamic keyword to work properly with LINQ. To me, this defeats the whole purpose of simplicity with Microsoft WebMatrix, Razor and Microsoft.Data.
</p>
<p>
<a href="http://huagati.blogspot.com/" target="_blank">KristoferA</a> comments on the post and suggests generating Linq to SQL datacontext using a page-level directive, which would essentially give the developer entity objects to work with (and query against). This again defeats the purpose of simplicity, and now you can no longer change the database scheme without &ldquo;recompiling&rdquo; your web-app.
</p>
<p>
The namespace naming is another sour point for some, and I can agree that there is little point is &ldquo;abusing&rdquo; the Microsoft.Data namespace for such a trivial little helper, perhaps <a href="http://twitter.com/DomRibaut/status/20832610230" target="_blank">Microsoft.WebMatrix.Data</a> or Microsoft.Data.Connection?
</p>
<h2>Who is this for?</h2>
<p>
Microsoft WebMatrix (and ASP.NET WebPages) is not a tool built for &ldquo;professional&rdquo; programmers, additionally is it not a fully generic framework for building everything. It&rsquo;s a domain specific language that is optimized for building simple web applications without to much resources.
</p>
<p>
It is not meant for enterprise applications that handles millions of transactions. Will it be used for that? Yes, it probably will! We&rsquo;ve seen plenty of classic examples of websites that starts with simple web-frameworks and find themselves in big trouble when their services become popular. Services like Twitter and Facebook was not built to scale to their current levels, yet they started as simple concepts and services and has grown to become important services which affects global policies and real-life social interactions.
</p>
<p>
It&#39;s Not Rocket Science, But It&#39;s Our Work: <a href="http://blog.twitter.com/2008/05/its-not-rocket-science-but-its-our-work.html">http://blog.twitter.com/2008/05/its-not-rocket-science-but-its-our-work.html</a>
</p>
<p>
And obviously, it&rsquo;s for those of us who still miss the old days with ASP Classic, here is a pretty good (and funny) read, <a href="http://www.packtpub.com/article/Classic-ASP" target="_blank">8 Reasons to Stick with ASP 3.0 in 2006 (and 2007).</a>
</p>
<h2>Final thoughts</h2>
<p>
It&rsquo;s very clear that Microsoft WebMatrix (and related technologies) are primarily is focused towards beginners and it&rsquo;s a great tool to build simple websites. I wouldn&rsquo;t advice anyone to use this if you already know ASP.NET MVC and want to build complex web solutions, ASP.NET Web Forms, MVC or other more general purpose frameworks would probably be more fit.
</p>
<p>
Additionally I think it&rsquo;s important to remember that WebMatrix is primarily focused on SQL Compact Edition for data access, the built in editor doesn&rsquo;t allow you to modify SQL Server database. So the question (and response to some of the comments) is how many layers do you want to wrap your data access logic for a SQLCE database?
</p>
<p>
Been a while since Microsoft did a push towards simplifying development for beginners, when we went from VB6 to VB.NET, everything was more complex and the entry level for VB.NET is on-par with C#. With the release of .NET Framework 4, the complexity and total amount of features is mind blowing. I for sure welcome tools, languages and frameworks that simplifies how we develop software.
</p>
<p>
Simplicity is hard and it&#39;s something we should strive towards in all that we do.</p>
]]></content:encoded>
			<wfw:commentRss>http://sondreb.com/blog/post/trying-to-understand-microsoft-data-dll.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unity as IoC container for Caliburn.Micro</title>
		<link>http://sondreb.com/blog/post/unity-as-ioc-container-for-caliburn-micro.aspx</link>
		<comments>http://sondreb.com/blog/post/unity-as-ioc-container-for-caliburn-micro.aspx#comments</comments>
		<pubDate>Thu, 08 Jul 2010 09:06:27 +0000</pubDate>
		<dc:creator>SondreB</dc:creator>
				<category><![CDATA[Complexity]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://sondreb.com/blog/post.aspx?id=5bf54cbd-ef71-41fe-a43a-3e62d34f0a5d</guid>
		<description><![CDATA[You might have heard about Caliburn, a client framework for WPF and Silverlight. Caliburn is a very rich and featured framework, as a consequence of this the, the great programmer Rob Eisenberg have reset the full Caliburn with a new and fresh one, named Caliburn.Micro. Caliburn.Micro is smaller, more lightweight and it has a lot [...]]]></description>
			<content:encoded><![CDATA[<p>You might have heard about <a href="http://caliburn.codeplex.com/" target="_blank">Caliburn</a>, a client framework for WPF and Silverlight. Caliburn is a very rich and featured framework, as a consequence of this the, the great programmer Rob Eisenberg have reset the full Caliburn with a new and fresh one, named <a href="http://caliburnmicro.codeplex.com/" target="_blank">Caliburn.Micro</a>.</p>
<p>Caliburn.Micro is smaller, more lightweight and it has a lot of good features that I think are useful when building rich applications for WPF, Silverlight and Windows Phone 7.</p>
<p>Caliburn.Micro have a focus on convention, meaning that it will automate a lot of the tedious tasks you normally have to do when you’re applying design patterns such as Model-View-ViewModel (MVVM, Presentation Model). Actions (commanding) can be achieved simply by naming your ViewModel operations with the same name as your Buttons and other action-controls in the View.</p>
<p>This new framework can reduce the complexity of your applications and make them cleaner and more adaptable to change in the future. Reducing complexity should always be one of the top priorities when building software.</p>
<p>(<strong>Note:</strong> <em>The content of this article will probably become outdated as the <a href="http://caliburnmicro.codeplex.com/documentation" target="_blank">Caliburn.Micro documentation</a> is updated, though at the current time this is the only known example of IoC with Caliburn.Micro</em>)</p>
<p>(<strong>Note July 9th 2010:</strong> As expected, Rob Eisenberg has updated the Caliburn.Micro documentation with an <a href="http://caliburnmicro.codeplex.com/wikipage?title=Customizing%20The%20Bootstrapper&amp;referringTitle=Documentation" target="_blank">bootstrapper which uses MEF</a>. If you’re a MEF-kind-of-programmer, check it out. I would still advice on using the Common Service Locator in the bootstrapper as oppose to directly working with the MEF-types. I don’t like binding my types to a specific IoC container, which you are with the MEF-attributes on your types and properties. With some IoC frameworks, you can simply use any custom interface and have your objects injected using Dependency Injection) </p>
<h2>Inversion of Control</h2>
<p>Inversion of Control is a pattern which helps separate the responsibility of creating objects from the classes which uses them. This can greatly enhance the way you can build a modular application which easier supports replacing existing logic and makes testing a whole lot simpler.</p>
<p>To learn more about IoC, see <a title="http://msdn.microsoft.com/en-us/library/ff647976.aspx" href="http://msdn.microsoft.com/en-us/library/ff647976.aspx">http://msdn.microsoft.com/en-us/library/ff647976.aspx</a></p>
<h2>Building Caliburn.Micro</h2>
<p>At the present time, there is no binary release of Caliburn.Micro available. You have to download the source code and compile it yourself using Visual Studio 2010. Head on over to CodePlex to get the source, <a title="http://caliburnmicro.codeplex.com/SourceControl/list/changesets" href="http://caliburnmicro.codeplex.com/SourceControl/list/changesets">http://caliburnmicro.codeplex.com/SourceControl/list/changesets</a></p>
<p>Caliburn.Micro is released under the MIT license, which means you can basically do almost anything you want with the source, even include it in your own product which is not open source. When you open the Caliburn.Micro solution file, you’ll see three projects, one for Silverlight, one for WPF and a last one for Windows Phone 7 (WP7).</p>
<h2>Downloading Unity</h2>
<p>Before you can continue to add IoC support for your WPF application, you need to download your favorite IoC framework. My favorite is Autofac, but for this demo I’m using Unity which is developed by the Microsoft patterns &amp; practices group. Get the latest release from <a title="http://unity.codeplex.com/" href="http://unity.codeplex.com/">http://unity.codeplex.com/</a></p>
<h2>Creating a new WPF project</h2>
<p>Go ahead and create a new WPF project or open any existing project you might have. First step is to add reference to the following assemblies: Caliburn.Micro, System.Windows.Interactivity (included with Caliburn.Micro and my sample download at the bottom), Microsoft.Practices.Unity and finally the Microsoft.Practices.ServiceLocation. The ServiceLocation assembly is a <a href="http://commonservicelocator.codeplex.com/" target="_blank">common service locator</a> assembly that has been built to provide a unified interface for all IoC frameworks.</p>
<p>Next you should follow the example in the documentation for Caliburn.Micro, it explains how to get the basic application up and working, see <a title="http://caliburnmicro.codeplex.com/wikipage?title=Basic%20Configuration%2c%20Actions%20and%20Conventions&amp;referringTitle=Documentation" href="http://caliburnmicro.codeplex.com/wikipage?title=Basic%20Configuration%2c%20Actions%20and%20Conventions&amp;referringTitle=Documentation">http://caliburnmicro.codeplex.com/wikipage?title=Basic%20Configuration%2c%20Actions%20and%20Conventions&amp;referringTitle=Documentation</a></p>
<h2>Creating a Container</h2>
<p>If you got your basic application up and running with an empty bootstrapper, it’s time to create your IoC container. Create a new class in your project and name it Container. Create a single method can call it Build, returning IServiceLocator (found in the Microsoft.Practices.ServiceLocation namespace). This makes it possible for you to reuse this container type across other third party libraries which happen to play nice and supports the Common Service Locator.</p>
<pre>&#160;&#160;&#160; public IServiceLocator Build()&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160; IUnityContainer unity = new UnityContainer();

&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Register our services.&#160;&#160;&#160;&#160;&#160;&#160;&#160; unity.RegisterType&lt;IFileService, FileService&gt;();

&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Register all the ViewModels in our project.&#160;&#160;&#160;&#160;&#160;&#160;&#160; foreach (Type t in typeof(ViewModel).Assembly.GetTypes())&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (typeof(ViewModel).IsAssignableFrom(t))&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; unity.RegisterType(t);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Return an type which implements the Common Service Locator interface.&#160;&#160;&#160;&#160;&#160;&#160;&#160; UnityServiceLocator commonLocator = new UnityServiceLocator(unity);&#160;&#160;&#160;&#160;&#160;&#160;&#160; return commonLocator;&#160;&#160;&#160; }</pre>
<h2>Finishing the Bootstrapper</h2>
<p>If you followed the example on the Caliburn.Micro site, you should have a empty bootstrapper. I called mine ClientBootstrap and it loads my ShellViewModel as the root element.</p>
<p>There are four operations you need to override to add your custom IoC container, they are Configure, BuildUp, GetAllInstances and GetInstance. If your Container class returns an IServiceLocator, you already have similar methods available. The only thing missing is the BuildUp. Unfortunlately there are no operation in the Common Service Locator interface for BuildUp, so either you have to revert to returning the IUnityContainer from your Build operation, or you might make it without the BuildUp override.</p>
<p>This is how my bootstrapper ends up looking.</p>
<pre>&#160;&#160;&#160; public class ClientBootstrap : Bootstrapper&lt;ShellViewModel&gt;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160; IServiceLocator _container;

&#160;&#160;&#160;&#160;&#160;&#160;&#160; protected override void Configure()&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Container container = new Container();&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _container = container.Build();&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160; protected override void BuildUp(object instance)&#160;&#160;&#160;&#160;&#160;&#160;&#160; {}

&#160;&#160;&#160;&#160;&#160;&#160;&#160; protected override IEnumerable&lt;object&gt; GetAllInstances(Type service)&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return _container.GetAllInstances(service);&#160;&#160;&#160;&#160;&#160;&#160;&#160; }

&#160;&#160;&#160;&#160;&#160;&#160;&#160; protected override object GetInstance(Type service, string key)&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return _container.GetInstance(service, key);&#160;&#160;&#160;&#160;&#160;&#160;&#160; }&#160;&#160;&#160; }</pre>
<h2>Source Code</h2>
<p>You can download the <a href="http://sondreb.com/pub/FlickrDownloadrSample.zip" target="_blank">sample source code here</a>. This sample is named “Flickr Downloadr” for the simple reason that I’m rewriting my popular photo download utility to WPF4, check out the existing version at <a href="http://flickrdownloadr.codeplex.com/">http://flickrdownloadr.codeplex.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sondreb.com/blog/post/unity-as-ioc-container-for-caliburn-micro.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>View Model Loading by Convention</title>
		<link>http://sondreb.com/blog/post/view-model-loading-by-convention.aspx</link>
		<comments>http://sondreb.com/blog/post/view-model-loading-by-convention.aspx#comments</comments>
		<pubDate>Sun, 20 Jun 2010 12:51:55 +0000</pubDate>
		<dc:creator>SondreB</dc:creator>
				<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://sondreb.com/blog/post.aspx?id=af41b305-6025-44d3-b37f-ff74b2a021e7</guid>
		<description><![CDATA[Following up on my previous post on how you can achieve no code-behind for your WPF or Silverlight application, I will explain one possible way of doing view model instantiation using any Inversion of Control container and using a naming convention to do it automatically. MVVM Project Structure One of the first things you learn [...]]]></description>
			<content:encoded><![CDATA[<p>Following up on my previous post on how you can achieve <a href="http://sondreb.com/blog/post/No-Code-Behind-for-MVVM.aspx" target="_blank">no code-behind</a> for your WPF or Silverlight application, I will explain one possible way of doing view model instantiation using any Inversion of Control container and using a naming convention to do it automatically.</p>
<h2>MVVM Project Structure</h2>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="InTheBoks_structure" border="0" alt="InTheBoks_structure" align="right" src="http://sondreb.com/blog/files/WindowsLiveWriter/ViewModelLoadingbyConvention/2699B974/InTheBoks_structure.png" width="211" height="544" />One of the first things you learn when searching for training material on MVVM in the context of Silverlight and WPF, is that many developers tends to chunk all their View Models and Views into a single project folder. This might work for a small project that has a minimal set of views, but for any bigger projects this will quickly become a mess so my advice is to avoid it altogether, you never know if your project will expand beyond your initial plans.</p>
<p>Either create a root-folder for all of your functional areas, or create a root-folder that contains all your features. I like to use the convention of a folder named simple “Features”. Within this folder, I create another folder for each distinct functional area of my app. Each functional feature can easily contain one or multiple views and view models.</p>
<p>On the right you can see an screenshot of the current structure for my InTheBoks project, where the ViewBase.cs from my previous blog post is stored under a Framework section.</p>
<p>With this structure, your View (e.g. MainView.xaml) and your View Model (e.g. MainViewModel.cs) will end up under the same .NET namespace, which is important when we want to load the view model by-convention.</p>
<p>What does by-convention mean? It’s simply figuring out the full type-name for the view model by following a defined project structure where we no longer need to manually connect the view and the view model.</p>
<h2>Expanding the ViewBase</h2>
<p>It’s time to expand the ViewBase we first defined in my previous post on <a href="http://sondreb.com/blog/post/No-Code-Behind-for-MVVM.aspx" target="_blank">No Code-Behind for MVVM</a>. Inside the constructor of my PageView, UserControlView, WindowView (WPF) and ChildWindowView (SL), I set the DataContext with a call to an ViewBaseHelper class. This is done right after the InitializeComponent has been called using reflection.</p>
<pre>DataContext = ViewBaseHelper.Instance.LoadViewModel(GetType());</pre>
<p>The full source for my ViewBaseHelper is of course included in the sample download at the bottom, but here is the essential part that tries to load your View Model automagically:</p>
<pre>internal object LoadViewModel(Type viewType){&#160;&#160;&#160; if (viewType == null)&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160; return null;&#160;&#160;&#160; }

&#160;&#160;&#160; var viewModelTypeName = viewType.AssemblyQualifiedName.Replace(viewType.FullName, viewType.FullName + &quot;Model&quot;);

&#160;&#160;&#160; var viewModelType = Type.GetType(viewModelTypeName);

&#160;&#160;&#160; if (viewModelType == null)&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160; return null;&#160;&#160;&#160; }

&#160;&#160;&#160; return Container.Resolve(viewModelType);}</pre>
<p>In my example code I have relied upon Autofac as my choice for <a href="http://www.martinfowler.com/articles/injection.html" target="_blank">Inversion of Control container</a>. The code that handles dependency injection is fairly small and can easily be replaced with an alternative IoC container.</p>
<h2>What about design-time?</h2>
<p>The method I’ve explained for convention based view model loading doesn’t work for design-time, which fortunately we have a solution for.</p>
<p>While this method does break somewhat with the idea of not directly binding the view to any view model type, this is only for design time and it can be very useful as you have a finer degree of control on which type you bind your view against and how you want it to be initialized.</p>
<p>All you need to do is add an d: element (which is ignore during compilation) which specifies the view model type and whether you want to create an actual instance of the VM or not. Here is an example from my MainView. First you need to import the namespace on which the view model is located and then set the d:DataContext attribute. IsDesignTimeCreatable is used to indicate if you want an object instance of the VM type.</p>
<pre>xmlns:Feature=&quot;clr-namespace:InTheBoks.Features.Main&quot;d:DataContext=&quot;{d:DesignInstance Type=Feature:MainViewModel, IsDesignTimeCreatable=True}&quot;</pre>
<p>asd</p>
<h2>Create new Feature</h2>
<p>One of the additional things I’ve done for InTheBoks, is to create templates for new features which creates the view and the view model with proper inheritance, namespace imports, and design-time binding. To do this yourself, simply add the correct .zip file with your template items in the following folder: </p>
<p>\Visual Studio 2010\Templates\ItemTemplates\Silverlight</p>
<p>I won’t go into further detail on this today, though this is a good thing to do if you’re working on a big project that has many views. This is how it can look when you customize your items with icons and illustrations.</p>
<p><a href="http://sondreb.com/blog/files/WindowsLiveWriter/ViewModelLoadingbyConvention/297EF85A/InTheBoks_feature.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" class="wlDisabledImage" title="InTheBoks_feature" border="0" alt="InTheBoks_feature" src="http://sondreb.com/blog/files/WindowsLiveWriter/ViewModelLoadingbyConvention/58DD4159/InTheBoks_feature_thumb.png" width="640" height="371" /></a></p>
<h2>Download the Source Code</h2>
<p>While my previous example was built around WPF, this new one is built using Silverlight. As this concept and code is built around InTheBoks, the name of the sample and the namespace is “InTheBoks”.</p>
<p>The sample doesn’t include any advanced MVVM-technologies such as commanding, only the one that is built into Silverlight 4 which is binding. For the purpose of clarity, I removed any other external dependency than Autofac.</p>
<p>Here is the download: <a href="http://sondreb.com/pub/InTheBoks-2010-06-20.zip" target="_blank">InTheBoks-2010-06-20.zip</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://sondreb.com/blog/post/view-model-loading-by-convention.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>No Code-Behind for MVVM</title>
		<link>http://sondreb.com/blog/post/no-code-behind-for-mvvm.aspx</link>
		<comments>http://sondreb.com/blog/post/no-code-behind-for-mvvm.aspx#comments</comments>
		<pubDate>Tue, 08 Jun 2010 14:55:55 +0000</pubDate>
		<dc:creator>SondreB</dc:creator>
				<category><![CDATA[Software Patterns]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://sondreb.com/blog/post.aspx?id=e432fa9b-381c-49da-a916-5fd793902570</guid>
		<description><![CDATA[One of the annoying things when you start working with Model-View-ViewModel in Windows Presentation Foundation (WPF) is the fact that you can’t just delete the code-behind file for your .xaml files. After discussing the problem with Peter Lillevold, he came up with a solution to our problem. Let’s first discuss the problem and then present [...]]]></description>
			<content:encoded><![CDATA[<p>One of the annoying things when you start working with Model-View-ViewModel in Windows Presentation Foundation (WPF) is the fact that you can’t just delete the code-behind file for your .xaml files.</p>
<p>After discussing the problem with <a href="http://twitter.com/occulto" target="_blank">Peter Lillevold</a>, he came up with a solution to our problem. Let’s first discuss the problem and then present the solution.</p>
<h2>Initialize Component</h2>
<p>When you look at a recently created XAML file, you’ll notice there is a call to the InitializeComponent in the constructor. This is an operation that is not available in the derived type (Window, Page, UserControl) nor is it directly visible in your project. Right-click on the method call and Go To Definition (F-12) opens an generated file you normally don’t see.</p>
<p>The operation is responsible for loading (initializing) the XAML which is embedded as a resource in your application binaries.</p>
<p>Example of a code-behind class:</p>
<pre>public partial class MainWindow : Window{&#160;&#160;&#160; public MainWindow()&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160; InitializeComponent();&#160;&#160;&#160; }}</pre>
<p>Unfortunately the XAML views require this call to InitializeComponent to function properly, if you go ahead and delete the code-behind file you’ll end up with an blank window/user control when they are loaded.</p>
<h2>View Base Types</h2>
<p>The solution is to provide a view-base for all your top-UI containers, such as Window, Page and UserControl. These view-base types can additionally be used to construct convention-based initialization of View Models in an MVVM-pattern implementation. This is beyond the scope of this post, might be visited in a future post.</p>
<p>Here is an example on how to do this for a Window view:</p>
<pre>public partial class WindowView : Window{&#160;&#160;&#160; public WindowView()&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160; var initializeComponentMethod = GetType().GetMethod(&quot;InitializeComponent&quot;, &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; BindingFlags.Public | BindingFlags.Instance);&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (initializeComponentMethod != null)&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; initializeComponentMethod.Invoke(this, new object[0]);&#160;&#160;&#160;&#160;&#160;&#160;&#160; }&#160;&#160;&#160; }}</pre>
<p>First we tries to get an reference to the current instance of the object, which will return the inherited type (for example “ExampleView” type as included in my sample source code). Then we validate if the method actually exists and if it does, we invoke the InitializeComponent method.</p>
<p>Next step is to change the XAML markup so you no longer use the framework type for Window, Page or UserControl, but instead your own custom base view types. At this point you can delete the code-behind of your XAML files, just make sure you don’t delete any existing logic that you might have in your code-behind.</p>
<p><strong>Side note:</strong> Having logic in code-behind is not a violation of good practices, even when you’re working with the MVVM (Presentation) pattern.</p>
<p>Open your XAML and add a statement that imports the CLR namespace where your view types are, e.g. </p>
<pre>xmlns:NoCodeBehind=&quot;clr-namespace:NoCodeBehind&quot;</pre>
<p>Then change the root-XML-element in your XAML markup file to e.g.</p>
<pre>&lt;NoCodeBehind:WindowView </pre>
<p>Note that the x:Class element on the root element dictates the name of your view, meaning your XAML file can be named something other than the generated type of the view.</p>
<h2>Example Source Code</h2>
<p>For a concrete example of this implementation in WPF and how you can avoid the code-behind file altogether is included below. The two examples are ExampleView.xaml and ExampleControl.xaml which both works without code-behind files.</p>
<p>Please use the example with caution and there are no guaranties that the workaround doesn’t change some behavior in your running application. Any feedback is welcome, please leave comments!</p>
<p>Download the <a href="http://sondreb.com/pub/NoCodeBehind.zip" target="_blank">NoCodeBehind example</a> in C#.</p>
]]></content:encoded>
			<wfw:commentRss>http://sondreb.com/blog/post/no-code-behind-for-mvvm.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Complexity that rules us all</title>
		<link>http://sondreb.com/blog/post/complexity-that-rules-us-all.aspx</link>
		<comments>http://sondreb.com/blog/post/complexity-that-rules-us-all.aspx#comments</comments>
		<pubDate>Thu, 20 May 2010 14:35:30 +0000</pubDate>
		<dc:creator>SondreB</dc:creator>
				<category><![CDATA[Complexity]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://sondreb.com/blog/post.aspx?id=84a217c7-e28d-45e4-8a65-6de438f92e1e</guid>
		<description><![CDATA[Complexity is the number one cause [1] of failures on IT-projects. It’s probably the number one reason for any type of project failure. Failed projects and bad software makes our customers and users unhappy. What are the reason we initiate IT-projects? It’s all about reducing complex problems to meaningful tasks that can be completed by [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sondreb.com/blog/files/WindowsLiveWriter/Complexitythatrulesusall/5C3083DE/4184803610_ca1bcc685c_o.jpg"><img style="border-bottom: 0px; border-left: 0px; margin: 0px 0px 10px 10px; display: inline; border-top: 0px; border-right: 0px" title="4184803610_ca1bcc685c_o" border="0" alt="4184803610_ca1bcc685c_o" align="right" src="http://sondreb.com/blog/files/WindowsLiveWriter/Complexitythatrulesusall/370313A5/4184803610_ca1bcc685c_o_thumb.jpg" width="400" height="225" /></a> Complexity is the number one cause [1] of failures on IT-projects. It’s probably the number one reason for any type of project failure. Failed projects and bad software makes our customers and <strong>users unhappy</strong>.</p>
<p>What are the reason we initiate IT-projects? It’s all about <strong>reducing complex problems</strong> to meaningful tasks that can be completed by humans.</p>
<h2>Law of Software</h2>
<p>Let’s focus on software development and what value software have for the users. Building software is what I and thousands of others are doing every single day, and we’re not exactly becoming better at what we’re doing, we’re actually only able to successfully complete aprox. 30% [2] of the projects that are initiated.</p>
<p>According to <a href="http://msdn.microsoft.com/en-us/magazine/ff646970.aspx" target="_blank">David S. Platt’s 3 Laws of Software</a>, the software we build have zero value in and of itself. It doesn’t matter how technically good your code is, the only individual who cares are you and your own mother.</p>
<p><strong>Platt’s 3 Law of Software</strong> [3] says the following:</p>
<p>1. Your software has <strong>zero value in and of itself</strong>. Only value it ever has is how it enhances the happiness of the user.</p>
<p>2. Software can <strong>increase users’ happiness</strong> in one of two ways. It can help a user accomplish a task that she wants done or it can give the user pleasure. Example: Outlook helps you read and write emails, HALO on the Xbox gives you pleasure and fun.</p>
<p>3. The <strong>users should not think</strong> about your computer program. At all. Ever.</p>
<p>(<em>Click the link above to read the full law, I’ve just included the highlights</em>)</p>
<h2>What is writing software?</h2>
<p>Writing software is the undertaking of understanding any arbitrary complex problem and writing software instructions to solve those complex problems.</p>
<p>The goal of writing software should be to <strong>reduce complex problems</strong> to <strong>simple tasks</strong>. Simple tasks that humans can initiate, often without requiring much need for thinking. The less the user is required to think, the happier and more productive they will be.</p>
<h2>Thinking simple</h2>
<p>When you have a complex problem you want to solve, what do we tend to use as mechanisms to solve them? It’s obviously not thinking in simple terms, this is pretty obvious when you look at the software we’re building.</p>
<p>As our understanding of a complex problem increases (as we work out the details of a software design), we can’t seem to be able to come up with simple solutions, we often take this route of thinking: Complex problems requires complex solutions.</p>
<p>This is wrong, and it’s the root cause of so many software project failures.</p>
<p>We need to <strong>start thinking simple</strong>. We need to figure out how we can reduce the complex details of a design, until we have an design and architecture that is as simple as possible and still delivers the value for our users.</p>
<p>Our goal should be: <strong>Least complex architecture possible</strong> [4].</p>
<p>There are many reasons why something ends up being complex, one important factor is the amount of functionality we put into our software. According to Robert L. Glass [5] in his book Facts and Fallacies of Software Engineering, the fact is as following, <strong>25% increase in functionality increases complexity by 100%</strong>.</p>
<p>Next time you are faced with a complex problem that someone wants to be solved using software, start by thinking about the users and how you can increase their happiness. Then start reducing the initial complex solution of the complex problem, into the most simple solution you can which still achieves the goal: <strong>Making your users happy!</strong></p>
<h2>References</h2>
<p>[1]: <a href="http://www.objectwatch.com/white_papers.htm#ITComplexity">http://www.objectwatch.com/white_papers.htm#ITComplexity</a></p>
<p>[2]: The CHAOS report by The Standish Group (<a href="http://www.standishgroup.com/">http://www.standishgroup.com/</a>)</p>
<p>[3]: <a title="http://msdn.microsoft.com/en-us/magazine/ff646970.aspx" href="http://msdn.microsoft.com/en-us/magazine/ff646970.aspx">http://msdn.microsoft.com/en-us/magazine/ff646970.aspx</a></p>
<p>[4]: <a href="http://sondreb.com/blog/post/MSDN-Live-Solution-Architecture-Slides.aspx">http://sondreb.com/blog/post/MSDN-Live-Solution-Architecture-Slides.aspx</a></p>
<p>[5] <a href="http://www.robertlglass.com/">http://www.robertlglass.com/</a></p>
<p>[Photo]: <a href="http://www.flickr.com/photos/kodomut/">http://www.flickr.com/photos/kodomut/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sondreb.com/blog/post/complexity-that-rules-us-all.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extending Authentication on Facebook SDK</title>
		<link>http://sondreb.com/blog/post/extending-authentication-on-facebook-sdk.aspx</link>
		<comments>http://sondreb.com/blog/post/extending-authentication-on-facebook-sdk.aspx#comments</comments>
		<pubDate>Mon, 17 May 2010 20:02:54 +0000</pubDate>
		<dc:creator>SondreB</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://sondreb.com/blog/post.aspx?id=92f15c51-6984-4a35-a47e-222c75304758</guid>
		<description><![CDATA[Using the Facebook Developer Toolkit (Facebook SDK), you can quickly get started building applications of any kind that integrates with the social networking service, Facebook. I’m currently using this for the coming version of InTheBoks, which will from now on use Facebook Connect for authentication. While working on this integration, I realized that the Facebook [...]]]></description>
			<content:encoded><![CDATA[<p>Using the Facebook Developer Toolkit (<a href="http://msdn.microsoft.com/en-us/windows/ee388574.aspx" target="_blank">Facebook SDK</a>), you can quickly get started building applications of any kind that integrates with the social networking service, Facebook.</p>
<p>I’m currently using this for the coming version of <a href="http://www.intheboks.com/" target="_blank">InTheBoks</a>, which will from now on use Facebook Connect for authentication. While working on this integration, I realized that the Facebook Developer Toolkit never raises any events back to the Silverlight application when it loads the first time and tries to look for a persistent cookie. Learn how you can extend the toolkit so you can improve the user experience of your Silverlight applications that integrates with Facebook.</p>
<p>This post does not describe how to get started with the Facebook Developer Toolkit and Silverlight, this is just a <strong>quick way you can improve the authentication processes with Silverlight</strong>.</p>
<h2>Requirements</h2>
<p>First you need to get the <a href="http://facebooktoolkit.codeplex.com/SourceControl/list/changesets" target="_blank">source code</a> for the Facebook Developer Toolkit. We need this so we can extend the <a href="http://facebooktoolkit.codeplex.com/SourceControl/changeset/view/50207#420706" target="_blank">BrowserSession.cs</a> file.</p>
<h2>BrowserSession</h2>
<p>Start by extending the BrowserSession class with an event handler and one method that will be executed from the fblogin.js JavaScript file. Since we are editing an existing framework, we don’t want to change any existing implementations of code so we’ll add an extra event handler like this:</p>
<p>public event EventHandler NotAuthenticated;</p>
<p>The next step is to add an method that is called from JavScript:</p>
<p>[ScriptableMember]   <br />public void NotLoggedIn()    <br />{    <br />&#160;&#160;&#160; if (NotAuthenticated != null)    <br />&#160;&#160;&#160; {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; NotAuthenticated(this, EventArgs.Empty);    <br />&#160;&#160;&#160; }    <br />}</p>
<p>fblogin.js</p>
<p>Open the fblogin.js file that is included with the Facebook Developer Toolkit and should be at the root of your web application that hosts your Silverlight app.</p>
<p>Find the function isUserConnected, which should look like this:</p>
<p>function isUserConnected() {   <br />&#160;&#160;&#160; FB.ensureInit(function () {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; FB.Connect.get_status().waitUntilReady(function (status) {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var plugin = document.getElementById(&#8216;_sl_facebookapp&#8217;);    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; facebook_getSession();    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; });    <br />&#160;&#160;&#160; });    <br />}</p>
<p>Replace the above function with this updated one:</p>
<p>function isUserConnected() { </p>
<p>&#160;&#160;&#160; FB.ensureInit(function () {   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; FB.Connect.get_status().waitUntilReady(function (status) { </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var plugin = document.getElementById(&#8216;_sl_facebookapp&#8217;); </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; switch (status) {   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; case FB.ConnectState.connected:    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; facebook_getSession();    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; break;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; case FB.ConnectState.appNotAuthorized:    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; case FB.ConnectState.userNotLoggedIn:    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; plugin.Content.FacebookLoginControl.NotLoggedIn();    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; });    <br />&#160;&#160;&#160; });    <br />}</p>
<p>That’s all you need to change to enable a way to get a callback when the JavaScript have checked if the user is authenticated or not.</p>
<h2>Notes on the UI</h2>
<p>With this additional event, you can now hook up to three events to update your UI. Here is the code from the constructor in my ViewModel.</p>
<p>_session = new BrowserSession(ApplicationKey, new Enums.ExtendedPermissions[] { Enums.ExtendedPermissions.offline_access });   <br />LoginButtonText = &quot;Loading&#8230;&quot;;    <br />_session.NotAuthenticated += new EventHandler(Session_NotAuthenticated);    <br />_session.LoginCompleted += new EventHandler&lt;System.ComponentModel.AsyncCompletedEventArgs&gt;(Session_LoginCompleted);    <br />_session.LogoutCompleted += new EventHandler&lt;System.ComponentModel.AsyncCompletedEventArgs&gt;(Session_LogoutCompleted);</p>
<p>I have a single HyperLinkButton that have it’s content bound to a string property named LoginButtonText. This is displaying “Loading…” when the app is loading, then depending on which event is raised, I change the LoginButtonText to “LOGIN” if the NotAuthenticated event is raised, “LOGOUT” if the LoginCompleted is raised and back again to “LOGIN” if the user logs out.</p>
]]></content:encoded>
			<wfw:commentRss>http://sondreb.com/blog/post/extending-authentication-on-facebook-sdk.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MSDN Live: Solution Architecture Slides</title>
		<link>http://sondreb.com/blog/post/msdn-live-solution-architecture-slides.aspx</link>
		<comments>http://sondreb.com/blog/post/msdn-live-solution-architecture-slides.aspx#comments</comments>
		<pubDate>Mon, 10 May 2010 08:14:52 +0000</pubDate>
		<dc:creator>SondreB</dc:creator>
				<category><![CDATA[Complexity]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sondreb.com/blog/post.aspx?id=1da6bc7d-ef3d-4147-8fbd-8eabe811f789</guid>
		<description><![CDATA[Here are the slides from my talk on Solution Architecture at MSDN Live in the spring of 2010. The slide decks alone isn&#8217;t enough to appreciate the presentation, so I have included all notes that was written for the presentation. This means you can read through the presentation and the points I made when delivering [...]]]></description>
			<content:encoded><![CDATA[<p>Here are the slides from my talk on Solution Architecture at MSDN Live in the spring of 2010. The slide decks alone isn&#8217;t enough to appreciate the presentation, so I have <strong>included all notes</strong> that was written for the presentation. This means you can read through the presentation and the points I made when delivering it in Stavanger, Bergen, Trondheim and Oslo. <a href="http://www.slideshare.net/SondreB/msdn-live-2010-solution-architecture/download">Download the full presentation</a> or watch below.</p>
</p>
<div style="width: 425px" id="__ss_4032379"><strong style="margin: 12px 0px 4px; display: block"><a title="MSDN Live 2010 - Solution Architecture" href="http://www.slideshare.net/SondreB/msdn-live-2010-solution-architecture">MSDN Live 2010 &#8211; Solution Architecture</a></strong><object id="__sse4032379" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=msdnlive2010-solutionarchitecture-100510030202-phpapp02&amp;stripped_title=msdn-live-2010-solution-architecture" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><embed name="__sse4032379" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=msdnlive2010-solutionarchitecture-100510030202-phpapp02&amp;stripped_title=msdn-live-2010-solution-architecture" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="padding-bottom: 12px; padding-left: 0px; padding-right: 0px; padding-top: 5px">More presentations by <a href="http://www.slideshare.net/SondreB">Sondre Bjellås</a>.</div>
</p></div>
<p>For more background on the presentation, also read <a href="http://sondreb.com/blog/post/MSDN-Live-Solution-Architecture.aspx">my blog post</a> that I wrote during the preparations. The final result is very different than I initially planned and I didn’t deliver what was promised in the agenda. I still hope the presentation gave enough value to those who attended and I hope it inspired to enable change and sparked a move towards simpler solutions with reduced complexity.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://sondreb.com/blog/post/msdn-live-solution-architecture-slides.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

