<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>planetgeek.ch</title>
	
	<link>http://www.planetgeek.ch</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sun, 05 Feb 2012 10:12:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/planetgeekch" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="planetgeekch" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>The future smells like JavaScript</title>
		<link>http://www.planetgeek.ch/2012/02/02/the-future-smells-like-javascript-2/</link>
		<comments>http://www.planetgeek.ch/2012/02/02/the-future-smells-like-javascript-2/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 20:46:56 +0000</pubDate>
		<dc:creator>jonas.bandi</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.planetgeek.ch/?p=3100</guid>
		<description><![CDATA[Of course I am only repeating what others are preaching about the recent rise of JavaScript. But I think the movement is significant and can&#8217;t be overstated. And recent developments are really even making it more and more interesting. Nobody can deny hat JavaScript is the de facto programming language of Html5. Every other language [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: left; width: 42px; padding-right: 10px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.planetgeek.ch/2012/02/02/the-future-smells-like-javascript-2/";
		var dzone_title = "The future smells like JavaScript";
		var dzone_style = "1";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><div class="separator" style="float: right;text-align: right">
<a href="http://en.wikipedia.org/wiki/JavaScript"><img border="0" src="http://3.bp.blogspot.com/-SYscWhKil2c/Tyl7VBWFEEI/AAAAAAAABJI/67C2IzYjHGg/s1600/js.jpg"  style="border: medium none" / rel="lightbox[roadtrip]"></a></div>
<p>Of course I am only <a href="http://davybrion.com/blog/2011/06/you-might-want-to-start-taking-javascript-seriously/">repeating what others</a> are preaching about the recent <a href="http://dannorth.net/2011/12/19/the-rise-and-rise-of-javascript/">rise of JavaScript</a>.</p>
<p>But I think the movement is significant and can&#8217;t be overstated. And recent developments are really even making it more and more interesting.</p>
<p>Nobody can deny hat <a href="http://en.wikipedia.org/wiki/JavaScript">JavaScript</a> is the de facto programming language of Html5. Every other language trying to bolt itself onto Html5 looks like pure friction so far. And Html5 is looking upon a prospering future.<span id="more-3100"></span></p>
<p>Today we are used to some established JavaScript frameworks that make working with JavaScript more fun and productive. <a href="http://jquery.com/">jQuery</a> seems to emerge as the clear leader by popularity here.</p>
<p>More recently<a href="http://codebrief.com/2012/01/the-top-10-javascript-mvc-frameworks-reviewed/"> tons of javascript application frameworks</a> (so called MVC frameworks) are emerging, that facilitate programming complex applications inside the browser and taking most of the traditional presentation-logic away from the server.</p>
<div class="separator" style="float: left">
<a href="http://nodejs.org/"><img border="0" height="100" src="http://2.bp.blogspot.com/-paluGXhk-8s/Tym6PfvGp9I/AAAAAAAABJY/Ehjgd7UWack/s320/nodejs.png"  style="border: none" width="220" / rel="lightbox[roadtrip]"></a></div>
<p>On the other hand we have the <a href="http://nodejs.org/">node.js</a> ecosystem that takes JavaScript to the server and allows us to use the same language, concepts, libraries and tools for the full application development stack.<br />
And that ecosystem is thriving! JavaScript is the <a href="https://github.com/languages">most popular langage on GitHub</a> &#8230; and have a look at the impressive <a href="https://github.com/joyent/node/wiki/modules">node modules list</a>.</p>
<p>Now this is all well and <a href="http://martinfowler.com/bliki/AlphaGeek.html">alpha-geeky</a>, but there are showing up the first &#8220;real-world&#8221; success stories: <a href="http://www.theregister.co.uk/2011/03/01/the_rise_and_rise_of_node_dot_js/">Voxer</a>, <a href="http://venturebeat.com/2012/01/24/why-walmart-is-using-node-js/">Walmart</a>, <a href="http://venturebeat.com/2011/08/16/linkedin-node/">LinkedIn</a> &#8230;</p>
<p>Of course there are <a href="http://teddziuba.com/2011/10/node-js-is-cancer.html">the critics</a>.</p>
<p>Surprisingly Microsoft recently positioned itself to become one of the most influencing conveyor of the JavaScript hype. It seems that they are investing heavily into JavaScript on different frontiers:</p>
<p>Microsoft was <a href="http://blog.nodejs.org/2011/06/23/porting-node-to-windows-with-microsoft%E2%80%99s-help/">pushing node.js onto the the Windows environment</a>.<br />
Now they are <a href="http://www.windowsazure.com/en-us/develop/nodejs/">pushing it into their Azure cloud platform</a>. And <a href="http://www.windowsazure.com/en-us/develop/nodejs/tutorials/deploying-with-cloud9/">evolving a 3rd party ecosystem around that</a>.</p>
<div class="separator" style="float: right;text-align: center">
<img border="0" height="120" src="http://4.bp.blogspot.com/-GyiFQw-SVLc/Tyl7te9DLfI/AAAAAAAABJQ/19iB-ne5kIE/s320/w8.jpg" style="border: none" width="200" /></div>
<p>But probably the biggest step for the future of JavaScript is the new strategy of Microsoft for <a href="http://en.wikipedia.org/wiki/Windows_8">Windows 8</a> desktop and tablet applications (Metro style apps). While there are several options for developing Metro style apps, <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465380.aspx">JavaScript seems to become a major pillar</a>.<br />
This opens up yet another area for JavaScript and JavaScript developers, completely adjacent to the web.<br />
Developing for the desktop (or tablet) will most likely always be pretty different than for the web. For Metro style apps there will be a lot of new concepts, libraries and tools that are different to the ones that are used in web development (just have a look at <a href="http://en.wikipedia.org/wiki/Windows_Runtime">WinRT</a>, <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465493.aspx">WinJS</a> &#8230;).<br />
But the desktop- and the web-stack will move closer together and JavaScript with HTML5 and CSS will be the common denominator. Which I think is a very interesting evolution.<br />
For instance look at this <a href="http://code.msdn.microsoft.com/windowsapps/Groove-Drum-Sequencer-cc6028ec">example of a drum sequencer</a> (a traditional client application) that is using JavaScript and jQuery for its UI.<br />
The prospect of reusing code and knowhow between desktop-ui- and web-ui-programming seems tempting &#8230; even if a lot of <a href="https://twitter.com/#%21/ursenzler/status/162793217425801216">.NET developers</a> and <a href="http://martinfowler.com/bliki/gotoAarhus2011.html">other gurus</a> are not so thrilled by the prospect of omnipresent JavaScript.</p>
<p>Of course another interesting thing will be to see how Metro style apps will change the architecture of future desktop applications. I think some concepts from web development will get adopted into desktop development. A stricter enforcement of separation between UI- and backend-components within a single application will most probably be a result (i.e. there seems to be no notion of traditional data-access in WinRT).</p>
<div style="color: #999999">
<span style="font-size: x-small"><br />
</span></div>
<div style="color: #444444">
<span style="font-size: x-small">PS: This is my first cross-post between <a href="http://blog.jonasbandi.net/">my blog</a> and <a href="http://www.planetgeek.ch/">planetgeek.ch</a>. Thanks <a href="https://twitter.com/#%21/danielmarbach">@danielmarbach</a> for inviting me.</span><br />
<span style="font-size: x-small"><br />
</span></div>
<div style="clear: right;font-size: 10px">
<a href="http://twitter.com/jbandi"><img align="left" alt="http://www.google.com/s2/favicons?domain=twitter.com" border="0" height="13px" src="http://www.google.com/s2/favicons?domain=twitter.com" style="border: 0 none;margin: 0px" />If you like this, follow me on twitter &#8230;</a></div>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.planetgeek.ch/2012/02/02/the-future-smells-like-javascript-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Client / Server Localization – Introduction</title>
		<link>http://www.planetgeek.ch/2012/01/25/client-server-localization-introduction/</link>
		<comments>http://www.planetgeek.ch/2012/01/25/client-server-localization-introduction/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 21:59:51 +0000</pubDate>
		<dc:creator>Daniel Marbach</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[bbv.Common]]></category>
		<category><![CDATA[Distributed Event Broker]]></category>
		<category><![CDATA[Localization]]></category>

		<guid isPermaLink="false">http://www.planetgeek.ch/?p=3065</guid>
		<description><![CDATA[This is the introduction posts about dynamic client / server localization which describes the problem domain. In one of my current projects, we are building a client / server application that uses windows communication foundation requests and responses and event driven data, which is fired over the distributed event broker. Some of the data is [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: left; width: 42px; padding-right: 10px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.planetgeek.ch/2012/01/25/client-server-localization-introduction/";
		var dzone_title = "Client / Server Localization &#8211; Introduction";
		var dzone_style = "1";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><p>This is the introduction posts about dynamic client / server localization which describes the problem domain. In one of my current projects, we are building a client / server application that uses windows communication foundation requests and responses and event driven data, which is fired over the <a title="Distributed Event Broker – Introduction" href="http://www.planetgeek.ch/2011/08/26/distributed-event-broker-introduction/">distributed event broker</a>. Some of the data is dynamically rendered on the client but needs to be translated into several languages. For information which is already known at compile time localization is really straight forward with WPF. But what about data which is not known at compile time of the client?</p>
<p><span id="more-3065"></span></p>
<p>To see the difference between localizible data which is known at compile time and dynamic data we need to look how static data can be localized in WPF. We use the <a href="http://wpflocalizeextension.codeplex.com/">WPF Localization Extension</a>. We just have to reference the localization extension and then we can define localizible data in the XAML like:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;Window x:Class=&quot;Product.Name.SomeView&quot;
        xmlns:l=&quot;http://schemas.root-project.org/xaml/presentation&quot;&gt;
	&lt;StackPanel Margin=&quot;10&quot;&gt;
        &lt;Label Content=&quot;{l:LocText Product.Name:Main:Label_UserName}&quot; /&gt;
		&lt;Button Content=&quot;{l:LocText Product.Name:Main:Button_Cancel}&quot; /&gt;
	&lt;/StackPanel&gt;
&lt;/Window&gt;
</pre>
<p>All we then have to do is to create a corresponding resource file <em>Main.resx</em> and its language equivalents (for example <em>Main.de-ch.resx</em>) which contains a key <em>Label_UserName</em> and a key <em>Button_Cancel</em>. The resource files get compiled into satellite assemblies and will be deployed with the client application. Whenever the user switches the language of the user interface the label and the button will contain localized information according to the selected language or text from the fallback resource (usually from the main resource file). So far so good. Let&#8217;s look into more advanced use cases.</p>
<p>Imagine we have the following WCF service which is used by the client:</p>
<pre class="brush: csharp; title: ; notranslate">
public interface IOrderService
{
	IEnumerable&lt;ValidationResult&gt; ValidateOrder(Order order);
}

[DataContract]
public class ValidationResult
{
	public ValidationResult(string message) {
		this.Message = message;
	}

	[DataMember]
	string Message { get; private set; }
}

public class OrderService : IOrderService
{
	public IEnumerable&lt;ValidationResult&gt; ValidateOrder(Order order) {
		return new[] { new ValidationResult(&quot;Unable to process order. Customer creditworthiness validation is pending!&quot;) };
	}
}
</pre>
<p>The server might have some business rules which are only known on the server side. The client needs to dynamically render validation results in case an order is not valid. We want to have the flexibility to extend the business validation rules without changing the client application. The sample above would always give back a validation result with an English message text. If the client language would be another than English this would have no influence onto the validation message.</p>
<p>What if the validation takes a lot of time and we want to inform the client about the validation process with an event over the distributed event broker.</p>
<pre class="brush: csharp; title: ; notranslate">
public interface IOrderService
{
	void ValidateOrder(Order order);
}

public class ValidatedEventArgs : EventArgs
{
	public ValidatedEventArgs(IEnumerable&lt;ValidationResult&gt; results) {
		this.Results = results;
	}

	public IEnumerable&lt;ValidationResult&gt; Results { get; private set; }
}

[DataContract]
public class ValidationResult
{
	public ValidationResult(string message) {
		this.Message = message;
	}

	[DataMember]
	string Message { get; private set; }
}

public class OrderService : IOrderService
{
	[EventPublication(&quot;distributed://OrderValidated&quot;, HandlerRestriction.Asynchronous)]
	public event EventHandler&lt;ValidatedEventArgs&gt; Validated = delegate { };

	public void ValidateOrder(Order order) {
		// start some asynchronous background task
		// immediately return to the client
		// when background task is finished, execute
		// this.OnValidated(new[] { new ValidationResult(&quot;Unable to process order. Customer creditworthiness validation is pending!&quot;) });
	}

	private void OnValidated(IEnumerable&lt;ValidationResult&gt; results) {
	     this.Validated(this, new ValidatedEventArgs(results));
	}
}
</pre>
<p>With this approach the client would also only retrieve untranslated validation results. In the next series of posts we are going into the nuts and bolts how a dynamic client / server validation can be achieved.</p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.planetgeek.ch/2012/01/25/client-server-localization-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Structure your code by feature</title>
		<link>http://www.planetgeek.ch/2012/01/25/3077/</link>
		<comments>http://www.planetgeek.ch/2012/01/25/3077/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 11:18:50 +0000</pubDate>
		<dc:creator>Urs Enzler</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Clean Code]]></category>
		<category><![CDATA[Methodology]]></category>
		<category><![CDATA[Test Driven Development]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://www.planetgeek.ch/?p=3077</guid>
		<description><![CDATA[cross-post from bbv blog When software projects grow both in age and size the developers often struggle with the structure of the code. It gets more and more difficult to find the class you have to change for a new requirement. In this post, I’ll show you how we organize our code and how we derive [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: left; width: 42px; padding-right: 10px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.planetgeek.ch/2012/01/25/3077/";
		var dzone_title = "Structure your code by feature";
		var dzone_style = "1";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><p><em>cross-post from <a title="bbv blog" href="http://www.bbv.ch/?p=704&amp;option=com_wordpress&amp;Itemid=173">bbv blog</a></em></p>
<p>When software projects grow both in age and size the developers often struggle with the structure of the code. It gets more and more difficult to find the class you have to change for a new requirement. In this post, I’ll show you how we organize our code and how we derive our structure directly from the requirements.</p>
<p><span id="more-3077"></span></p>
<p>When you look at example code from the internet or how some frameworks (e.g. ASP.NET MVC) structure their code, you see that they most likely organize the code by layer or put classes of the same kind in the same place.</p>
<p>For example in Model-View-ViewModel and ASP.NET MVC samples you will see namespaces/folders named <em>Views</em>, <em>ViewModels</em>, <em>Controllers</em>, <em>Entities</em>, <em>DataTransferObjects</em>, <em>Repositories</em> and so on.</p>
<p><strong>Layers they say!</strong></p>
<p>Now, we all were told that layers are good. Mainly because they simplify the code due to the fact that layers higher in the hierarchy are only allowed to access layers further down in the hierarchy. That’s okay, but has nothing to do with structuring code.</p>
<p><strong>Feature Features!</strong></p>
<p>I made the experience that structuring code by feature results in a much simpler layout. The main reason for this is that all the classes you are currently working on are physically near to each other despite their kind. The view, view-model and so on of the customer search are all in the same place: under the namespace <em>MyCompany.MyProduct.Customers.Search</em>. Thus minimizing navigation in the solution explorer (Visual Studio). Furthermore, these namespaces do not grow when the software grows, only the number of namespaces increases due to new features being implemented. Now when I have to look for a class then I start by looking up the feature it is needed in, go to this namespace and find it there.</p>
<p>The namespace per feature approach gives you some additional advantages:</p>
<ul>
<li>when a feature has to be removed you can “simply” remove the namespace as a whole and you do not have to search through all the layer based namespaces</li>
<li>the structure of your code reflects the features and not the technologies used (watch <a href="http://cleancoder.posterous.com/architecture-deference">Architecture Deference</a> to see why this is important)</li>
<li>refactoring namespaces (e.g. introducing sub-features) is simple because only the feature you are currently working on is affected</li>
</ul>
<p><strong>“But what about assemblies?”</strong></p>
<p>Remember that assemblies are used to deploy a program on a machine. If you have a client and a server you’ll need at least two assemblies, probably at least three because of shared code. But this is a completely different decision than structuring. When you split up your code into different assemblies to deploy to different sites, you should still use the same namespaces in these assemblies. Start with changing the default namespace in the project settings.</p>
<p><strong>Agile, Scrum, User Stories, Product Backlog and getting a structure by feature</strong></p>
<p>When you develop software in an Agile way and your requirements are given in the form of User Stories then deriving features and therefore namespaces is really simple.</p>
<ol>
<li>Identify the Themes in your Product Backlog  (see <a href="http://agile101.net/2009/08/10/the-difference-between-agile-themes-epics-and-user-stories/">Themes/Epics/User Stories</a>)</li>
<li>Per Theme introduce a namespace. E.g. <em>MyCompany.MyProduct.Theme1</em></li>
<li>Identify features within each Theme. Often these features are initially described by Epics. E.g. <em>searching</em>, <em>editing</em></li>
<li>Per identified feature introduce a namespace below the Theme: <em>MyCompany.MyProduct.Theme1.Feature1</em></li>
<li>When namespaces grow too big, introduce sub-namespaces according to sub-features. Always try to think in user actions and not in technological differences.</li>
</ol>
<p><strong>“But what about infrastructure code?”</strong></p>
<p>Yes, there is code that is used by several features. This code should be put into the existing namespace per feature hierarchy and not into its own. You got this right when you don’t need to add <em>using </em>statements into each code file (.Net,  <em>import </em>for Java).</p>
<p>Code shared by <em>MyCompany.MyProduct.Theme1.Searching </em>and <em>MyCompany.MyProduct.Theme1.Editing </em>should be in <em>MyCompany.MyProduct.Theme1.</em></p>
<p>“<strong>But my assemblies get really big! That slows me down because the time needed to build increases, especially when practicing Test Driven Development!”</strong></p>
<p>I develop software test driven. That means that I build my code and run tests every few seconds (I try at least). Build time gets very important. Additionally, Visual Studio and Resharper don’t reward you with good performance once a project reaches a certain size.</p>
<p>Therefore, assemblies need sometimes to be split up even if deployed at the same location.</p>
<p>When splitting assemblies you should consider the <a href="http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod">principles of package design</a> and you should split along feature/namespace boundaries. If you split by feature the code and the number of projects that have to be built to run a unit test is minimized; thus minimizing the time you have to wait for the test to run.</p>
<p><strong>“But the framework I use already dictates me to use namespaces like <em>view</em> or <em>viewmodel</em>!”</strong></p>
<p>You have two options: look for another framework or start with a namespace per feature inside the namespaces that were given by the framework. E.g. <em>MyCompany.MyProduct.View.Theme1.Feature1</em></p>
<p>So, how do you structure your code? And why? Let me know in the comments section.</p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.planetgeek.ch/2012/01/25/3077/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Ninject.Extensions.Factory introduction</title>
		<link>http://www.planetgeek.ch/2011/12/31/ninject-extensions-factory-introduction/</link>
		<comments>http://www.planetgeek.ch/2011/12/31/ninject-extensions-factory-introduction/#comments</comments>
		<pubDate>Sat, 31 Dec 2011 01:29:13 +0000</pubDate>
		<dc:creator>remo.gloor</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Factory]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[Ninject]]></category>
		<category><![CDATA[Open source]]></category>

		<guid isPermaLink="false">http://www.planetgeek.ch/?p=3049</guid>
		<description><![CDATA[The new release of Ninject 3.0 comes with a new extension that adds support for factories to Ninject. It supports factory interfaces, Func and Lazy. In this blog post I will explain how they are used. Why using factories? The recommended way to use IoC containers is that the composition root of the application is [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: left; width: 42px; padding-right: 10px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.planetgeek.ch/2011/12/31/ninject-extensions-factory-introduction/";
		var dzone_title = "Ninject.Extensions.Factory introduction";
		var dzone_style = "1";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><p>The new release of Ninject 3.0 comes with a new extension that adds support for factories to Ninject. It supports factory interfaces, Func and Lazy. In this blog post I will explain how they are used.</p>
<p><strong>Why using factories?</strong><br />
The recommended way to use IoC containers is that the <a href="http://blog.ploeh.dk/2011/07/28/CompositionRoot.aspx" target="_blank">composition root</a> of the application is the only place where the container is accessed. Unfortunately many application can&#8217;t create everything at once during the application start or at the beginning of a web/wcf request because not everything is known at this moment. Therefore these applications need a way to create new instances using the kernel at a later point. Preferably we want to do this without introducing a reference to the container. This is where factories come into play. Instead of injecting the kernel into classes that need to create new instances we inject a factory. This factory is responsible to create the new instances using the kernel. There are two ways to implement such a factory: A factory interface and as a Func or Lazy.<br />
<span id="more-3049"></span></p>
<p><strong>Factory Interface</strong><br />
The recommended way to add factories is to define an interface containing one or several methods to create the required dependencies as shown by the next code snippet.</p>
<pre class="brush: csharp; title: ; notranslate">
public class Foo
{
	private IBarFactroy barFactroy;
	public Foo(IBarFactory barFactory)
	{
		this.barFactory = barFactory;
	}

	public void Do()
	{
		var bar = this.barFactroy.CreateBar();
		...
	}
}

public interface IBarFactory
{
	Bar CreateBar();
}
</pre>
<p>This interface is declared at the same place as the class that is using it. In the binding configuration it can now be bound using the new ToFactory() method. This tells Ninject that it shall automatically implement a factory class for the specified interface and inject a new instance of this factory into each object that request an instance of the factory interface.</p>
<pre class="brush: csharp; title: ; notranslate">
kernel.Bind&amp;lt;IBarFactory&amp;gt;().ToFactory();
</pre>
<p>Sometimes it is necessary to pass some parameters to the new instance. This can be done very simply by adding those parameters to the factory method. The extension uses the convention that you have to use the same parameter names in the factory like you did in the constructor of the created object. The order of the parameters in the factory method and constructor do not have to match. </p>
<pre class="brush: csharp; title: ; notranslate">
public class Foo
{
	private IBarFactroy barFactroy;
	public Foo(IBarFactory barFactory)
	{
		this.barFactory = barFactory;
	}

	public void Do(int x, int y)
	{
		var bar = this.barFactroy.CreateBar(x, y);
		...
	}
}

public interface IBarFactory
{
	Bar CreateBar(int x, int y);
}

public class Bar
{
	public Bar(int y, int x)
	{
	}
}

foo.Do(1, 2); // Creates a Bar instance with x = 1, y = 2
</pre>
<p>Behind the scenes Ninject will create a proxy that implements the specified factory interface and intercept all methods so that the proxy behaves like the following implementation of the factory interface:</p>
<pre class="brush: csharp; title: ; notranslate">
public class BarFactory : IBarFactory
{
	private IResolutionRoot resolutionRoot;
	public BarFactory(IResolutionRoot resolutionRoot)
	{
		this.resolutionRoot = resolutionRoot;
	}

	public Bar CreateBar(int y, int x)
	{
		return this.resolutionRoot.Get&amp;lt;Bar&amp;gt;(
			new ConstructorArgument(&amp;quot;y&amp;quot;, y),
			new ConstructorArgument(&amp;quot;x&amp;quot;, x));
	}
}
</pre>
<p><strong>Factory Interface &#8211; Named Bindings</strong><br />
Sometimes there is the need to create differnet instances of an interface using named bindings. The default instace provider of the extension has the convention that it tries to return an instance using a named binding whenever a method starts with &#8220;Get&#8221;. E.g. IFoo GetMySpecialFoo() is equal to </p>
<pre class="brush: csharp; title: ; notranslate">
resolutionRoot.Get&amp;lt;IFoo&amp;gt;(&amp;quot;MySpecialFoo&amp;quot;);
</pre>
<p><strong>Custom instance provider</strong><br />
In some cases the default instance provider doesn&#8217;t meet your requirements. In this case you can do your own implementation with a custom behavior. This is done by implementing the IInstanceProvider interface:</p>
<pre class="brush: csharp; title: ; notranslate">
    /// &amp;lt;summary&amp;gt;
    /// Provides instances to the interceptor.
    /// &amp;lt;/summary&amp;gt;
    public interface IInstanceProvider
    {
        /// &amp;lt;summary&amp;gt;
        /// Gets an instance for the specified method and arguments.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name=&amp;quot;instanceResolver&amp;quot;&amp;gt;The instance resolver.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name=&amp;quot;methodInfo&amp;quot;&amp;gt;The method info of the method that was called on the factory.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name=&amp;quot;arguments&amp;quot;&amp;gt;The arguments that were passed to the factory.&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;The newly created instance.&amp;lt;/returns&amp;gt;
        object GetInstance(IInstanceResolver instanceResolver, MethodInfo methodInfo, object[] arguments);
    }
</pre>
<p>In most cases it is easier to derive from the StandardInstanceProvider and overload the required methods to change the behavior.</p>
<p><strong>Func</strong><br />
The second way to add factories is to inject a Func to the class that needs to create a new object. Like the factory interface it supports arguments too. But since a Func gives you absolutely no information about the parameters you have to pass, I recommend not using Func unless it takes no arguments. Even if it takes no arguments I personally think factory interfaces is the cleaner way to add factories. You have to write more code but the readability is better than with Func.</p>
<pre class="brush: csharp; title: ; notranslate">
public class Foo
{
	private Func&amp;lt;Bar&amp;gt; barFactroy;
	public Foo(Func&amp;lt;Bar&amp;gt; barFactory)
	{
		this.barFactory = barFactory;
	}

	public void Do()
	{
		var bar = this.barFactroy();
		...
	}
}
</pre>
<p>That&#8217;s everything you have to do in this case. There is no need to create a special binding for the Func.</p>
<p><strong>Lazy</strong><br />
Sometimes the creation of a dependency must be postponed because it uses a lot of resources or it is heavy to create and rarely used. In this case you can inject Lazy instead of IDependency. This way, the creation of the dependency will be postponed until the Value of the Lazy is accessed the first time. This instance will be reused for all following accesses to Value.</p>
<pre class="brush: csharp; title: ; notranslate">
public class Foo
{
	private Lazy&amp;lt;Bar&amp;gt; lazyBar;
	public Foo(Lazy&amp;lt;Bar&amp;gt; bar)
	{
		this.lazyBar = bar;
	}

	public void Do()
	{
		var bar = this.lazyBar.Value;
		...
	}
}
</pre>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.planetgeek.ch/2011/12/31/ninject-extensions-factory-introduction/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New Features and changes of Ninject 3.0</title>
		<link>http://www.planetgeek.ch/2011/12/30/new-features-and-changes-of-ninject-3-0/</link>
		<comments>http://www.planetgeek.ch/2011/12/30/new-features-and-changes-of-ninject-3-0/#comments</comments>
		<pubDate>Fri, 30 Dec 2011 20:23:03 +0000</pubDate>
		<dc:creator>remo.gloor</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[Ninject]]></category>
		<category><![CDATA[Open source]]></category>

		<guid isPermaLink="false">http://www.planetgeek.ch/?p=3026</guid>
		<description><![CDATA[Ninject 3.0 release candidate has gone live. This release introduces some new feature and some changes in its behavior. This blog post will give you detailed information what has changed. It covers mainly Ninject core. Other blog posts that describe the changes and the new extensions will follow soon. New fluent syntax to bind multiple [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: left; width: 42px; padding-right: 10px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.planetgeek.ch/2011/12/30/new-features-and-changes-of-ninject-3-0/";
		var dzone_title = "New Features and changes of Ninject 3.0";
		var dzone_style = "1";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><p>Ninject 3.0 release candidate has gone live. This release introduces some new feature and some changes in its behavior. This blog post will give you detailed information what has changed. It covers mainly Ninject core. Other blog posts that describe the changes and the new extensions will follow soon.<br />
<span id="more-3026"></span><br />
<strong>New fluent syntax to bind multiple interfaces to the same service</strong><br />
One of the big lacks of previous Ninject version was that there was no real support for the &#8220;Interface segregation principle&#8221;. It was not easily possible to tell Ninject that several interfaces shall be bound to the same service so that in case of a singleton the same instance is returned for different interfaces. Ninject provides now a fluent syntax that allows you to bind up to 4 interfaces together to the same instance:</p>
<pre class="brush: csharp; title: ; notranslate">
Bind&lt;IInterface1, IInterface2, IInterface3, IInterface4&gt;().To&lt;Implementation&gt;(). ...;
</pre>
<p>Some may ask what is if I want to bind more than four interface to the same service. In a small discussion we came to the conclusion that if you have more than four interfaces on a single service than most likely you have a problem with the single responsibility principle and should fix this in first place. So I put the limit to four for the fluent syntax because adding additional ones means quite a bit of work in the implementation. For those that really need more interfaces there is a workaround though:</p>
<pre class="brush: csharp; title: ; notranslate">
var bindingConfiguration =
    Bind&lt;IInterface1, IInterface2, IInterface3, IInterface4&gt;()
        .To&lt;Implementation&gt;()
        .BindingConfiguration;
kernel.AddBinding(new Binding(typeof(IInterface5), bindingConfiguration));
kernel.AddBinding(new Binding(typeof(IInterface6), bindingConfiguration));
</pre>
<p><strong>Fluent syntax changes</strong><br />
Several changes for the fluent syntax were introduced:</p>
<ul>
<li><strong>ToConstructor</strong> has been added. See <a href="http://www.planetgeek.ch/2011/05/28/ninject-constructor-selection-preview/" title="Ninject constructor selection preview">Ninject constructor selection preview</a> for detailed information.</li>
<li><strong>WhenInjectedInto</strong> previously matched only when the target type was exactly the specified one. Now it matches also if the target is derived from the specified type.</li>
<li><strong>WhenInjectedExactlyInto</strong> has been added for all those that want the previous behavior of WhenInjectedInto.</li>
<li><strong>WhenAnyAnchestorNamed</strong> has been added. Other than WhenParentNamed it does not match only if the parent has the specified name but also if any of its ancestors has the specified name.</li>
<li><strong>OnActivation</strong> and <strong>OnDeactivation</strong> receive now the implementation type instead of the service type as instance. In case the implementation type is undefined an object is passes as instance.</li>
<li>Generic overloads for <strong>OnActivation</strong> and <strong>OnDeactivation</strong> have been added that allow casting the implementation type. This is required in case the implementation type is undefined.</li>
</ul>
<p><strong>Constructor selection and strong typed constructor arguments</strong><br />
This release introduces the new &#8220;To&#8221; fluent syntax overload &#8220;ToConstructor&#8221;. This overload allows you to select the constructor that shall be used in the fluent syntax and to specify constructor arguments strongly typed and without magic strings. For more information about this feature please read my previous blog post about this topic. <a href="http://www.planetgeek.ch/2011/05/28/ninject-constructor-selection-preview/" title="Ninject constructor selection preview">Ninject constructor selection preview</a></p>
<p>Furthermore, the default selection of the constructor has been changed. Previous versions of Ninject considered constructors that have self bindable dependencies (e.g. a none abstract class) or dependencies for which a default value (int x = 3) is defined but no binding has been defined for those dependencies as invalid constructors and preferred all other constructors. In 3.0 these kinds of parameters are now treated the same way as if a binding exists for them. This can result in a different behavior of your application in case you have more than one constructor for your classes.</p>
<p>This version also requires that the constructor is uniquely selected. In case there is more than one constructor available with the same weight an activation exception is thrown. In this case you have to select the constructor manually (e.g. by using the new ToConstructor syntax).</p>
<p><strong>Inherited constructor arguments</strong><br />
Previously it was possible to pass constructor arguments to the resolved object by passing ConstructorArgument to &#8220;Get&#8221;. This feature was extended so that it is now possible to pass the constructor arguments to deeper levels too using the following syntax:</p>
<pre class="brush: csharp; title: ; notranslate">
kernel.Get&lt;IFoo&gt;(new ConstructorArgument(&quot;parameterName&quot;, value, true));
kernel.Get&lt;IFoo&gt;(new ConstructorArgument(&quot;parameterName&quot;, context =&gt; LazyEvaluatedValue(context), true));
</pre>
<p><strong>Changed to client profile and removed InRequestScope</strong><br />
Version 3.0 is now build as client profile library. Since InRequestScope requires a reference to System.Web it was removed from Ninject core. This scope type is now provided by the new Ninject.Web.Common extension which is the base for all web type extensions.</p>
<p><strong>Various small changes</strong></p>
<ul>
<li>Support for constructor parameter with a default value has been added. If a constructor parameter has a default value it is used in case there is no explicit binding defined.</li>
<li>Services that are bound using ToConstant are now in singleton scope by default. This decreases the work required when it is used somewhere.</li>
<li>Open Generics bindings are now overridable by a closed generic binding of the same generic type.</li>
<li>Instead of specially handling IKernel internal a default binding for IKernel and IResolutionRoot is added by the kernel during construction. This makes it possible to Rebind them if required.</li>
</ul>
<p><strong>Small extension changes</strong></p>
<ul>
<li><strong>Ninject.Extensions.ContextPreservation:</strong> BindInterfaceToBinding has been removed. Use the new Ninject core syntax to bind multiple interfaces to one implementation instead.</li>
<li><strong>Ninject.Extensions.Xml:</strong> InRequestScope requires the additional extension Ninject.Web.Common.Xml.</li>
</ul>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.planetgeek.ch/2011/12/30/new-features-and-changes-of-ninject-3-0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Pair Programming Stereotypes</title>
		<link>http://www.planetgeek.ch/2011/12/27/pair-programming-stereotypes/</link>
		<comments>http://www.planetgeek.ch/2011/12/27/pair-programming-stereotypes/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 13:10:59 +0000</pubDate>
		<dc:creator>Urs Enzler</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Methodology]]></category>
		<category><![CDATA[Pair Programming]]></category>

		<guid isPermaLink="false">http://www.planetgeek.ch/?p=2997</guid>
		<description><![CDATA[Over the last couple of years, I’ve done a lot of pair programming. Pair programming inside my team, at customer sites, in coding dojos and in my open source projects. Pair programming is really a great and effective experience when performed by an pair of developers knowing how to pair program. Unfortunately, you cannot just [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: left; width: 42px; padding-right: 10px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.planetgeek.ch/2011/12/27/pair-programming-stereotypes/";
		var dzone_title = "Pair Programming Stereotypes";
		var dzone_style = "1";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><p>Over the last couple of years, I’ve done a lot of pair programming. Pair programming inside my team, at customer sites, in coding dojos and in my open source projects.</p>
<p>Pair programming is really a great and effective experience when performed by an pair of developers knowing how to pair program.</p>
<p>Unfortunately, you cannot just put two developers in front of a single computer and expect them to perform perfectly from the start. Pair programming has to be learned. Both developers need to learn the difference between being the driver (the one holding the keyboard) and the navigator. See <a title="Pair Programming" href="http://www.planetgeek.ch/?p=1464">here</a> for details.</p>
<p>During my pair programming sessions I encountered some recurrent stereotypes, which I list in this post.</p>
<p><span id="more-2997"></span></p>
<h3>Navigator Stereotypes</h3>
<h4>The Dictator</h4>
<p>The Dictator is a navigator who tells the driver what he has to type: “And now go to the end of the line and write a closing parenthesis and now…”. Instead of navigating by challenging the current solution and looking where to go next, the dictator gets caught in the programming details.</p>
<p>Actually, the Dictator wishes he had the keyboard. Therefore, when you encounter a dictator simply pass him the keyboard and switch to the navigator role.</p>
<h4>The Spell Checker</h4>
<p>The Spell Checker sits beside you and reacts to every typo you make by immediately correcting you. Of course, the spell checker has therefore not enough time to really navigate.</p>
<p>Make a deal with the Spell Checker that he gets you a coffee (or anything else you’d like) whenever he corrects you.</p>
<h4>The Slasher</h4>
<p>The Slasher is a navigator that criticises everything you write. While critique is good, he does it in a way without building upon what you already have built.</p>
<p>Like free jazz musicians build up a tune together by reusing what the other band members have played, good pair programmers use what is already there to go on.</p>
<p>Try switching roles and be a role-model navigator. Maybe the Slasher turns into an Ignorant though (see below).</p>
<h4>The Silent</h4>
<p>The Silent is a navigator who says nothing; or almost nothing. He just sits there and looks how you are working.</p>
<p>Challenge the Silent with questions about what he thinks about your solution, or which test to write next.</p>
<h4>The Bored</h4>
<p>The Bored tends to distract you from work instead of providing you with information helping you focus on problem solving.</p>
<p>Just send him away, it’s better to code alone than with a Bored.</p>
<h3>Driver Stereotypes</h3>
<h4>The Secretive</h4>
<p>The Secretive just types some code without telling what he is about to do. The navigator has to figure out what’s going on by himself. There is no discussion between the driver and the navigator about the route to go, which solution to follow or which design to choose.</p>
<p>As a navigator ask the Secretive what his plans are or what is the idea.</p>
<h4>The Ignorant</h4>
<p>The Ignorant simply ignores all advice of the navigator. Mostly because he thinks that his ideas or his programming skills are superior compared to those of the navigator.</p>
<p>When confronted with an Ignorant, simply stop pairing and rise the topic in the next retrospective. Ignorants are normally bad navigators, too. They probably turn into Dictators or Slashers.</p>
<h4>The Overwhelmed</h4>
<p>The Overwhelmed is simply not used to pair program and therefore very nervous and out of control.</p>
<p>Make sure that you are the best navigator you can be. Be extra cautious with critique and mainly support the Overwhelmed.</p>
<p>Unfortunately, most developers start with this stereotype. Therefore, don’t force pair programming to much on them and either let them be navigators first or only put navigators beside them who have enough social skills to handle the situation.</p>
<h4>The Jumper</h4>
<p>The Jumper is a driver who likes to make wild jumps in the source code so that it’s impossible for the navigator to follow his steps.</p>
<p>Slow the Jumper down by asking questions about his plans and make sure you know more short-cuts than him.</p>
<h4></h4>
<h4>The Tool-Unfamiliar</h4>
<p>The Tool-Unfamiliar does not know any shortcuts of the developer environment and is therefore simply a dead slow programmer.</p>
<p>Switch roles and show the Tool-Unfamiliar some of your tricks. Printing a cheat sheet with short-cuts helps a lot, too.</p>
<p>I’m sure there are other stereo-types. Let me know by writing a comment below!</p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.planetgeek.ch/2011/12/27/pair-programming-stereotypes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Different Flavours of Pair Programming</title>
		<link>http://www.planetgeek.ch/2011/12/26/different-flavours-of-pair-programming/</link>
		<comments>http://www.planetgeek.ch/2011/12/26/different-flavours-of-pair-programming/#comments</comments>
		<pubDate>Mon, 26 Dec 2011 12:43:40 +0000</pubDate>
		<dc:creator>Urs Enzler</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Methodology]]></category>
		<category><![CDATA[Test Driven Development]]></category>
		<category><![CDATA[Pair Programming]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://www.planetgeek.ch/?p=1464</guid>
		<description><![CDATA[Pair programming – two developers working together at a single computer – can result in better software written faster, but only if you know what you do. Pair programming is not just sitting together and code as you would when being alone. Unfortunately, this is what most developers practice – resulting in a painful and [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: left; width: 42px; padding-right: 10px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.planetgeek.ch/2011/12/26/different-flavours-of-pair-programming/";
		var dzone_title = "Different Flavours of Pair Programming";
		var dzone_style = "1";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><p>Pair programming – two developers working together at a single computer – can result in better software written faster, but only if you know what you do.</p>
<p>Pair programming is not just sitting together and code as you would when being alone. Unfortunately, this is what most developers practice – resulting in a painful and ineffective experience.</p>
<p>To get most out of pair programming, you first have to know your setup.</p>
<p><span id="more-1464"></span></p>
<h3>Pair Programming for Transferring Know-How</h3>
<p>This is the case when an expert and a novice pair together and the expert is coding while the novice is looking over the expert’s shoulder.</p>
<p>The expert shows the novice how something is done: coding style, design pattern, business logic concepts and so forth.</p>
<p>The novice gets an overview very quickly. However, the learning effect is rather low because of the passive role of the novice.</p>
<p>This kind of pair programming is very useful when introducing the novice to a new area.</p>
<h3>Educational Pair Programming</h3>
<p>When you switch the positions of the expert and the novice, you get educational pair programming. The expert coaches the novice while he tries to solve the problem. The learning effect is much greater in this kind of pair programming. But the speed of development is considerably lower.</p>
<h3></h3>
<h3>Real Pair Programming</h3>
<p>In real pair programming there are two experts working together to solve the problem at hand. Although they work at the same time on the same problem, their job is slightly different.</p>
<p>One (the driver) is responsible for</p>
<ul>
<li>typing code</li>
<li>finding a solution that works</li>
</ul>
<p>The other (the navigator) is responsible for</p>
<ul>
<li>challenging the current solution (what is missing? what could go wrong?)</li>
<li>where to go next</li>
</ul>
<ul>This results in discussions about design, coding style, readability and much more. The outcome of such a pair programming session is a piece of code that is simpler, better understandable an less bug prone.</ul>
<h3>Pair Programming and Test Driven Development</h3>
<p>Pair programming is especially powerful when developing software in Test Driven Development manner.</p>
<p>The driver is mainly responsible to get the failing test working by finding a quick solution (failing test phase). The navigator looks for test cases that show that the current solution is wrong or makes wrong assumptions (green tests phase). Together they look for simpler implementations (refactoring phase).</p>
<h3>Why Pair Programming works</h3>
<p>When practising real pair programming, both developers can concentrate on a single thing: Either finding a solution to the current problem, the current failing unit test, or challenging the current solution with new test cases.</p>
<p>This results in less switches between problem solving and problem analysing mode (red – green phases). Less switching between these two tasks results in higher efficiency<sup>1</sup> (less downtime because no task switch) and higher effectiveness<sup>2</sup> (navigator keeps focus on what has to be done and does not get lost in programming details). Finally, two developers can motivate each other much better to refactor code to get simpler solutions than a single developer does himself.</p>
<p><em>A final note: pair programming like any other methodology or practice has to be learned. Two developers cannot just sit together and expect to get benefits right away. Pair programming needs a lot of trust and discipline. Both has to be built first.</em></p>
<p><sup>1</sup> efficiency = doing something quickly</p>
<p><sup>2</sup> effectiveness = doing the right thing</p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.planetgeek.ch/2011/12/26/different-flavours-of-pair-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>No more development, TDD begins with MoreUnit</title>
		<link>http://www.planetgeek.ch/2011/12/25/no-more-development-tdd-begins-with-moreunit/</link>
		<comments>http://www.planetgeek.ch/2011/12/25/no-more-development-tdd-begins-with-moreunit/#comments</comments>
		<pubDate>Sun, 25 Dec 2011 10:01:44 +0000</pubDate>
		<dc:creator>Adrian Elsener</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Test Driven Development]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[Mockito]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Unit Test]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.planetgeek.ch/?p=3000</guid>
		<description><![CDATA[Do you program or do you already TDD? If you prefer to do TDD you will love the eclipse plug-in called MoreUnit. It is as simple as powerful. All it does is executing tests from corresponding productive class and makes it very simple to change between them. Just press Ctrl-J (like Jump) to jump from [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: left; width: 42px; padding-right: 10px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.planetgeek.ch/2011/12/25/no-more-development-tdd-begins-with-moreunit/";
		var dzone_title = "No more development, TDD begins with MoreUnit";
		var dzone_style = "1";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><p>Do you program or do you already TDD? <img src='http://www.planetgeek.ch/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
If you prefer to do TDD you will love the eclipse plug-in called MoreUnit. It is as simple as powerful. All it does is executing tests from corresponding productive class and makes it very simple to change between them.<br />
Just press Ctrl-J (like Jump) to jump from test to implementing class and the other way. Or press Ctrl-R (like Run) to run the test regardless if you are in the test or the implementation class.<span id="more-3000"></span></p>
<h3>Configuration</h3>
<p>There are just a few things you have to configure. I recommend to remove the prefix for tests because I name test classes like the original name with the suffix test.</p>
<h4>Find classes with different names</h4>
<p>If you have more than one test class for an implementation you prefer to decide into which test to jump. If you like this enable the option ‘Enable flexible naming of tests’. (At beginning I could not imagin who could have like this but since a short time I use it very intensive)</p>
<h4>Mocks</h4>
<p>There is a experimental feature to create mocks for dependencies. If you have a class which has a constructor to get some configurations MoreUnit is able to create initializing our testee with a mock. I tried it with mockito as mocking framework. My sample is a simple class which takes an object of type Param to be configured.</p>
<pre class="brush: java; title: ; notranslate">
public class Feature {
 private final Param param;

 public Feature(final Param param) {
 this.param = param;
 }

 public void create() {
 System.out.println(param);
 }
}
public interface Param {
}
</pre>
<p>While creating the test with MoreUnit (just press Ctrl-J in the Feature class) it will as us in the second step of creation wizard which dependencies should be mocked.<br />
<a href="http://www.planetgeek.ch/wp-content/uploads/2011/12/mockDependencies.jpg"  rel="lightbox[roadtrip]"><img src="http://www.planetgeek.ch/wp-content/uploads/2011/12/mockDependencies-300x172.jpg" alt="" title="Mocking dependencies" width="300" height="172" class="alignnone size-medium wp-image-3012" /></a><br />
As you can see I selected the constructor which takes an instance of Param. I don’t select any method to create a test method for it. So it will create a test class like this:</p>
<pre class="brush: java; title: ; notranslate">
@RunWith(MockitoJUnitRunner.class)
public class FeatureTest {
 @Mock
 private Param param;
 private Feature feature;

 @Before
 public void createFeature() throws Exception {
 feature = new Feature(param);
 }
}
</pre>
<p>In my opinion this is not bad but, I’d prefere to have the initialisation for mocking within the @Before method and not with the @RunWith. Because sometimes I have other JUnit runners like the Parameterized.class. So I have to remove the @RunWith and add the ‘MockitoAnnotations.initMocks(this);’. So the test will look like this:</p>
<pre class="brush: java; title: ; notranslate">
public class FeatureTest {
 @Mock
 private Param param;
 private Feature feature;

 @Before
 public void createFeature() throws Exception {
 MockitoAnnotations.initMocks(this);
 feature = new Feature(param);
 }
}
</pre>
<p>You might say: “If I have to do so much I just can write it on myself”. Nearly right. Imagin you have more than just one parameter. MoreUnit will create all the members with corresponding Annotations. There are some problems with the current version (2.4.2). Creating the mocks in an already existing test will have the result there is a second member for the unit under test and if the annotation @RunWith is already on the class it will be added twice. So it will be very helpful while creating a new test but not very comfortable if the test is existing and contains mocks.</p>
<h3>Where to find</h3>
<p><a href="http://moreunit.sourceforge.net" title="MoreUnit">http://moreunit.sourceforge.net</a><br />
Update-Site: <a href="http://moreunit.sourceforge.net/update-site" title="Update-Site">http://moreunit.sourceforge.net/update-site</a><br />
The plugin should also be available in the Eclipse Marketplace. Just search for ‘moreunit’</p>
<p>I think it is a very helpful tool if you will program with TDD. Because it helps you to change between implementation an test very quick. (Yes, much faster than Ctrl-F6, try it <img src='http://www.planetgeek.ch/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  )</p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.planetgeek.ch/2011/12/25/no-more-development-tdd-begins-with-moreunit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Lazy for implementing IDisposable pattern</title>
		<link>http://www.planetgeek.ch/2011/12/15/using-lazy-for-implementing-idisposable-pattern/</link>
		<comments>http://www.planetgeek.ch/2011/12/15/using-lazy-for-implementing-idisposable-pattern/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 02:00:42 +0000</pubDate>
		<dc:creator>Daniel Marbach</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Dispose]]></category>
		<category><![CDATA[Lazy]]></category>

		<guid isPermaLink="false">http://www.planetgeek.ch/?p=2988</guid>
		<description><![CDATA[Implementing the dispose pattern according to IDisposable can be very tedious. Why not simply use the new Lazy&#60;T&#62; to get rid of some boiler plate code? The trick is to define a Lazy&#60;Action&#62; with a function delegate which calls a release method. As long as you don&#8217;t access the value property of the lazy type [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: left; width: 42px; padding-right: 10px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.planetgeek.ch/2011/12/15/using-lazy-for-implementing-idisposable-pattern/";
		var dzone_title = "Using Lazy<T> for implementing IDisposable pattern";
		var dzone_style = "1";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><p>Implementing the dispose pattern according to <a href="http://msdn.microsoft.com/en-us/library/system.idisposable.aspx" target="_blank">IDisposable</a> can be very tedious. Why not simply use the new <a href="http://msdn.microsoft.com/en-us/library/dd642331.aspx" target="_blank">Lazy&lt;T&gt;</a> to get rid of some boiler plate code? The trick is to define a Lazy&lt;Action&gt; with a function delegate which calls a <em>release</em> method. As long as you don&#8217;t access the <em>value</em> property of the lazy type the <em>release</em> method is not called. <a href="http://msdn.microsoft.com/en-us/library/dd642331.aspx" target="_blank">Lazy&lt;T&gt;</a> offers the possibility to check whether the underlying value has been created or not (property <em>IsValueCreated</em>). Therefore we can use this to check whether we already disposed the underlying resources. Let&#8217;s see how this looks like in code:</p>
<pre class="brush: csharp; title: ; notranslate">
    public class SomeDisposable : IDisposable  {
        private Lazy&lt;Action&gt; dispose;

        public SomeDisposable()  {
            this.dispose = new Lazy&lt;Action&gt;(() =&gt; this.Release);
        }

        public void Dispose() {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing) {
            if (disposing &amp;&amp; !this.dispose.IsValueCreated) {
                this.dispose.Value();
            }
        }

        private void Release() {
            this.resource1.Dispose();
            this.resource2.Disconnect();
            this.resource2.Dispose();
        }
    }
</pre>
<p>Remarks: I left out the finalizer to not clutter up the code sample too much.</p>
<p>Happy lazy coding!</p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.planetgeek.ch/2011/12/15/using-lazy-for-implementing-idisposable-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>bbv.Common.Bootstrapper Tutorial Part 6</title>
		<link>http://www.planetgeek.ch/2011/12/10/bbv-common-bootstrapper-tutorial-part-6/</link>
		<comments>http://www.planetgeek.ch/2011/12/10/bbv-common-bootstrapper-tutorial-part-6/#comments</comments>
		<pubDate>Sat, 10 Dec 2011 16:16:51 +0000</pubDate>
		<dc:creator>Daniel Marbach</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[bbv.Common]]></category>
		<category><![CDATA[bbvcommon]]></category>
		<category><![CDATA[bootstrapper]]></category>

		<guid isPermaLink="false">http://www.planetgeek.ch/?p=2971</guid>
		<description><![CDATA[The reporting mechanism allows creating a full report of the bootstrapping process. To be able to report the bootstrapping process the process must actually run and a reporter must be present. By default the bootstrapper uses a null reporter which does nothing with the report. But it is also possible to hook in a report [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: left; width: 42px; padding-right: 10px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.planetgeek.ch/2011/12/10/bbv-common-bootstrapper-tutorial-part-6/";
		var dzone_title = "bbv.Common.Bootstrapper Tutorial Part 6";
		var dzone_style = "1";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><p>The reporting mechanism allows creating a full report of the bootstrapping process. To be able to report the bootstrapping process the process must actually run and a reporter must be present. By default the bootstrapper uses a null reporter which does nothing with the report. But it is also possible to hook in a report generator which creates Visio, Enterprise Architect or &#8230; (you name it!) diagrams.</p>
<p>A custom reporter must implement the reporter interface <tt>IReporter</tt>. The reporter receives an <tt>IReportingContext</tt> which contains all necessary information about the bootstrapping process. The custom reporter must be passed upon the construction of the <tt>DefaultBootstrapper&lt;TExtension&gt;</tt>.<span id="more-2971"></span></p>
<pre class="brush: csharp; title: ; notranslate">
        new DefaultBootstrapper&lt;ICustomExtension&gt;( /* Input your IReporter */ )
</pre>
<p>The reporting context is structured like the following:</p>
<p><a href="http://www.planetgeek.ch/wp-content/uploads/2011/12/ReportingContext.png"  rel="lightbox[roadtrip]"><img class="alignnone size-medium wp-image-2983" title="ReportingContext" src="http://www.planetgeek.ch/wp-content/uploads/2011/12/ReportingContext-300x199.png" alt="" width="300" height="199" /></a></p>
<p>An example of a reporter which reports all into a string could look like:</p>
<pre class="brush: csharp; title: ; notranslate">
        public class StringReporter : IReporter
        {
            private IReportingContext context;

            public void Report(IReportingContext context)
            {
                this.context = context;
            }

            public override string ToString()
            {
                return Dump(this.context);
            }

            private static string Dump(IReportingContext context)
            {
                var builder = new StringBuilder();

                context.Extensions.ForEach(e =&gt; Dump(e.Name, e.Description, builder, 0));

                Dump(context.Run, builder);
                Dump(context.Shutdown, builder);

                return builder.ToString();
            }

            private static void Dump(IExecutionContext executionContext, StringBuilder sb)
            {
                Dump(executionContext.Name, executionContext.Description, sb, 3);

                Dump(executionContext.Executables, sb);
            }

            private static void Dump(IEnumerable&lt;IExecutableContext&gt; executableContexts, StringBuilder sb)
            {
                foreach (IExecutableContext executableContext in executableContexts)
                {
                    Dump(executableContext.Name, executableContext.Description, sb, 6);

                    executableContext.Behaviors.ForEach(b =&gt; Dump(b.Name, b.Description, sb, 9));
                }
            }

            private static void Dump(string name, string description, StringBuilder sb, int indent)
            {
                sb.AppendLine(string.Format(CultureInfo.InvariantCulture, &quot;{0}[Name = {1}, Description = {2}]&quot;, string.Empty.PadLeft(indent), name, description));
            }
        }
</pre>
<p>Restrictions: In the version 1.0 of the bootstrapper there is a limitation for lazy resolved behaviors. Lazy resolved behaviors do not report as the actual behavior but as a LazyBehavior type. Hope I can resolve this in the feature version.</p>
<p>Happy reporting!</p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.planetgeek.ch/2011/12/10/bbv-common-bootstrapper-tutorial-part-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss><!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Object Caching 1262/1283 objects using disk: basic

Served from: planetgeek.ch @ 2012-02-05 11:13:35 -->

