<?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/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Raffaeu's blog</title>
	
	<link>http://blog.raffaeu.com</link>
	<description>A NET coder relocated in Netherlands</description>
	<lastBuildDate>Sun, 07 Apr 2013 19:02:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/RaffaeuEnglishBlog" /><feedburner:info uri="raffaeuenglishblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license><image><link>http://creativecommons.org/licenses/by/3.0/</link><url>http://creativecommons.org/images/public/somerights20.gif</url><title>Some Rights Reserved</title></image><feedburner:emailServiceId>RaffaeuEnglishBlog</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Castle WCF Facility</title>
		<link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/hwvGzUJ0sok/castle-wcf-facility.aspx</link>
		<comments>http://blog.raffaeu.com/archive/2013/04/05/castle-wcf-facility.aspx#comments</comments>
		<pubDate>Fri, 05 Apr 2013 07:42:00 +0000</pubDate>
		<dc:creator>raffaeu</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Pattern]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://blog.raffaeu.com/?p=436</guid>
		<description><![CDATA[In the previous post we saw how to provide Inversion of Control capabilities to a WCF service. That’s pretty cool but unfortunately it requires a big refactoring if you plan to apply the Dependency Inversion pattern on an existing WCF project. Today we will see an interesting alternative provided by Castle project. If you are <span class="ellipsis">&#8230;</span> <span class="more-link-wrap"><a href="http://blog.raffaeu.com/archive/2013/04/05/castle-wcf-facility.aspx" class="more-link"><span>Read More &#8594;</span></a></span>]]></description>
				<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_button">
										<a name="fcbk_share"	href="http://www.facebook.com/raffaeu"	target="blank">
											<img src="http://blog.raffaeu.com/wp-content/plugins/facebook-button-plugin/img/standart-facebook-ico.jpg" alt="Fb-Button" />
										</a>	
									</div><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://blog.raffaeu.com/archive/2013/04/05/castle-wcf-facility.aspx" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>In the <a href="http://blog.raffaeu.com/archive/2013/01/31/wcf-and-dependency-inversion-using-castle-windsor.aspx" target="_blank">previous post</a> we saw how to provide <em>Inversion of Control</em> capabilities to a WCF service. That’s pretty cool but unfortunately it requires a big refactoring if you plan to apply the Dependency Inversion pattern on an existing WCF project. </p>
<p>Today we will see an interesting alternative provided by Castle project. If you are not aware of Castle, you can have a look at the community web site <a href="http://www.castleproject.org/" target="_blank">here</a>. Castle provides a set of tools for NET, <em>Active Record, Dynamic Proxy, Windsor</em> and a set of <strong>facilities</strong> that you can easily plug into your code.</p>
<h2>The demo project</h2>
<p>Before starting to have&nbsp; a look at <strong>Castle Wcf Facility</strong> we need a new WCF project and a WCF web site to host our service. The idea is to create an empty service and host it, then we will refactor the project to include Castle Windsor and WCF facility.</p>
<p>Let’s start by creating an IIS web site, a DNS redirect and a folder for our IIS web site. The final result will be like the following one:</p>
<p><a href="http://blog.raffaeu.com/wp-content/uploads/2013/04/image.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blog.raffaeu.com/wp-content/uploads/2013/04/image_thumb.png" width="351" height="79"></a></p>
<p>Now we need to create the new project in Visual Studio. I have created a solution that contains 2 projects:</p>
<ul>
<li>Empty WCF Service Library named “<em>Service.Contracts</em>”
<li>Empty WCF Service Library named “<em>Service.Implementations</em>”
<ul>
<li>reference the project “<em>Service.Contracts</em>”</li>
</ul>
</li>
</ul>
<p>And this would be the final result of this step:</p>
<p><a href="http://blog.raffaeu.com/wp-content/uploads/2013/04/image1.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blog.raffaeu.com/wp-content/uploads/2013/04/image_thumb1.png" width="202" height="191"></a></p>
<blockquote><p>We have just implemented the <em>correct</em> way of creating a WCF service implementation and a WCF service contract. The Client will have a reference to the <em>contract</em> assembly in order to be able to work with the service implementation, <em>without the need of using a Proxy</em>. This concept is outside the fact that I will use an ioc container, it’s just a lot easier than adding a “web service reference” in visual studio and carry tons of useless proxy classes in your project.</p>
</blockquote>
<h2>Hosting WCF service</h2>
<p>The final step is to host this WCF Service inside an IIS ASP.NET or ASP.NET MVC website. I have create a new “<em>web site application</em>” and from the options I choose “<em>WCF service application</em>”. Then I select my local IIS for the development path, but this is up to you.</p>
<p><a href="http://blog.raffaeu.com/wp-content/uploads/2013/04/image2.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blog.raffaeu.com/wp-content/uploads/2013/04/image_thumb2.png" width="260" height="130"></a></p>
<p>Now Visual Studio will ask you if you want to override the current web site or use the existing content. If you choose the second option you will have to provide also web.config configuration and initial setup, so I kindly suggest the first option.</p>
<p>If everything went ok you should be able to visit the default service created by Visual Studio at this url: <a href="http://staging.service.local/Service.svc">http://staging.service.local/Service.svc</a>. </p>
<p>Now we need to change the content and the name of the .svc file, but before we need to add a reference for <em>Contracts</em> and <em>Implementations</em> from the solution explorer!</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:be9b3b93-539f-401d-9877-0a7df1c02419" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre class="crayon-plain-tag">[sourcecode language='php' ]
&lt;%@ ServiceHost 
    Language=&quot;C#&quot; Debug=&quot;true&quot; 
    Service=&quot;Service.Implementations.ServiceImplementation&quot; %&gt;
[/sourcecode]</pre>
</div>
<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>We need to reference the Implementation because we don’t have a factory yet able to translate the <em>IServiceContract</em> into a <em>ServiceImplementation</em> class. So the next step is to install in our solution the WCF castle facility nuget package.</p>
<p><a href="http://blog.raffaeu.com/wp-content/uploads/2013/04/image3.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blog.raffaeu.com/wp-content/uploads/2013/04/image_thumb3.png" width="299" height="147"></a></p>
<h2>Add WCF facility</h2>
<p>So far we didn’t need any external tool because we have an empty service created by default by Visual Studio with a dummy code, or probably during the tutorial you have already changed your service to so something more interesting. The next step is to add a facility in order to be able to change the default factory used by IIS to create an instance of our service. </p>
<p>The first step is to add a new <em>global.asax</em> file if you don’t have one already and plug the Windsor container inside the <em>Application_Start</em> event.<br />This is my global.asax file:</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:5a1d79c1-5588-446a-a279-52d2a994f8ca" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre class="crayon-plain-tag">[sourcecode language='php' ]
&lt;%@ Application Language=&quot;C#&quot; Inherits=&quot;ServiceApplication&quot; %&gt;
[/sourcecode]</pre>
</div>
<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>Now, in the code behind file we want to create an instance of a new Windsor Container during the <em>Application_Start</em> event:</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:306dfa3b-7490-4833-84b9-cb1d1cd3e4ce" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre class="crayon-plain-tag">[sourcecode language='csharp' ]
public class ServiceApplication : HttpApplication
{
    public static WindsorContainer Container { get; set; }

    protected void Application_Start()
    {
        BuildContainer();
    }
}
[/sourcecode]</pre>
</div>
<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 this is the code to initialize a new container. In this code we need to pay attention in the way we specify the server name, because WCF facility uses the <strong>service</strong> attribute value to search inside the Windsor container. So, this is the code to register the service:</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:7aad7b42-9271-44c1-862e-89319a0b0d39" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre class="crayon-plain-tag">[sourcecode language='csharp' ]
private void BuildContainer()
{
    Container = new WindsorContainer();
    Container.Kernel.AddFacility&lt;WcfFacility&gt;();
    Container.Kernel.Register(Component.For&lt;IServiceContract&gt;()
                                        .ImplementedBy&lt;ServiceImplementation&gt;()
                                        .Named(&quot;ServiceContract&quot;));
}
[/sourcecode]</pre>
</div>
<p>And this is the change we need to apply to the Service.svc file:</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:33b6f515-f186-4ff8-a116-eee814580900" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre class="crayon-plain-tag">[sourcecode language='php' ]
&lt;%@ ServiceHost 
    Language=&quot;C#&quot; Debug=&quot;true&quot; 
    Service=&quot;ServiceContract&quot;
    Factory=&quot;Castle.Facilities.WcfIntegration.DefaultServiceHostFactory, Castle.Facilities.WcfIntegration&quot; %&gt;
[/sourcecode]</pre>
</div>
<p>Now your service is ready to use dependency injection under the power of Castle Windsor. </p>
<h2>Add a dependency to a WCF service using Windsor</h2>
<p>Simple example, I have a service that requires an <em>ILogger</em> injected in it. I need to change the code for my service to allow injection and then I need to register the logger in the global.asax file during the Windsor container activation process.</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:77bf6284-8f3b-4ff0-aca9-9a92f6b07862" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre class="crayon-plain-tag">[sourcecode language='csharp' ]
public class ServiceImplementation : IServiceContract
{
    private readonly ILogger logger;

    public ServiceImplementation(ILogger logger)
    {
        this.logger = logger;
    }

    public string GetData(int value)
    {
        this.logger.Trace(&quot;Method started!&quot;);
        return string.Format(&quot;You entered: {0}&quot;, value);
    }
}
[/sourcecode]</pre>
</div>
<p>And this how we change the registration in the container:</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:eddf5f67-d1a0-43d1-bd54-c507e317f8ad" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre class="crayon-plain-tag">[sourcecode language='csharp' ]
Container.Kernel.Register(
    // register the logger
    Component.For&lt;ILogger&gt;()
        .ImplementedBy&lt;TraceLogger&gt;(),
    // register the service
    Component.For&lt;IServiceContract&gt;()
        .ImplementedBy&lt;ServiceImplementation&gt;()
        .Named(&quot;ServiceContract&quot;));
[/sourcecode]</pre>
</div>
<p>The source code is available here: </p>
<p><a title="http://sdrv.ms/16BLYoI" href="http://sdrv.ms/16BLYoI">http://sdrv.ms/16BLYoI</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=hwvGzUJ0sok:MeJJ6xwfRHw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=hwvGzUJ0sok:MeJJ6xwfRHw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=hwvGzUJ0sok:MeJJ6xwfRHw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=hwvGzUJ0sok:MeJJ6xwfRHw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=hwvGzUJ0sok:MeJJ6xwfRHw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=hwvGzUJ0sok:MeJJ6xwfRHw:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=hwvGzUJ0sok:MeJJ6xwfRHw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/hwvGzUJ0sok" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.raffaeu.com/archive/2013/04/05/castle-wcf-facility.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.raffaeu.com/archive/2013/04/05/castle-wcf-facility.aspx</feedburner:origLink></item>
		<item>
		<title>WCF and dependency inversion using Castle Windsor</title>
		<link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/GaqLpNuvyq4/wcf-and-dependency-inversion-using-castle-windsor.aspx</link>
		<comments>http://blog.raffaeu.com/archive/2013/01/31/wcf-and-dependency-inversion-using-castle-windsor.aspx#comments</comments>
		<pubDate>Thu, 31 Jan 2013 21:00:09 +0000</pubDate>
		<dc:creator>raffaeu</dc:creator>
				<category><![CDATA[Design Pattern]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://raffaeu.com/?p=10</guid>
		<description><![CDATA[When you start to work with TDD and other Agile practices the first thing you try to apply almost everywhere in your code is the Dependency Inversion pattern because you want to invert the logic of your dependencies to make your code more testable and maintainable. In order to accomplish this result I am using <span class="ellipsis">&#8230;</span> <span class="more-link-wrap"><a href="http://blog.raffaeu.com/archive/2013/01/31/wcf-and-dependency-inversion-using-castle-windsor.aspx" class="more-link"><span>Read More &#8594;</span></a></span>]]></description>
				<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_button">
										<a name="fcbk_share"	href="http://www.facebook.com/raffaeu"	target="blank">
											<img src="http://blog.raffaeu.com/wp-content/plugins/facebook-button-plugin/img/standart-facebook-ico.jpg" alt="Fb-Button" />
										</a>	
									</div><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://blog.raffaeu.com/archive/2013/01/31/wcf-and-dependency-inversion-using-castle-windsor.aspx" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>When you start to work with TDD and other Agile practices the first thing you try to apply almost everywhere in your code is the <a href="http://www.objectmentor.com/resources/articles/dip.pdf" target="_blank">Dependency Inversion</a> pattern because you want to invert the logic of your dependencies to make your code more testable and maintainable.</p>
<p>In order to accomplish this result I am using <a href="http://www.castleproject.org/" target="_blank">Castle Windsor</a>, while before 2013 I was working with <a href="http://unity.codeplex.com/" target="_blank">Microsoft Unity</a>. I am not going to jump into the conversation <em>“Which Inversion of Control container is better?”</em> because it really depends on what you need to do. For years I was more than satisfied with Unity but recently I started to create complex bootstrappers for my applications and I found Windsor more flexible, that’s it! <img class="wlEmoticon wlEmoticon-nerdsmile" style="border-style: none;" alt="Nerd smile" src="http://raffaeu.com/wp-content/uploads/2013/03/e371a865-70fe-4570-89c5-0f74d566115ewlEmoticon-nerdsmile_2.png" /></p>
<h2>How does WCF create a service instance?</h2>
<p>First of all, in order to apply dependency inversion inside WCF we need to understand how WCF works and how it creates new service instance. I found this article on MSDN very helpful during my researches: <a href="http://msdn.microsoft.com/en-us/library/ms733848.aspx" target="_blank">Extending WCF</a>.</p>
<p>So, this is the final result I want to obtain:</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/f267a525-1e1c-4443-8409-c6f564da2580image_2.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="image" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/ece6a48f-0d5b-46ec-a2f3-2e405c7e1184image_thumb.png" width="547" height="500" border="0" /></a></p>
<p>When you create a new service in WCF, you can specify the factory that will be in charge of creating the service instance.</p>
<p>This is the code you should use to specify the factory:</p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; font-family: 'Courier New', courier, monospace; direction: ltr; text-align: left; margin: 20px 0px 10px; line-height: 12pt; max-height: 200px; width: 97.5%; background-color: #f4f4f4; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre class="crayon-plain-tag"><span id="lnum1" style="color: #606060;">   1:</span> &lt;%@ ServiceHost Language=<span style="color: #006080;">"C#"</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum2" style="color: #606060;">   2:</span>     Factory=<span style="color: #006080;">"Raf.DependencyInjectionHostFactory"</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum3" style="color: #606060;">   3:</span>     Service=<span style="color: #006080;">"Raf.MyService"</span> %&gt;</pre><br />
<!--CRLF--></p>
</div>
</div>
<p>Now, the factory should start a new instance of our service, or better, should use the <strong>ioc container</strong> to resolve an instance of that service.</p>
<p>Second step is to create a custom host that will add a new <strong>behaviour</strong> to our service, the behaviour will call the <strong>service locator</strong> (<em>I know it’s an anti-pattern …</em>) to inject the dependencies. In my case, Castle Windsor.</p>
<p><strong>Factory</strong></p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; font-family: 'Courier New', courier, monospace; direction: ltr; text-align: left; margin: 20px 0px 10px; line-height: 12pt; max-height: 200px; width: 97.5%; background-color: #f4f4f4; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre class="crayon-plain-tag"><span id="lnum1" style="color: #606060;">   1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> DependencyInjectionHostFactory : ServiceHostFactory</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum2" style="color: #606060;">   2:</span> {</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum3" style="color: #606060;">   3:</span>     <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum4" style="color: #606060;">   4:</span>     {</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum5" style="color: #606060;">   5:</span>         <span style="color: #008000;">// method called when we hit a request to http:// ... youservice.svc</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum6" style="color: #606060;">   6:</span>         <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">new</span> DependencyInjectionHost(serviceType, baseAddresses);</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum7" style="color: #606060;">   7:</span>     }</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum8" style="color: #606060;">   8:</span> }</pre><br />
<!--CRLF--></p>
</div>
</div>
<p><strong>Host</strong></p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; font-family: 'Courier New', courier, monospace; direction: ltr; text-align: left; margin: 20px 0px 10px; line-height: 12pt; max-height: 200px; width: 97.5%; background-color: #f4f4f4; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre class="crayon-plain-tag"><span id="lnum1" style="color: #606060;">   1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> DependencyInjectionHost : ServiceHost</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum2" style="color: #606060;">   2:</span> {</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum3" style="color: #606060;">   3:</span>     <span style="color: #008000;">// omit</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum4" style="color: #606060;">   4:</span>     <span style="color: #008000;">// ...</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum5" style="color: #606060;">   5:</span>     <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> OnOpening()</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum6" style="color: #606060;">   6:</span>     {</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum7" style="color: #606060;">   7:</span>         <span style="color: #008000;">// attach the behavior</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum8" style="color: #606060;">   8:</span>         Description.Behaviors.Add(<span style="color: #0000ff;">new</span> DependencyInjectionServiceBehavior());</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum9" style="color: #606060;">   9:</span>         <span style="color: #0000ff;">base</span>.OnOpening();</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum10" style="color: #606060;">  10:</span>     }</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum11" style="color: #606060;">  11:</span> }</pre><br />
<!--CRLF--></p>
</div>
</div>
<p><strong>Service behavior</strong></p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; font-family: 'Courier New', courier, monospace; direction: ltr; text-align: left; margin: 20px 0px 10px; line-height: 12pt; max-height: 200px; width: 97.5%; background-color: #f4f4f4; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre class="crayon-plain-tag"><span id="lnum1" style="color: #606060;">   1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> DependencyInjectionServiceBehavior : IServiceBehavior</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum2" style="color: #606060;">   2:</span> {</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum3" style="color: #606060;">   3:</span>     <span style="color: #cc6633;">#region</span> IServiceBehavior Members</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum4" style="color: #606060;">   4:</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum5" style="color: #606060;">   5:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum6" style="color: #606060;">   6:</span>     {</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum7" style="color: #606060;">   7:</span>     }</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum8" style="color: #606060;">   8:</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum9" style="color: #606060;">   9:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> AddBindingParameters(</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum10" style="color: #606060;">  10:</span>         ServiceDescription serviceDescription,</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum11" style="color: #606060;">  11:</span>         ServiceHostBase serviceHostBase,</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum12" style="color: #606060;">  12:</span>         Collection&lt;ServiceEndpoint&gt; endpoints,</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum13" style="color: #606060;">  13:</span>         BindingParameterCollection bindingParameters)</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum14" style="color: #606060;">  14:</span>     {</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum15" style="color: #606060;">  15:</span>     }</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum16" style="color: #606060;">  16:</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum17" style="color: #606060;">  17:</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum18" style="color: #606060;">  18:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum19" style="color: #606060;">  19:</span>     {</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum20" style="color: #606060;">  20:</span>         <span style="color: #0000ff;">foreach</span> (ChannelDispatcherBase cdb <span style="color: #0000ff;">in</span> serviceHostBase.ChannelDispatchers)</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum21" style="color: #606060;">  21:</span>         {</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum22" style="color: #606060;">  22:</span>             var cd = cdb <span style="color: #0000ff;">as</span> ChannelDispatcher;</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum23" style="color: #606060;">  23:</span>             <span style="color: #0000ff;">if</span> (cd != <span style="color: #0000ff;">null</span>)</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum24" style="color: #606060;">  24:</span>             {</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum25" style="color: #606060;">  25:</span>                 <span style="color: #0000ff;">foreach</span> (EndpointDispatcher ed <span style="color: #0000ff;">in</span> cd.Endpoints)</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum26" style="color: #606060;">  26:</span>                 {</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum27" style="color: #606060;">  27:</span>                     ed.DispatchRuntime.InstanceProvider =</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum28" style="color: #606060;">  28:</span>                         <span style="color: #0000ff;">new</span> DependencyInjectionInstanceProvider(serviceDescription.ServiceType);</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum29" style="color: #606060;">  29:</span>                 }</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum30" style="color: #606060;">  30:</span>             }</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum31" style="color: #606060;">  31:</span>         }</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum32" style="color: #606060;">  32:</span>     }</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum33" style="color: #606060;">  33:</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum34" style="color: #606060;">  34:</span>     <span style="color: #cc6633;">#endregion</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum35" style="color: #606060;">  35:</span> }</pre><br />
<!--CRLF--></p>
</div>
</div>
<p>So, the instance provider is able to retrieve a registration for our service using the service locator:</p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; font-family: 'Courier New', courier, monospace; direction: ltr; text-align: left; margin: 20px 0px 10px; line-height: 12pt; max-height: 200px; width: 97.5%; background-color: #f4f4f4; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre class="crayon-plain-tag"><span id="lnum1" style="color: #606060;">   1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> DependencyInjectionInstanceProvider : IInstanceProvider</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum2" style="color: #606060;">   2:</span> {</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum3" style="color: #606060;">   3:</span>     <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">readonly</span> Type serviceType;</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum4" style="color: #606060;">   4:</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum5" style="color: #606060;">   5:</span>     <span style="color: #0000ff;">public</span> DependencyInjectionInstanceProvider(Type serviceType)</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum6" style="color: #606060;">   6:</span>     {</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum7" style="color: #606060;">   7:</span>         <span style="color: #0000ff;">this</span>.serviceType = serviceType;</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum8" style="color: #606060;">   8:</span>     }</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum9" style="color: #606060;">   9:</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum10" style="color: #606060;">  10:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">object</span> GetInstance(InstanceContext instanceContext, Message message)</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum11" style="color: #606060;">  11:</span>     {</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum12" style="color: #606060;">  12:</span>         IServiceLocator serviceLocator = ServiceLocator.Current;</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum13" style="color: #606060;">  13:</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum14" style="color: #606060;">  14:</span>         <span style="color: #0000ff;">return</span> serviceLocator.GetInstance(serviceType);</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum15" style="color: #606060;">  15:</span>     }</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum16" style="color: #606060;">  16:</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum17" style="color: #606060;">  17:</span>     <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> ReleaseInstance(InstanceContext instanceContext, <span style="color: #0000ff;">object</span> instance)</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum18" style="color: #606060;">  18:</span>     {</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum19" style="color: #606060;">  19:</span>         <span style="color: #008000;">// if you container allows you to destroy instance</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum20" style="color: #606060;">  20:</span>         <span style="color: #008000;">// you can destroy your service instance here</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum21" style="color: #606060;">  21:</span>     }</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum22" style="color: #606060;">  22:</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum23" style="color: #606060;">  23:</span>     <span style="color: #cc6633;">#endregion</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum24" style="color: #606060;">  24:</span> }</pre><br />
<!--CRLF--></p>
</div>
</div>
<p>That’s it. Of course my container needs to know what is my service registration, and with Windsor I have two options:</p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; font-family: 'Courier New', courier, monospace; direction: ltr; text-align: left; margin: 20px 0px 10px; line-height: 12pt; max-height: 200px; width: 97.5%; background-color: #f4f4f4; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre class="crayon-plain-tag"><span id="lnum1" style="color: #606060;">   1:</span> <span style="color: #008000;">// option one, register the interface</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum2" style="color: #606060;">   2:</span> Component</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum3" style="color: #606060;">   3:</span>     .For&lt;IWriteService&gt;()</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum4" style="color: #606060;">   4:</span>     .ImplementedBy&lt;WriteService&gt;()</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum5" style="color: #606060;">   5:</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum6" style="color: #606060;">   6:</span> <span style="color: #008000;">// option two register the class</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum7" style="color: #606060;">   7:</span> Component</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum8" style="color: #606060;">   8:</span>     .For&lt;WriteService&gt;()</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum9" style="color: #606060;">   9:</span>     .ImplementedBy&lt;WriteService&gt;()</pre><br />
<!--CRLF--></p>
</div>
</div>
<p>And of course you need to change the markup of your .svc file depending on how you want to resolve the service, with the <em>interface</em> or with the<em>  class</em> type.</p>
<h2>Dependency Injection</h2>
<p>Now, let’s assume that my service needs an <em>IUnitOfWork</em> contract, how should we do that?</p>
<p>First of all we need to register both types in our container, and with Windsor one of the possible options is this one:</p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; font-family: 'Courier New', courier, monospace; direction: ltr; text-align: left; margin: 20px 0px 10px; line-height: 12pt; max-height: 200px; width: 97.5%; background-color: #f4f4f4; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre class="crayon-plain-tag"><span id="lnum1" style="color: #606060;">   1:</span> Component.For&lt;IUnitOfWork&gt;()</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum2" style="color: #606060;">   2:</span>             .ImplementedBy&lt;UnitOfWork&gt;(),</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum3" style="color: #606060;">   3:</span> Component</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum4" style="color: #606060;">   4:</span>     .For&lt;ICommandService&gt;()</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum5" style="color: #606060;">   5:</span>     .ImplementedBy&lt;CommandService&gt;(),</pre><br />
<!--CRLF--></p>
</div>
</div>
<p>And my command service is constructed in this way:</p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; font-family: 'Courier New', courier, monospace; direction: ltr; text-align: left; margin: 20px 0px 10px; line-height: 12pt; max-height: 200px; width: 97.5%; background-color: #f4f4f4; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre class="crayon-plain-tag"><span id="lnum1" style="color: #606060;">   1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> CommandService : ICommandService</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum2" style="color: #606060;">   2:</span> {</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum3" style="color: #606060;">   3:</span>     <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">readonly</span> IUnitOfWork unitOfWork;</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum4" style="color: #606060;">   4:</span></pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum5" style="color: #606060;">   5:</span>     <span style="color: #0000ff;">public</span> CommandService(IUnitOfWork unitOfWork)</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum6" style="color: #606060;">   6:</span>     {</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum7" style="color: #606060;">   7:</span>         <span style="color: #0000ff;">this</span>.unitOfWork = unitOfWork;</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum8" style="color: #606060;">   8:</span>     }</pre><br />
<!--CRLF--><br />
<pre class="crayon-plain-tag"><span id="lnum9" style="color: #606060;">   9:</span> }</pre><br />
<!--CRLF--></p>
</div>
</div>
<p><strong>Note for purist of CQRS</strong>: I know that a command service should get a command <em>dispatcher</em> injected but for this blog post I guess it would not make things clear enough, so a <em>unit of work</em> or an <em>IRepository</em> would make more sense.</p>
<div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:34ee017f-d621-477d-afbc-70f7c5e7a81c" style="float: none; margin: 0px; display: inline; padding: 0px;">Technorati Tags: <a href="http://technorati.com/tags/WCF" rel="tag">WCF</a>,<a href="http://technorati.com/tags/Dependency+Injection" rel="tag">Dependency Injection</a>,<a href="http://technorati.com/tags/Inversion+of+Control" rel="tag">Inversion of Control</a>,<a href="http://technorati.com/tags/Castle+Windsor" rel="tag">Castle Windsor</a></div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=GaqLpNuvyq4:z4_cJvO8Gdw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=GaqLpNuvyq4:z4_cJvO8Gdw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=GaqLpNuvyq4:z4_cJvO8Gdw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=GaqLpNuvyq4:z4_cJvO8Gdw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=GaqLpNuvyq4:z4_cJvO8Gdw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=GaqLpNuvyq4:z4_cJvO8Gdw:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=GaqLpNuvyq4:z4_cJvO8Gdw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/GaqLpNuvyq4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.raffaeu.com/archive/2013/01/31/wcf-and-dependency-inversion-using-castle-windsor.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.raffaeu.com/archive/2013/01/31/wcf-and-dependency-inversion-using-castle-windsor.aspx</feedburner:origLink></item>
		<item>
		<title>I got lucky this year, no end of the world.</title>
		<link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/NhqQMnlTgDE/i-got-lucky-this-year-no-end-of-the-world.aspx</link>
		<comments>http://blog.raffaeu.com/archive/2013/01/30/i-got-lucky-this-year-no-end-of-the-world.aspx#comments</comments>
		<pubDate>Wed, 30 Jan 2013 17:16:55 +0000</pubDate>
		<dc:creator>raffaeu</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Private]]></category>

		<guid isPermaLink="false">http://raffaeu.com/?p=14</guid>
		<description><![CDATA[This year has been seriously tough for me and my family, but finally we went beyond it successfully. So I guess it’s time for my first year review and new year proposals. 2012, relocation(s) In Spring 2012 we moved away from Bermuda after almost 5 years. The relocation has not been easy, after few months <span class="ellipsis">&#8230;</span> <span class="more-link-wrap"><a href="http://blog.raffaeu.com/archive/2013/01/30/i-got-lucky-this-year-no-end-of-the-world.aspx" class="more-link"><span>Read More &#8594;</span></a></span>]]></description>
				<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_button">
										<a name="fcbk_share"	href="http://www.facebook.com/raffaeu"	target="blank">
											<img src="http://blog.raffaeu.com/wp-content/plugins/facebook-button-plugin/img/standart-facebook-ico.jpg" alt="Fb-Button" />
										</a>	
									</div><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://blog.raffaeu.com/archive/2013/01/30/i-got-lucky-this-year-no-end-of-the-world.aspx" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>This year has been seriously tough for me and my family, but finally we went beyond it successfully. So I guess it’s time for my first year review and new year proposals.</p>
<h3>2012, relocation(s)</h3>
<p>In Spring 2012 we moved away from Bermuda after almost 5 years. The relocation has not been easy, after few months in Netherlands I got sick and I had to quit my job and take a long break. Unfortunately I didn’t take a serious break between Bermuda and Netherlands and my body couldn’t afford it. So, we decided to move to Italy and kite surf for a couple of months (which was quite successful and pleasant …) and take a break from any type of technology (phone, mail, web …).</p>
<p>It was a good break and overall I am quite happy I took it, even if it cost us a lot of money, being on vacation and not getting a revenue. But I personally believe that life is one and health and family come before everything else. That’s it.    <br />Btw I also cured my problem and now I am back in shape and ready for my daily activities, which include this blog.</p>
<p>In November we decided to move back to Netherlands and I successfully signed a new contract for a position of Software Architect for <a href="http://www.mproof.nl" target="_blank">Mproof</a>, a Dutch Software House. The environment is really Agile and friendly and this is making me an “happy coder”. Plus I am working remotely with a team in Ukraine, which I recently visited. It was a nice trip and I was able to share some Agile workshops about SOLID and TDD. I am also quite happy seeing new coders embracing Agile without prejudices.</p>
<p>Recently I also attended the XP days (Agile conference) in Netherlands and I had the pleasure to interact with some Europeans coders and architects. I guess I would speak about Agile and NET, next year and the next XP days, not sure about what yet.</p>
<p>Unfortunately I had to quit a lot of extra activities for a while, such as “blog”, “open source”, “studying”, “certifications” and so on … I had some health problems and the laptop was one of my first enemies during these months so I couldn’t interact with technologies for a while until I was fine. My wife was very helpful during this time and we found in the kite surf a good cure for stress.</p>
<h3>Overall expectations</h3>
<p>Well, if you ask me now, I can easily say that at the beginning of 2012 we were not planning to leave Bermuda yet, especially for the economical crisis around the world. The relocation was a shock for the family because we were almost used to Bermuda were everything is “another world”, so you can imagine the shock after few months of city living. After we left Bermuda we had some plans but sometimes reality is much different and you need to “adapt” your plans to reality.</p>
<ul>
<li>I completed my IASA certification and in my backlog there is my third book.</li>
<li>I couldn’t complete the code of my previous books but my readers can now access all my code on TFS 2012.</li>
<li>I finally complete my learning process on kite surfing, even if I can’t jump yet, and I found it a really nice and cool sport.</li>
<li>We successfully relocated to Netherlands and this was my dream when I was a kid. I also got a new job which it’s quite challenging right now and of course well paid! <img class="wlEmoticon wlEmoticon-hotsmile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Hot smile" src="http://raffaeu.com/wp-content/uploads/2013/03/980a0ab4-6397-4469-be50-4bca6819a133wlEmoticon-hotsmile_2.png"></li>
</ul>
<h3>Plans for 2013</h3>
<p>I have few plans for 2013 but I will do my best to accomplish them. First of all learn Dutch, you can easily live in Netherlands without speaking Dutch, but you will never be “part of it” if you know what I mean. Because I am good European citizen I don’t regret to learn a new European language, even if I can say already that Dutch is a pretty damn difficult language to learn. <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smile" src="http://raffaeu.com/wp-content/uploads/2013/03/9856f515-a27a-485e-95f5-d5c76af2cca9wlEmoticon-smile_2.png"> </p>
<p>Move back to my blog and show a lot of Agile samples, complete my blog migration on WordPress because I am quite disappointed about Subtext roadmap at the moment. </p>
<p>Totally embrace Agile at my current employer. </p>
<p>Kite surf and be back to gym. Write my third book. Plus I have some private plans with my family that I can’t share with you… <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smile" src="http://raffaeu.com/wp-content/uploads/2013/03/b41f2c46-0799-407d-8dd6-74446bba80e8wlEmoticon-smile_2.png"></p>
<p>The plans over my blog will all be related to my new book, so you will be able to “taste” a little bit of it over my next blog’s posts. I got a free account on TFS 2012 and I am publishing all my projects over there so that anyone of you can simply go there and get the latest version of what’s available.</p>
<p>I am not sure yet, but I would like to re-start to speak at public conferences, I think the XP days would be a good re-start.</p>
<p>For now that’s it!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=NhqQMnlTgDE:1X7VlayX3uc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=NhqQMnlTgDE:1X7VlayX3uc:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=NhqQMnlTgDE:1X7VlayX3uc:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=NhqQMnlTgDE:1X7VlayX3uc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=NhqQMnlTgDE:1X7VlayX3uc:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=NhqQMnlTgDE:1X7VlayX3uc:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=NhqQMnlTgDE:1X7VlayX3uc:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/NhqQMnlTgDE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.raffaeu.com/archive/2013/01/30/i-got-lucky-this-year-no-end-of-the-world.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.raffaeu.com/archive/2013/01/30/i-got-lucky-this-year-no-end-of-the-world.aspx</feedburner:origLink></item>
		<item>
		<title>TDD a WCF service, is it possible?</title>
		<link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/S203FWOOk5U/tdd-a-wcf-service-is-it-possible.aspx</link>
		<comments>http://blog.raffaeu.com/archive/2013/01/29/tdd-a-wcf-service-is-it-possible.aspx#comments</comments>
		<pubDate>Tue, 29 Jan 2013 14:58:55 +0000</pubDate>
		<dc:creator>raffaeu</dc:creator>
				<category><![CDATA[TDD]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://raffaeu.com/?p=15</guid>
		<description><![CDATA[Right now I am working on a CQRS project, and I am using WCF as my web service technology. In this project I decided to challenge myself and make a full TDD project. The first big problem I found was to simulate a real web server, because I didn’t want to hit a production or <span class="ellipsis">&#8230;</span> <span class="more-link-wrap"><a href="http://blog.raffaeu.com/archive/2013/01/29/tdd-a-wcf-service-is-it-possible.aspx" class="more-link"><span>Read More &#8594;</span></a></span>]]></description>
				<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_button">
										<a name="fcbk_share"	href="http://www.facebook.com/raffaeu"	target="blank">
											<img src="http://blog.raffaeu.com/wp-content/plugins/facebook-button-plugin/img/standart-facebook-ico.jpg" alt="Fb-Button" />
										</a>	
									</div><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://blog.raffaeu.com/archive/2013/01/29/tdd-a-wcf-service-is-it-possible.aspx" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>Right now I am working on a <a href="http://martinfowler.com/bliki/CQRS.html" target="_blank">CQRS</a> project, and I am using WCF as my web service technology. In this project I decided to challenge myself and make a full TDD project. The first big problem I found was to simulate a real web server, because I didn’t want to hit a production or QA environment to run my tests.     <br />Second I didn’t want to write any integration test at all, so I had to figure out how to create an <em>in-Process</em> test to run my WCF methods.</p>
<blockquote><p><em>Why in-process test? When you write a unit test, you should test a single functionality, and in order to make the test atomic, it should run in-process. It should not involve third party tiers like a database or IIS, otherwise the test won’t be in-process anymore, so it will became an Integration test.</em></p>
</blockquote>
<p>The first idea I came out was to fake the behaviour of IIS, and in order to accomplish this I could easily work with a mock framework like <a href="http://www.typemock.com/" target="_blank">Typemock</a> and mock out the entire IIS infrastructure.</p>
<p>Is this what I really want? Not at all. I don’t want and I don’t need to fake the behaviour of IIS, I need an instance of it because my WCF services are using custom factories and custom behaviours and I need to be sure they are acting in the right way.</p>
<p>So I have created two different type of tests. The first one is pure Unit Test, where I verify the command behaviours:</p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; width: 97.5%; background-color: #f4f4f4">
<div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">     <pre class="crayon-plain-tag"><span id="lnum1" style="color: #606060">   1:</span> [TestMethod]</pre><br />
<!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum2" style="color: #606060">   2:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> AddUsersCommandHandler_ValidCommand_WillPersist()</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum3" style="color: #606060">   3:</span> {</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum4" style="color: #606060">   4:</span>     <span style="color: #008000">// arrange</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum5" style="color: #606060">   5:</span>     AddUsersCommand expectedCommand = <span style="color: #0000ff">new</span> AddUsersCommand { UsersStream = expectedStream };</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum6" style="color: #606060">   6:</span>     <span style="color: #008000">// service with mocked unit of work</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum7" style="color: #606060">   7:</span>     IServiceCommandHandler&lt;AddUsersCommand&gt; handler = <span style="color: #0000ff">new</span> AddUsersCommandHandler(mockUnit.Object);</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum8" style="color: #606060">   8:</span> </pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum9" style="color: #606060">   9:</span>     <span style="color: #008000">// act</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum10" style="color: #606060">  10:</span>     handler.Handle(expectedCommand);</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum11" style="color: #606060">  11:</span> </pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum12" style="color: #606060">  12:</span>     <span style="color: #008000">// assertions against the command behaviour</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum13" style="color: #606060">  13:</span>     mockUnit</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum14" style="color: #606060">  14:</span>         .Verify(x =&gt; x.BeginTransaction(), Times.Once());</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum15" style="color: #606060">  15:</span>     mockUnit</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum16" style="color: #606060">  16:</span>         .Verify(x =&gt; x.Save(It.IsAny&lt;User&gt;()));</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum17" style="color: #606060">  17:</span>     mockUnit</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum18" style="color: #606060">  18:</span>         .Verify(x =&gt; x.CommitTransaction(), Times.Once());</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum19" style="color: #606060">  19:</span> }</pre><p><!--CRLF--></div>
</div>
<p>The second one is the (in)famous integration test, where you call the WCF service and test the overall process. Unfortunately for the second step I couldn’t find anything really TDD so I had to figure out by myself a different solution.</p>
<h2>IIS Express</h2>
<p>Yesterday I spent some time googling around for a solution while I found a nice <a href="http://weblogs.asp.net/scottgu/archive/2010/06/28/introducing-iis-express.aspx" target="_blank">post from Scott Gu</a> about IIS express. With IIS express we have an in-process IIS server that we can startup or shutdown at any time during the lifecycle of our tests. It provides almost all the functionalities provided by IIS and it also trigger the <em>Application_Start</em> event, something not very well handled by Cassini …</p>
<p>So, first of all I had to figure out how to bootstrap my unit tests to run over a different IIS than the one configured in the web.config.</p>
<p>Piece of cake, first of all I need something that allows me to bootstrap IIS express before my unit test harness starts:</p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; height: 273px; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; width: 97.5%; background-color: #f4f4f4">
<div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">
    <pre class="crayon-plain-tag"><span id="lnum1" style="color: #606060">   1:</span> [ClassInitialize]</pre><br />
<!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum2" style="color: #606060">   2:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> ClassInitialize(TestContext context)</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum3" style="color: #606060">   3:</span> {</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum4" style="color: #606060">   4:</span>     <span style="color: #008000">// create a process for IIS express</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum5" style="color: #606060">   5:</span>     issProcess = <span style="color: #0000ff">new</span> Thread(IssUtility.StartIisExpress)</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum6" style="color: #606060">   6:</span>                  {</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum7" style="color: #606060">   7:</span>                     IsBackground = <span style="color: #0000ff">true</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum8" style="color: #606060">   8:</span>                  };</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum9" style="color: #606060">   9:</span>     <span style="color: #008000">// start it</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum10" style="color: #606060">  10:</span>     issProcess.Start();</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum11" style="color: #606060">  11:</span>     <span style="color: #008000">// create a new channel factory using the generated URL</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum12" style="color: #606060">  12:</span>     factory = <span style="color: #0000ff">new</span> ChannelFactory&lt;IDomainWriteService&gt;(</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum13" style="color: #606060">  13:</span>        <span style="color: #0000ff">new</span> BasicHttpBinding(),</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum14" style="color: #606060">  14:</span>        <span style="color: #0000ff">new</span> EndpointAddress(<span style="color: #006080">"http://localhost:5555/services/DomainWriteService.svc"</span>));</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum15" style="color: #606060">  15:</span> }</pre><p><!--CRLF--></div>
</div>
<p>Then I need another utility to kill everything when my test harness is done:</p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; width: 97.5%; background-color: #f4f4f4">
<div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">
    <pre class="crayon-plain-tag"><span id="lnum1" style="color: #606060">   1:</span> [ClassCleanup]</pre><br />
<!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum2" style="color: #606060">   2:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> ClassCleanup()</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum3" style="color: #606060">   3:</span> {</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum4" style="color: #606060">   4:</span>     <span style="color: #008000">// close the WCF factory</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum5" style="color: #606060">   5:</span>     factory.Close();</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum6" style="color: #606060">   6:</span>     <span style="color: #008000">// shutdown IIS express</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum7" style="color: #606060">   7:</span>     IssUtility.TearDownIis();</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum8" style="color: #606060">   8:</span>     issProcess.Abort();</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum9" style="color: #606060">   9:</span> }</pre><p><!--CRLF--></div>
</div>
<p>At this point I can write any test in the following format:</p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; width: 97.5%; background-color: #f4f4f4">
<div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">
    <pre class="crayon-plain-tag"><span id="lnum1" style="color: #606060">   1:</span> [TestMethod]</pre><br />
<!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum2" style="color: #606060">   2:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> ChannelFactory_ReceiveValidCommand_WillExecute()</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum3" style="color: #606060">   3:</span> {</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum4" style="color: #606060">   4:</span>     var expectedCommand = BuildAddUsersCommand();</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum5" style="color: #606060">   5:</span>     service.AddUsers(expectedCommand);</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum6" style="color: #606060">   6:</span> }</pre><p><!--CRLF--></div>
</div>
<p>I found this technique very useful because we work with TFS on Azure so my Build environment cannot be polluted at all with any third party components or by installing the WCF service under test in the build machine.</p>
<p>In the same way I found very quick to bootstrap IIS express for my tests, honestly they are faster than running on my local IIS 8.</p>
<h2>IIS Express utility class</h2>
<p>Below is the code I use to initialize IIS express, feel free to use it in your tests and let me know if you come up with a better solution than this one.</p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; width: 97.5%; background-color: #f4f4f4">
<div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">
    <pre class="crayon-plain-tag"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">namespace</span> xxx</pre><br />
<!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum2" style="color: #606060">   2:</span> {</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum3" style="color: #606060">   3:</span>     <span style="color: #0000ff">using</span> System.Diagnostics;</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum4" style="color: #606060">   4:</span> </pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum5" style="color: #606060">   5:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> IssUtility</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum6" style="color: #606060">   6:</span>     {</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum7" style="color: #606060">   7:</span>         <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> Process iisProcess;</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum8" style="color: #606060">   8:</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum9" style="color: #606060">   9:</span>         <span style="color: #008000">// Start IIS on port 5555</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum10" style="color: #606060">  10:</span>         <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> StartIisExpress()</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum11" style="color: #606060">  11:</span>         {</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum12" style="color: #606060">  12:</span>             var startInfo = <span style="color: #0000ff">new</span> ProcessStartInfo</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum13" style="color: #606060">  13:</span>                 {</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum14" style="color: #606060">  14:</span>                     WindowStyle = ProcessWindowStyle.Normal,</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum15" style="color: #606060">  15:</span>                     ErrorDialog = <span style="color: #0000ff">true</span>,</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum16" style="color: #606060">  16:</span>                     LoadUserProfile = <span style="color: #0000ff">true</span>,</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum17" style="color: #606060">  17:</span>                     CreateNoWindow = <span style="color: #0000ff">false</span>,</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum18" style="color: #606060">  18:</span>                     UseShellExecute = <span style="color: #0000ff">false</span>,</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum19" style="color: #606060">  19:</span>                     Arguments =</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum20" style="color: #606060">  20:</span>                         <span style="color: #0000ff">string</span>.Format(<span style="color: #006080">"/path:\"{0}\" /port:{1}"</span>,</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum21" style="color: #606060">  21:</span>                                         <span style="color: #006080">@"your WCF dev path"</span>, 5555)</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum22" style="color: #606060">  22:</span>                 };</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum23" style="color: #606060">  23:</span> </pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum24" style="color: #606060">  24:</span>             var programfiles = <span style="color: #0000ff">string</span>.IsNullOrEmpty(startInfo.EnvironmentVariables[<span style="color: #006080">"programfiles"</span>])</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum25" style="color: #606060">  25:</span>                                     ? startInfo.EnvironmentVariables[<span style="color: #006080">"programfiles(x86)"</span>]</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum26" style="color: #606060">  26:</span>                                     : startInfo.EnvironmentVariables[<span style="color: #006080">"programfiles"</span>];</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum27" style="color: #606060">  27:</span> </pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum28" style="color: #606060">  28:</span>             startInfo.FileName = programfiles + <span style="color: #006080">"\\IIS Express\\iisexpress.exe"</span>;</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum29" style="color: #606060">  29:</span> </pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum30" style="color: #606060">  30:</span>             <span style="color: #0000ff">try</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum31" style="color: #606060">  31:</span>             {</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum32" style="color: #606060">  32:</span>                 iisProcess = <span style="color: #0000ff">new</span> Process {StartInfo = startInfo};</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum33" style="color: #606060">  33:</span> </pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum34" style="color: #606060">  34:</span>                 iisProcess.Start();</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum35" style="color: #606060">  35:</span>                 iisProcess.WaitForExit();</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum36" style="color: #606060">  36:</span>             }</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum37" style="color: #606060">  37:</span>             <span style="color: #0000ff">catch</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum38" style="color: #606060">  38:</span>             {</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum39" style="color: #606060">  39:</span>                 iisProcess.CloseMainWindow();</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum40" style="color: #606060">  40:</span>                 iisProcess.Dispose();</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum41" style="color: #606060">  41:</span>             }</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum42" style="color: #606060">  42:</span>         }</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum43" style="color: #606060">  43:</span> </pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum44" style="color: #606060">  44:</span>         <span style="color: #008000">// kill everything</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum45" style="color: #606060">  45:</span>         <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> TearDownIis()</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum46" style="color: #606060">  46:</span>         {</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum47" style="color: #606060">  47:</span>             iisProcess.CloseMainWindow();</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum48" style="color: #606060">  48:</span>             iisProcess.Dispose();</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum49" style="color: #606060">  49:</span>         }</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum50" style="color: #606060">  50:</span>     }</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum51" style="color: #606060">  51:</span> }</pre><p><!--CRLF--></div>
</div>
<p>Enjoy!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=S203FWOOk5U:PVC_HvgiSOA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=S203FWOOk5U:PVC_HvgiSOA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=S203FWOOk5U:PVC_HvgiSOA:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=S203FWOOk5U:PVC_HvgiSOA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=S203FWOOk5U:PVC_HvgiSOA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=S203FWOOk5U:PVC_HvgiSOA:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=S203FWOOk5U:PVC_HvgiSOA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/S203FWOOk5U" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.raffaeu.com/archive/2013/01/29/tdd-a-wcf-service-is-it-possible.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.raffaeu.com/archive/2013/01/29/tdd-a-wcf-service-is-it-possible.aspx</feedburner:origLink></item>
		<item>
		<title>Agile Architecture.</title>
		<link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/u9zCLutILLY/agile-architecture.aspx</link>
		<comments>http://blog.raffaeu.com/archive/2012/05/15/agile-architecture.aspx#comments</comments>
		<pubDate>Tue, 15 May 2012 09:24:14 +0000</pubDate>
		<dc:creator>raffaeu</dc:creator>
				<category><![CDATA[Design Pattern]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[TypeMock]]></category>

		<guid isPermaLink="false">http://raffaeu.com/?p=16</guid>
		<description><![CDATA[Last week I presented a webinar about Agile Architecture and I got an unexpected positive feedback from it. First it was unexpected because I didn’t expect to get lot of people interested in this particular topic. Second it was unexpected because I am still at the beginning of my teaching career and presenting webinars so <span class="ellipsis">&#8230;</span> <span class="more-link-wrap"><a href="http://blog.raffaeu.com/archive/2012/05/15/agile-architecture.aspx" class="more-link"><span>Read More &#8594;</span></a></span>]]></description>
				<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_button">
										<a name="fcbk_share"	href="http://www.facebook.com/raffaeu"	target="blank">
											<img src="http://blog.raffaeu.com/wp-content/plugins/facebook-button-plugin/img/standart-facebook-ico.jpg" alt="Fb-Button" />
										</a>	
									</div><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://blog.raffaeu.com/archive/2012/05/15/agile-architecture.aspx" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>Last week I presented a webinar about Agile Architecture and I got an unexpected positive feedback from it. First it was unexpected because I didn’t expect to get lot of people interested in this particular topic. Second it was unexpected because I am still at the beginning of my teaching career and presenting webinars so I am not so good yet to keep the audience interested for 60 min.</p>
<p>Btw, considering the result of the webinar, I decided to post the video of the webinar (thanks to the guys of <a href="http://www.typemock.com/" target="_blank">Typemock</a>!) and a short introduction to <a href="http://www.agilearchitect.org/" target="_blank">Agile Architecture</a>.</p>
<h4>Agile Architecture webinar:</h4>
<div style="border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; border-bottom: #cccccc 1px solid; margin: 2px; border-left: #cccccc 1px solid"><iframe height="300" src="http://player.vimeo.com/video/42069572" frameborder="0" width="400" mozallowfullscreen="mozallowfullscreen" webkitallowfullscreen="webkitallowfullscreen" allowfullscreen="allowfullscreen"></iframe></div>
<h4 style="Border: 1px solid #CCCCCC; Padding:2px;Background: #FFFF66">Update: slides available on SlideShare.</h4>
<div style="width:425px" id="__ss_12951051"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/raffaeu/software-architecture-in-an-agile-environment" title="Software architecture in an agile environment" target="_blank">Software architecture in an agile environment</a></strong> <object id="__sse12951051" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=softwarearchitectureinanagileenvironment-120516020742-phpapp02&amp;stripped_title=software-architecture-in-an-agile-environment&amp;userName=raffaeu"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><param name="wmode" value="transparent"><embed name="__sse12951051" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=softwarearchitectureinanagileenvironment-120516020742-phpapp02&amp;stripped_title=software-architecture-in-an-agile-environment&amp;userName=raffaeu" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="425" height="355"> </object>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/raffaeu" target="_blank">Raffaele Garofalo</a> </div>
</p></div>
<h3>Agile architecture</h3>
<p>What is Agile Architecture? It is a methodology that follows the Agile guidelines but differ from some aspect of its process. </p>
<p>At this web address: <a title="http://www.agilearchitect.org/" href="http://www.agilearchitect.org/">http://www.agilearchitect.org/</a> you can find <em>probably</em> the official website of this Agile methodology, even if you may find a lot of interesting discussions and articles here and there on the web, just <a href="http://www.google.com/#hl=en&amp;gs_nf=1&amp;cp=13&amp;gs_id=1d&amp;xhr=t&amp;q=agile+architecture&amp;pf=p&amp;safe=off&amp;output=search&amp;sclient=psy-ab&amp;oq=agile+archite&amp;aq=0&amp;aqi=g4&amp;aql=&amp;gs_l=&amp;pbx=1&amp;bav=on.2,or.r_gc.r_pw.r_qf.,cf.osb&amp;fp=12ac40e9db346b04&amp;biw=1280&amp;bih=647" target="_blank">google “Agile Architecture”</a>. </p>
<p>Another interesting web site is <a href="http://www.agilemodeling.com/">http://www.agilemodeling.com/</a> where you can find tons of information about Agile Modeling and Agile Architecture. (<em>If you watch the webinar I spoke about both of them</em>).</p>
<p>Finally, if you want just to read a quick article and understand the overall process of Agile Architecture, I found this article of <a href="http://shapingsoftware.com/about/" target="_blank">J.D. Meier</a> very helpful: “<a href="http://apparch.codeplex.com/wikipage?title=How%20To%20-%20Design%20Using%20Agile%20Architecture" target="_blank">How to design with Agile Architecture</a>”.</p>
<h3>TFS Template</h3>
<p>I got various requests about the TFS and Dashboard templates I used during the webinar. I got them from the beta of Team Foundation Server 2011, available <a href="http://msdn.microsoft.com/en-us/vstudio/ff637362" target="_blank">here</a>. You need to customize the process to fit better Agile Architecture methodology. I am planning to prepare a custom template for TFS 2011 as soon as the SDK will be finalized. </p>
<h3>Q/A from the webinar</h3>
<p>Below is a short list of some of the most interesting Questions and Answers I got during the webinar. I am posting them here because during the webinar I wasn’t able to read them because I am using the MAC version of GoToWebinar.</p>
<p><strong>Q: Acceptance Tests should have been written before the model.</strong></p>
<p><em>Not really, if you adopt the strict TDD all the acceptance tests should be written before, but when you envision the architecture, it is too early to write acceptance     <br />tests. When you start the iteration and you have your requirements defined, you may start to model against the acceptance criteria for that iteration. But remember      <br />that the modeling part should be light enough to provide value for the next step.</em></p>
<p><strong>Q: the functions of the architect are clear, but it is not clear how these functions are intended to fit into the Sprints.</strong></p>
<p><em>The sprint is composed by three parts, modeling, brainstorm and coding. The architect will perfectly fit into each of this phase. I think I have explained this     <br />concept during the webinar, but just to be sure. During modeling and brainstorm the architect should help with his knowledge and collaborate in the modeling, during      <br />the coding he should be an active coder too and contribute to the technical decisions providing knowledge and expertise.</em></p>
<p><strong>Q: Can you elaborate on what you mean with the &#8220;design phase&#8221;?</strong></p>
<p><em>Ok, during the first iteration, the envision, there is a light design phase. You should design some scratches of your envision, representing the architecture and the UI, but you should not invest too much time.     <br />Design phase while modeling means adopting UML to design your models.</em></p>
<p><strong>Q: How does your &#8220;Iter: 0&#8243; relate to the PO, backlog and sprint planning?</strong></p>
<p><em>Ah ah, interesting. The envision or iteration 0 is tricky to fit into SCRUM. Take the classic meter to measure an iteration, like 1 or 2 weeks. Inside this timeframe you should have enough space and time to prepare the necessary analysis and mocks required by next steps. So you may consider iter 0 like a beginning sprint.</em> </p>
<p><strong>Q: Couldn&#8217;t the use-case diagram be enough for the modelling phase? I&#8217;m interested in hearing your reasoning because I&#8217;m currently in this situation in my current project. What level of detail is enough when it comes to architecture that lets developers use their brain and problem solving power?</strong></p>
<p><em>No, the use case is not enough because it may incur into personal interpretation. With the use case and the acceptance you and your team are ready for the modeling phase, where you create the architectural style for that feature. The modeling should be enough to represent the current feature and it should not be implemented, the implementation occurs in the next phase where you apply TDD against the model discussed in the previous part. It is hard to keep the model the blueprint of the code and often it doesn&#8217;t provide value. It is important that the model represents what you are delivering.</em></p>
<p><strong>Q: Does the Process workflow you describe impact the philosophy of embracing change? How can we perform radical change when we get a bigger up-front model? </strong></p>
<p><em>No, it doesn&#8217;t because Agile Architecture pretends the flexibility into your model. Model just enough to represents the feature and remember that you can always come back and re-model and re-factor. Embracing Agile Architecture will force you to have a dynamic more agnostic and flexible model than using a classic architecture approach.      <br />Why would you get a radical change request with a radical model upfront? Of you adopt Agile you should structure these changes into small iterations.</em></p>
<p><em>The envision phase is the most critical, you or the architect need to understand what the stakeholder wants from your team. If you get that, you are in a good starting position.     <br />The big mistake is to take too much for the envision, which is not the modeling phase. Mocking out your application doesn&#8217;t mean to model everything, so the envision should take few days, at most one week. If it takes more you may have some smells in your team: lack of requirements, lack of business knowledge, lack of technical knowledge.      <br />Remember that every iteration has a modeling phase and a brainstorm phase, so you may move back to the envision and adapt it to the new requirements.</em>    </p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:347fbe6a-85f9-4232-a2b1-1b59e51b5f50" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">Technorati Tags: <a href="http://technorati.com/tags/Agile+Architecture" rel="tag">Agile Architecture</a>,<a href="http://technorati.com/tags/Agile" rel="tag">Agile</a>,<a href="http://technorati.com/tags/Scrum" rel="tag">Scrum</a>,<a href="http://technorati.com/tags/Agile+Modeling" rel="tag">Agile Modeling</a>,<a href="http://technorati.com/tags/Typemock" rel="tag">Typemock</a>,<a href="http://technorati.com/tags/Webinar" rel="tag">Webinar</a></div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=u9zCLutILLY:rHj4Ew_9X5w:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=u9zCLutILLY:rHj4Ew_9X5w:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=u9zCLutILLY:rHj4Ew_9X5w:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=u9zCLutILLY:rHj4Ew_9X5w:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=u9zCLutILLY:rHj4Ew_9X5w:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=u9zCLutILLY:rHj4Ew_9X5w:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=u9zCLutILLY:rHj4Ew_9X5w:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/u9zCLutILLY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.raffaeu.com/archive/2012/05/15/agile-architecture.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.raffaeu.com/archive/2012/05/15/agile-architecture.aspx</feedburner:origLink></item>
		<item>
		<title>Speaking about Agile Architecture</title>
		<link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/DUxhpjz5P-M/speaking-about-agile-architecture.aspx</link>
		<comments>http://blog.raffaeu.com/archive/2012/05/03/speaking-about-agile-architecture.aspx#comments</comments>
		<pubDate>Thu, 03 May 2012 18:25:08 +0000</pubDate>
		<dc:creator>raffaeu</dc:creator>
				<category><![CDATA[About]]></category>
		<category><![CDATA[Design Pattern]]></category>
		<category><![CDATA[Private]]></category>
		<category><![CDATA[TypeMock]]></category>

		<guid isPermaLink="false">http://raffaeu.com/?p=19</guid>
		<description><![CDATA[The 9th of May 2012 at 2 p.m. (GMT +1) I will speak about Agile Architecture. The webinar will be registered and hosted by Typemock. This is the address to register: https://www2.gotomeeting.com/register/427749090 Below is the Agenda and you are still in time to add some little changes: What is Software Architecture • What is Agile <span class="ellipsis">&#8230;</span> <span class="more-link-wrap"><a href="http://blog.raffaeu.com/archive/2012/05/03/speaking-about-agile-architecture.aspx" class="more-link"><span>Read More &#8594;</span></a></span>]]></description>
				<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_button">
										<a name="fcbk_share"	href="http://www.facebook.com/raffaeu"	target="blank">
											<img src="http://blog.raffaeu.com/wp-content/plugins/facebook-button-plugin/img/standart-facebook-ico.jpg" alt="Fb-Button" />
										</a>	
									</div><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://blog.raffaeu.com/archive/2012/05/03/speaking-about-agile-architecture.aspx" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>The 9th of May 2012 at 2 p.m. (GMT +1) I will speak about Agile Architecture. The webinar will be registered and hosted by <a href="http://www.typemock.com/" target="_blank">Typemock</a>.</p>
<p>This is the address to register: <a href="https://www2.gotomeeting.com/register/427749090">https://www2.gotomeeting.com/register/427749090</a></p>
<p>Below is the Agenda and you are still in time to add some little changes:</p>
<p><strong>What is Software Architecture</strong>    <br />• What is Agile development    <br />• How they can live together?    <br /><strong>Discover principles of Agile architecture</strong>    <br />• Lifecycle and process    <br />• Modeling and development    <br />• The right solution for the right problem    <br />• How to deliver quality with (TDD)</p>
<p>If you want to listen about this topic or more feel free to drop me an e-mail (<em>using my blog contact form</em>) and I will be more than glad to expand it during the webinar. Of course it has to be something related to Agile Architecture … <img class="wlEmoticon wlEmoticon-winkingsmile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Winking smile" src="http://raffaeu.com/wp-content/uploads/2013/03/1a77486d-6b6b-463e-bbe7-6ffafdb7480cwlEmoticon-winkingsmile_2.png"></p>
<p>If you want to read more about it I would suggest you the following articles:</p>
<p>Agile Architect principles   <br /><a title="http://www.agilearchitect.org/agile/principles.htm" href="http://www.agilearchitect.org/agile/principles.htm">http://www.agilearchitect.org/agile/principles.htm</a></p>
<p>J.D. Meier “Agile Architecture”   <br /><a title="http://blogs.msdn.com/b/jmeier/archive/2008/11/06/agile-architecture-method.aspx" href="http://blogs.msdn.com/b/jmeier/archive/2008/11/06/agile-architecture-method.aspx">http://blogs.msdn.com/b/jmeier/archive/2008/11/06/agile-architecture-method.aspx</a></p>
<p><strong>PS:</strong> I guess if we are numerous I may get a Typemock license available for free to one of the attendee. <img class="wlEmoticon wlEmoticon-winkingsmile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Winking smile" src="http://raffaeu.com/wp-content/uploads/2013/03/581df1a5-fd0a-48e7-a7c0-041f8fc20199wlEmoticon-winkingsmile_2.png"></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=DUxhpjz5P-M:9e4IrJ64c1w:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=DUxhpjz5P-M:9e4IrJ64c1w:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=DUxhpjz5P-M:9e4IrJ64c1w:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=DUxhpjz5P-M:9e4IrJ64c1w:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=DUxhpjz5P-M:9e4IrJ64c1w:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=DUxhpjz5P-M:9e4IrJ64c1w:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=DUxhpjz5P-M:9e4IrJ64c1w:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/DUxhpjz5P-M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.raffaeu.com/archive/2012/05/03/speaking-about-agile-architecture.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.raffaeu.com/archive/2012/05/03/speaking-about-agile-architecture.aspx</feedburner:origLink></item>
		<item>
		<title>NCache with .NET 4</title>
		<link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/SxUbVs-aY4Q/ncache-with-net-4.aspx</link>
		<comments>http://blog.raffaeu.com/archive/2012/04/22/ncache-with-net-4.aspx#comments</comments>
		<pubDate>Sun, 22 Apr 2012 20:17:18 +0000</pubDate>
		<dc:creator>raffaeu</dc:creator>
				<category><![CDATA[NCache]]></category>
		<category><![CDATA[NET World]]></category>

		<guid isPermaLink="false">http://raffaeu.com/?p=49</guid>
		<description><![CDATA[I am very excited about this new series I am publishing today. It’s all about caching, a very useful portion of your architecture that should be seriously taken into consideration, especially if you are designing a web application. Actually, I used NCache with NHibernate and I can only say that it is a very good <span class="ellipsis">&#8230;</span> <span class="more-link-wrap"><a href="http://blog.raffaeu.com/archive/2012/04/22/ncache-with-net-4.aspx" class="more-link"><span>Read More &#8594;</span></a></span>]]></description>
				<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_button">
										<a name="fcbk_share"	href="http://www.facebook.com/raffaeu"	target="blank">
											<img src="http://blog.raffaeu.com/wp-content/plugins/facebook-button-plugin/img/standart-facebook-ico.jpg" alt="Fb-Button" />
										</a>	
									</div><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://blog.raffaeu.com/archive/2012/04/22/ncache-with-net-4.aspx" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>I am very excited about this new series I am publishing today. It’s all about caching, a very useful portion of your architecture that should be seriously taken into consideration, especially if you are designing a web application.</p>
<p>Actually, I used <a href="http://www.alachisoft.com/ncache/" target="_blank">NCache</a> with <a href="http://nhforge.org/Default.aspx" target="_blank">NHibernate</a> and I can only say that it is a very good and valuable product. Of course most of you may believe that I got a free license so this is the reason of my review. Actually I am reviewing this product because I found it pretty good and that’s why the review came up with a short series of articles.</p>
<p>I will show you the following features of <a href="http://www.alachisoft.com/ncache/" target="_blank">NCache</a>:</p>
<ul>
<li><a href="http://blog.raffaeu.com/archive/2012/04/22/ncache-with-net-4.aspx" target="_blank">NCache architecture</a> </li>
<li><a href="http://blog.raffaeu.com/archive/2012/04/22/ncache-simple-caching-of-objects.aspx" target="_blank">Simple caching of objects</a> </li>
<li>Caching of complex graph </li>
<li>Control the lifetime of a cache </li>
</ul>
<h3>Introduction</h3>
<p>From <a href="http://www.alachisoft.com/ncache/" target="_blank">NCache</a> documentation:</p>
<blockquote><p><a href="http://www.alachisoft.com/ncache/" target="_blank">NCache</a> is a clustered caching solution that makes sharing and managing data in a cluster as simple as on a single server. It accomplishes this by coordinating updates to the data using cluster-wide concurrency control and replicating and distributing data modifications across the cluster using the highest performing clustered protocol available. The primary purpose of <a href="http://www.alachisoft.com/ncache/" target="_blank">NCache</a> is to help improve performance of .NET applications that would otherwise make expensive trips to database systems, web services, mainframes, or other systems across the network.</p>
</blockquote>
<p>Below is a very simplified diagram of NCache architecture (<em>please forgive me for the simplicity of this architecture design)</em>:</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/017cda4f-4212-49e3-ac7c-4784a6eaef33image_2.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/23942c85-2a87-47f5-a291-103ccfacabc7image_thumb.png" width="260" height="242"></a></p>
<h3>So, how does it work?</h3>
<p>The explanation is pretty simple but in the same time is represented by a complex architecture. You can have two different type of Cache, a local cache or a remote cache. The first one will work because the client has a cache server installed locally, the second one will work with the client accessing the remote cache server from the network.</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/8a4fab1c-2f88-4944-8a80-05736b1c8efeimage_4.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/960fc9e4-e392-4b38-8d97-546ff53cfb7bimage_thumb_1.png" width="260" height="181"></a></p>
<p>Of course you can easily swap from a local configuration to a remote configuration without even need to restart or rebuild your application, plus you can easily add or remove cache clusters to your architecture using an “hot swap” technology that doesn’t require any reboot or re-configuration.</p>
<h3>Installation</h3>
<p>Let’s try to get practical and let’s write some code, otherwise this blog post will get really boring! <img class="wlEmoticon wlEmoticon-winkingsmile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Winking smile" src="http://raffaeu.com/wp-content/uploads/2013/03/45a2716c-a9ba-407d-9403-79a3f01b8a8dwlEmoticon-winkingsmile_2.png"></p>
<p align="left">In order to use <a href="http://www.alachisoft.com/ncache/" target="_blank">NCache</a> you have to go to this web address and download a 60 days trial version: <a title="http://www.alachisoft.com/download.html" href="http://www.alachisoft.com/download.html">http://www.alachisoft.com/download.html</a>. There are three major versions: NCache for .NET (x86 and x64) in two flavors, Enterprise and Professional, NCache for Java (x86 and x64) and NCache express (a free version with a limited amount of features). In this demo I will use the full version for .NET in x64 bit Professional. The setup for the professional edition is about ~30 Mb and it’s pretty quick to install.</p>
<p align="left"><strong>Note:</strong> the only problem you may encounter is with Windows UAC because <a href="http://www.alachisoft.com/ncache/" target="_blank">NCache</a> works better if UAC is disabled. To know more about UAC go here: <a href="http://msdn.microsoft.com/en-us/library/ms229742.aspx" target="_blank">MSDN Windows ACL</a></p>
<p align="left">The Wizard will propose you three different types of installation, like the screenshot below:</p>
<p align="left"><a href="http://raffaeu.com/wp-content/uploads/2013/03/443ec435-0afc-4c9f-b79c-bd16ff5ad5daSNAGHTMLe4f4ea.png"><img title="SNAGHTMLe4f4ea" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="SNAGHTMLe4f4ea" src="http://raffaeu.com/wp-content/uploads/2013/03/dba4d0d5-8710-4aec-bc7a-52c1a7eb5b5aSNAGHTMLe4f4ea_thumb.png" width="292" height="230"></a></p>
<p align="left">In my case I need a developer license because I will run everything from my machine and I need also to have access to NCache API. The cache server installation is used to install a new cluster while the Remote Client installation is used to install the client connection components used by your applications to access the remote cache servers.</p>
<p>As soon as NCache is installed you will get a new icon in your start menu (<em>in my case is a tile because I have Windows 8</em>): </p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/53132a56-fc62-4364-8cc2-9d4e5cbb275fimage_6.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/6dc20f0e-c9a7-4f9b-b560-c53ac337b24aimage_thumb_2.png" width="131" height="132"></a></p>
<p>In the next posts I will show you how to configure your first cache and how to write a WPF application that will work against this cache.</p>
<p>Stay tuned</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=SxUbVs-aY4Q:ya29F937Isg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=SxUbVs-aY4Q:ya29F937Isg:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=SxUbVs-aY4Q:ya29F937Isg:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=SxUbVs-aY4Q:ya29F937Isg:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=SxUbVs-aY4Q:ya29F937Isg:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=SxUbVs-aY4Q:ya29F937Isg:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=SxUbVs-aY4Q:ya29F937Isg:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/SxUbVs-aY4Q" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.raffaeu.com/archive/2012/04/22/ncache-with-net-4.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.raffaeu.com/archive/2012/04/22/ncache-with-net-4.aspx</feedburner:origLink></item>
		<item>
		<title>NCache, simple caching of objects.</title>
		<link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/Zxvo2s-T6gg/ncache-simple-caching-of-objects.aspx</link>
		<comments>http://blog.raffaeu.com/archive/2012/04/22/ncache-simple-caching-of-objects.aspx#comments</comments>
		<pubDate>Sun, 22 Apr 2012 20:16:25 +0000</pubDate>
		<dc:creator>raffaeu</dc:creator>
				<category><![CDATA[NCache]]></category>
		<category><![CDATA[NET World]]></category>

		<guid isPermaLink="false">http://raffaeu.com/?p=39</guid>
		<description><![CDATA[In the previous post I have introduced you to NCache architecture. In this post we will create our first cache (locally) and we will write some C# code to interact with this cache. For the purpose of this series I have created a very simple WPF 4.0 application available from my SkyDrive (see below at <span class="ellipsis">&#8230;</span> <span class="more-link-wrap"><a href="http://blog.raffaeu.com/archive/2012/04/22/ncache-simple-caching-of-objects.aspx" class="more-link"><span>Read More &#8594;</span></a></span>]]></description>
				<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_button">
										<a name="fcbk_share"	href="http://www.facebook.com/raffaeu"	target="blank">
											<img src="http://blog.raffaeu.com/wp-content/plugins/facebook-button-plugin/img/standart-facebook-ico.jpg" alt="Fb-Button" />
										</a>	
									</div><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://blog.raffaeu.com/archive/2012/04/22/ncache-simple-caching-of-objects.aspx" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>In the previous post I have introduced you to <a href="http://www.alachisoft.com/ncache/" target="_blank">NCache</a> architecture. In this post we will create our first cache (<em>locally</em>) and we will write some C# code to interact with this cache.</p>
<p>For the purpose of this series I have created a very simple WPF 4.0 application available from my SkyDrive (see below at the end of this post) that you can download and run locally; but of course you need to install NCache in your development machine. </p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/198fb652-2490-43d7-b611-08597e8dcc61SNAGHTML347a43.png"><img title="SNAGHTML347a43" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="SNAGHTML347a43" src="http://raffaeu.com/wp-content/uploads/2013/03/8a0e9306-c59b-4c93-97e1-7e8b61e0abcbSNAGHTML347a43_thumb.png" width="320" height="221"></a></p>
<p>With this <strong>very simple</strong> WPF application (<em>even if very simple it works with IoC and MVVM</em>) I have a Listbox that will provide a list of items (<em>books titles</em>). The list will be retrieved with the first command from a database, with the second command from the cache and with the third command the cache will be cleared. The cache is populated <strong>automatically</strong> after you retrieve the data from the database.</p>
<p><strong>Note:</strong> I am including the full source code of this series but this is not a series about MVVM and/or WPF so I will not provide that code inside the posts in order to stay focus on the topic, which is <a href="http://www.alachisoft.com/ncache/" target="_blank">NCache</a>.</p>
<h3>Create a new local cache</h3>
<p>First of all we need to create a new cache in NCache and this can be easily accomplished using the UI of NCache. Open you instance of NCache and create a new <strong>local cache</strong>, which is going to be more than enough for our demo.</p>
<p>The following picture shows the steps you need to follow to create a default local cache in your system.</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/f12dad50-ab57-492f-b02d-96dc6779c759image_2.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/ff470b84-40fc-4c7f-80a9-352bfdb4098dimage_thumb.png" width="420" height="300"></a></p>
<ol>
<li>Create a new local cache </li>
<li>Select the current machine as the destination of the local cache </li>
<li>Name the cache </li>
<li>Configure the memory allowed by this cache </li>
<li>Configure the objects lifecycle for the cache </li>
</ol>
<p>At this point, NCache will create the new cache and if you have configure it to startup the cache right away, the NCache IDE will open a new window showing you the NCache health status. From this window you can monitor the amount of objects created by the cache and many other functionalities.</p>
<h3>Retrieve the data from the database</h3>
<p>In this project I have created a <strong>very simple</strong> database structure that contains a table with a bunch or rows, each row represents a <strong>Book</strong> record. The data is retrieved using Entity Framework and this is the code used to populate the Listbox:</p>
<div id="codeSnippetWrapper" style="cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; overflow: auto; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
<div id="codeSnippet" style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">     <pre class="crayon-plain-tag"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> IList&lt;Book&gt; GetListOfBooks()</pre><br />
<!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum2" style="color: #606060">   2:</span> {</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum3" style="color: #606060">   3:</span>     <span style="color: #0000ff">using</span> (var orm = <span style="color: #0000ff">new</span> ORM())</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum4" style="color: #606060">   4:</span>     {</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum5" style="color: #606060">   5:</span>         var results = orm.GetListOfBooks();</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum6" style="color: #606060">   6:</span>         <span style="color: #0000ff">return</span> results</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum7" style="color: #606060">   7:</span>             .Select(result =&gt;</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum8" style="color: #606060">   8:</span>                 <span style="color: #0000ff">new</span> Book {Title = result.Title, ISBN = result.ISBN})</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum9" style="color: #606060">   9:</span>                 .ToList();</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum10" style="color: #606060">  10:</span>     }</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum11" style="color: #606060">  11:</span> }</pre><p><!--CRLF--></div>
</div>
<p>The data is then <strong>DataBound</strong> to a WPF listbox using the MVVM pattern:</p>
<div id="codeSnippetWrapper" style="cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; overflow: auto; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
<div id="codeSnippet" style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">
    <pre class="crayon-plain-tag"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">ListBox</span></pre><br />
<!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum2" style="color: #606060">   2:</span>    <span style="color: #ff0000">Grid</span>.<span style="color: #ff0000">Column</span><span style="color: #0000ff">="0"</span> <span style="color: #ff0000">Grid</span>.<span style="color: #ff0000">Row</span><span style="color: #0000ff">="1"</span> <span style="color: #ff0000">Grid</span>.<span style="color: #ff0000">RowSpan</span><span style="color: #0000ff">="3"</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum3" style="color: #606060">   3:</span>    <span style="color: #ff0000">Style</span><span style="color: #0000ff">="{StaticResource ListboxStyle}"</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum4" style="color: #606060">   4:</span>    <span style="color: #ff0000">ItemsSource</span><span style="color: #0000ff">="{Binding Books,IsAsync=True}"</span><span style="color: #0000ff">&gt;</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum5" style="color: #606060">   5:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">ListBox.ItemTemplate</span><span style="color: #0000ff">&gt;</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum6" style="color: #606060">   6:</span>         <span style="color: #0000ff">&lt;</span><span style="color: #800000">DataTemplate</span><span style="color: #0000ff">&gt;</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum7" style="color: #606060">   7:</span>             <span style="color: #0000ff">&lt;</span><span style="color: #800000">StackPanel</span><span style="color: #0000ff">&gt;</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum8" style="color: #606060">   8:</span>                 <span style="color: #0000ff">&lt;</span><span style="color: #800000">TextBlock</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="{Binding ISBN}"</span> <span style="color: #0000ff">/&gt;</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum9" style="color: #606060">   9:</span>                 <span style="color: #0000ff">&lt;</span><span style="color: #800000">TextBlock</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="{Binding Title}"</span> <span style="color: #0000ff">/&gt;</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum10" style="color: #606060">  10:</span>             <span style="color: #0000ff">&lt;/</span><span style="color: #800000">StackPanel</span><span style="color: #0000ff">&gt;</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum11" style="color: #606060">  11:</span>         <span style="color: #0000ff">&lt;/</span><span style="color: #800000">DataTemplate</span><span style="color: #0000ff">&gt;</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum12" style="color: #606060">  12:</span>     <span style="color: #0000ff">&lt;/</span><span style="color: #800000">ListBox.ItemTemplate</span><span style="color: #0000ff">&gt;</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum13" style="color: #606060">  13:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">ListBox</span><span style="color: #0000ff">&gt;</span></pre><p><!--CRLF--></div>
</div>
<p><font color="#4d4d4d">And the listbox shows the final results:</font></p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/c70369bd-4a13-4d43-8f18-795287e4b0a5SNAGHTML2369f4c.png"><img title="SNAGHTML2369f4c" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="SNAGHTML2369f4c" src="http://raffaeu.com/wp-content/uploads/2013/03/2eb94718-dba0-46a0-a8c2-c63cac0090d2SNAGHTML2369f4c_thumb.png" width="260" height="154"></a></p>
<h3>Retrieve the data from the cache</h3>
<p>The second command of the UI is calling the cache, instead of calling the database, to retrieve the data. But, how does it work? I have drawn below a very simple logical flow that my application follows in order to retrieve the data from the cache, <strong>when available</strong>.</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/eab92dd9-aa4d-475e-bc8e-9548b11282f0image_4.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/2df51b42-9ee1-462e-8f5d-6ad645ac106aimage_thumb_1.png" width="260" height="192"></a></p>
<p>And this is how it works:</p>
<div id="codeSnippetWrapper" style="cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; overflow: auto; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
<div id="codeSnippet" style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">
    <pre class="crayon-plain-tag"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #008000">// initialize the cache</span></pre><br />
<!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum2" style="color: #606060">   2:</span> <span style="color: #0000ff">using</span> (Cache cache = NCache.InitializeCache(<span style="color: #006080">"Cache"</span>))</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum3" style="color: #606060">   3:</span> {</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum4" style="color: #606060">   4:</span>     var list = <span style="color: #0000ff">new</span> List&lt;Book&gt;();</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum5" style="color: #606060">   5:</span>     <span style="color: #008000">// if cache empty, populate the cache</span></pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum6" style="color: #606060">   6:</span>     <span style="color: #0000ff">if</span> (cache.Count == 0)</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum7" style="color: #606060">   7:</span>     {</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum8" style="color: #606060">   8:</span>         IList&lt;Book&gt; books = GetListOfBooks();</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum9" style="color: #606060">   9:</span>         <span style="color: #0000ff">foreach</span> (Book book <span style="color: #0000ff">in</span> books)</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum10" style="color: #606060">  10:</span>         {</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum11" style="color: #606060">  11:</span>             cache.Add(book.ISBN, book);</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum12" style="color: #606060">  12:</span>         }</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum13" style="color: #606060">  13:</span>     }</pre><p><!--CRLF--></p>
<p>    </p><pre class="crayon-plain-tag"><span id="lnum14" style="color: #606060">  14:</span> }</pre><p><!--CRLF--></div>
</div>
<p>Of course this is just a simple implementation to show you how the NCache mechanism works. It is like working with a simple dictionary of objects if you are not implementing NCache on top of another caching framework.</p>
<p>As soon as you add the items to the cache, the NCache management studio will show you the new objects cached in the system:</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/bd88002f-f761-4418-b189-8c2330f74ec6image_6.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/50ecbdac-0805-4623-b289-d7b12cb7e778image_thumb_2.png" width="260" height="181"></a></p>
<h3>Few final notes</h3>
<ul>
<li>First of all you need to orchestrate your application in a way that the cache will be bootstrapped with the application, bootstrapping the cache in a method of the data layer like I did it is absolutely wrong! </li>
<li>The objects contained inside the cache, like any other cache system, <strong>must be serializable</strong> otherwise you will receive a nice runtime exception from NCache. </li>
</ul>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=Zxvo2s-T6gg:jLPwetJoGrc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=Zxvo2s-T6gg:jLPwetJoGrc:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=Zxvo2s-T6gg:jLPwetJoGrc:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=Zxvo2s-T6gg:jLPwetJoGrc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=Zxvo2s-T6gg:jLPwetJoGrc:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=Zxvo2s-T6gg:jLPwetJoGrc:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=Zxvo2s-T6gg:jLPwetJoGrc:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/Zxvo2s-T6gg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.raffaeu.com/archive/2012/04/22/ncache-simple-caching-of-objects.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.raffaeu.com/archive/2012/04/22/ncache-simple-caching-of-objects.aspx</feedburner:origLink></item>
		<item>
		<title>Leaving Bermuda for good!</title>
		<link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/d-rN10ImsKU/leaving-bermuda-for-good.aspx</link>
		<comments>http://blog.raffaeu.com/archive/2012/03/12/leaving-bermuda-for-good.aspx#comments</comments>
		<pubDate>Mon, 12 Mar 2012 21:41:28 +0000</pubDate>
		<dc:creator>raffaeu</dc:creator>
				<category><![CDATA[Bermuda]]></category>
		<category><![CDATA[Private]]></category>

		<guid isPermaLink="false">http://raffaeu.com/?p=28</guid>
		<description><![CDATA[If you search inside an English dictionary the sentence “leaving for good” you will find the following explanation: “leaving for good means leave a place permanently, with no intention to return”. This is exactly what is going to happen to me and my wife, we are leaving Bermuda for good. It has been 4 years <span class="ellipsis">&#8230;</span> <span class="more-link-wrap"><a href="http://blog.raffaeu.com/archive/2012/03/12/leaving-bermuda-for-good.aspx" class="more-link"><span>Read More &#8594;</span></a></span>]]></description>
				<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_button">
										<a name="fcbk_share"	href="http://www.facebook.com/raffaeu"	target="blank">
											<img src="http://blog.raffaeu.com/wp-content/plugins/facebook-button-plugin/img/standart-facebook-ico.jpg" alt="Fb-Button" />
										</a>	
									</div><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://blog.raffaeu.com/archive/2012/03/12/leaving-bermuda-for-good.aspx" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>If you search inside an English dictionary the sentence <em>“leaving for good”</em> you will find the following explanation: <em>“leaving for good means leave a place permanently, with no intention to return”</em>. This is exactly what is going to happen to me and my wife, we are leaving Bermuda for good. It has been 4 years and a half (beginning of 2008) but now it is time to move to a new adventure.</p>
<p>Below I decided to post a brief history of why we moved to Bermuda, what it means live in Bermuda and why we are leaving. </p>
<h3>Why did we move to Bermuda?</h3>
<p>In 2008 I was working in Switzerland for a private bank and I decided with my wife to challenge our life. We were 28 years old and we were sick of living in a country (Italy) where the only way to have a decent career is to <em>“know somebody …”</em>, in the same time we were exhausted by the <em>“frontaliere” (Italian term used to classify an Italian worker that cross the border with another country every day and comes back home in the evening)</em> life we were having by crossing the border of Switzerland every morning at 7 a.m. and coming back home in the evening at 8 p.m.</p>
<p>I found an interesting offer in Bermuda for a public re-insurance company (Nasdaq company) and I applied for the position of CTO (Chief Technology Officer). Within a few weeks our life has completely changed. I got my job and I had to leave Italy in few weeks and my wife was able to reach me only after 6 months, due to the absolutely insane restrictions that Bermuda immigration department applies to work permit holders.</p>
<p>If somebody asks me now, why did I move to Bermuda? I would say because I was looking for something different, something new, something more challenging. Did I find it? Absolutely yes, even if I am still looking for new challenges and new adventures, I absolutely <em>“realized” </em>what I was looking for when I moved to Bermuda. And to answer to the classic question: “Would you do it again?”, I would say: “Yes I would but I would change some things in a different way”. </p>
<h3>What is good about living in Bermuda?</h3>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/c8f5e793-f676-4da2-8dd6-de955ef5a694caribbean-islands-snorkeling_2.jpg"><img title="caribbean-islands-snorkeling" style="BORDER-LEFT-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px; BACKGROUND-IMAGE: none; BORDER-BOTTOM-WIDTH: 0px; FLOAT: left; PADDING-TOP: 0px; PADDING-LEFT: 0px; MARGIN: 6px 18px 6px 20px; DISPLAY: inline; PADDING-RIGHT: 0px; BORDER-TOP-WIDTH: 0px" border="0" alt="caribbean-islands-snorkeling" align="left" width="155" height="121" src="http://raffaeu.com/wp-content/uploads/2013/03/3fefb038-c15e-416e-ab27-77c3d21bd7eecaribbean-islands-snorkeling_thumb.jpg"></a>Well, I can’t say that the life in Bermuda was a bad experience. </p>
<ul>
<li>First of all <u>you save money</u>, and this is probably the best thing you can do when you are married and your plan is to build a family. In Bermuda salaries are absolutely higher than any other place in the world, tax rate is almost 0% (there are taxes but they were all paid by the employer) and the criminality <strong>was</strong> very low. </li>
<li><u>The weather</u>, it is absolutely nice especially from April to November/December you can easily have some spectacular sunny days and going in the office is really hard! <br />
    In the summertime the humidity can reach insane levels and between July and September you live with the A/C on all day <em>(humidity can reach 90%</em>). The average temperature is 20 C in the spring, 25 C in the summer and 15 C in the winter. <br />
    Of course you are in the Caribbean, more or less, so you can expect: Storms, Hurricanes, Heavy rain and more … </li>
<li>Meet <u>people from all over the world</u>. Even if Bermuda is a small island, we got the opportunity to meet people from all over the world. US, Europe, Australia, New Zeeland, you name it … This has been a fantastic experience, I made a lot of friends and even if I won’t see them anymore (<em>maybe</em>) I learned that the sex, the color of the skin and/or the nationality doesn’t really matter; you can find good and bad people coming from the same town. <img class="wlEmoticon wlEmoticon-winkingsmile" style="BORDER-TOP-STYLE: none; BORDER-BOTTOM-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none" alt="Winking smile" src="http://raffaeu.com/wp-content/uploads/2013/03/d5d1a821-1680-411c-9cae-b24c88c99373wlEmoticon-winkingsmile_2.png"> </li>
</ul>
<h3>What is bad about living in Bermuda?</h3>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/abdf7ff1-435e-401d-bf14-aa5b9bf88c95rant_2.jpg"><img title="rant" style="BORDER-LEFT-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px; BACKGROUND-IMAGE: none; BORDER-BOTTOM-WIDTH: 0px; FLOAT: left; PADDING-TOP: 0px; PADDING-LEFT: 0px; MARGIN: 7px 22px 11px 21px; DISPLAY: inline; PADDING-RIGHT: 0px; BORDER-TOP-WIDTH: 0px" border="0" alt="rant" align="left" width="163" height="121" src="http://raffaeu.com/wp-content/uploads/2013/03/5e291464-f542-49f1-a60e-3fada2d82688rant_thumb.jpg"></a>Wow, do you really want me to open this Pandora Box? Seriously?</p>
<ul>
<li><u>Bureaucracy</u> simply too long. Bermuda is a small island, there is an average of 60,000 people and 4/5,000 expats some says 10,000. The amount of public employees, considered the size of the island, is big and every single public service has problems. It takes long to get paperwork&#8217;s and permits and as soon as there is a little issue it will just take more time. They are starting some telematics automation but it is still not enough, especially from a geek point of view. </li>
<li><u>Food quality</u> is something that you have to deal with on a small island in the ocean, especially if you compare with the high price. One Apple may cost you around 1.5$,the water is very expensive, one bottle of sparkly water costs you almost 2.5$ … The meat and the fish are frozen and expensive too, because every single piece of food, or most of them must be imported by sea in the island.  </li>
<li><u>Cultural difference</u>, living on a small Island is different than living in a big a city and local culture and approach to socialization and communication is very different; for example, Bermuda requires a special ceremony composed by “<em>Good morning, how are you?</em>” that needs to be included before <strong>any</strong> request or question to a local. It is not bad but if you don’t know the local culture you may risk to be misunderstood. </li>
<li><u>Infrastructure difference</u>. If you come from a big city you may find fundamental to have high speed internet, cable TV, wireless everywhere and many other services. I had 3G and DSL in Bermuda but it was very expensive and not so high speed as I would like to have. Plus with bad weather conditions you may struggle in receiving good signals. </li>
</ul>
<h3>Why Netherlands?</h3>
<p>We have been in the Netherlands few times and visited the entire country, we love the flat landscape because is simple and well organized, Dutch are  friendly people and even if you speak only English you can easily communicate with everybody. The social system is expensive but works pretty well, so I prefer to pay more taxes but live in a system where everything works properly. The food is not too expensive and the quality is good. Traffic with the car is more complicated but if you ride a bicycle is the perfect place for you!</p>
<p>It is absolutely organized, consider that we found an apartment from internet, we saw it and we liked and when we moved in it was absolutely perfect. Every single paperwork has been done from internet and we received in the new location all the documents we needed. </p>
<p>Below I want to share some nice shot (<em>not mine</em>) taken from <a href="http://www.flickr.com">www.flickr.com</a>. They represent where I was and I where we are now! Enjoy. <img class="wlEmoticon wlEmoticon-smile" style="BORDER-TOP-STYLE: none; BORDER-BOTTOM-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none" alt="Smile" src="http://raffaeu.com/wp-content/uploads/2013/03/492d1695-c4ec-4c53-8d0a-d4bffb683cebwlEmoticon-smile_2.png">   </p>
<p>Bermuda photos</p>
<div id="scid:66721397-FF69-4ca6-AEC4-17E6B3208830:a8c3034a-20bf-4866-8bea-9976134a4c60" class="wlWriterEditableSmartContent" style="FLOAT: none; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; PADDING-LEFT: 0px; MARGIN: 0px; DISPLAY: inline; PADDING-RIGHT: 0px">
<table style="BORDER-TOP-STYLE: none; WIDTH: 410px; BORDER-COLLAPSE: collapse; BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; BORDER-RIGHT-STYLE: none; OUTLINE-STYLE: none; PADDING-LEFT: 0px; MARGIN: 0px; BORDER-LEFT-STYLE: none; PADDING-RIGHT: 0px" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td style="BORDER-TOP-STYLE: none; WIDTH: auto; BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; BORDER-RIGHT-STYLE: none; OUTLINE-STYLE: none; PADDING-LEFT: 0px; MARGIN: 0px; BORDER-LEFT-STYLE: none; PADDING-RIGHT: 0px"><a style="BORDER-TOP-STYLE: none; BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; BORDER-RIGHT-STYLE: none; OUTLINE-STYLE: none; PADDING-LEFT: 0px; MARGIN: 0px; BORDER-LEFT-STYLE: none; PADDING-RIGHT: 0px" target="_blank" href="Photomail&amp;Bpub=SDX.Photos"><img title="View album" style="BORDER-LEFT-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px; VERTICAL-ALIGN: bottom; BACKGROUND: none transparent scroll repeat 0% 0%; BORDER-BOTTOM-WIDTH: 0px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; OUTLINE-STYLE: none; PADDING-LEFT: 0px; MARGIN: 0px; PADDING-RIGHT: 0px; BORDER-TOP-WIDTH: 0px" alt="View album" src="http://raffaeu.com/wp-content/uploads/2013/03/29b36898-d550-41e0-aa2c-af5abc23e0a3Bermuda%20hrd.jpg"></a></p>
<div style="WIDTH: 410px; OVERFLOW: visible; PADDING-BOTTOM: 0px; TEXT-ALIGN: center; PADDING-TOP: 0px; PADDING-LEFT: 0px; MARGIN: 0px; PADDING-RIGHT: 0px">
<div style="WIDTH: 410px; OVERFLOW: visible"><a style="TEXT-DECORATION: none" target="_blank" href="Photomail&amp;Bpub=SDX.Photos"><span style="FONT-SIZE: 26pt; FONT-FAMILY: 'Segoe UI', helvetica, arial, sans-serif; WIDTH: 410px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; PADDING-LEFT: 0px; LINE-HEIGHT: 1.26em; PADDING-RIGHT: 0px" defaulttext="Enter album name here">Bermuda</span></a></div>
<div style="FONT-SIZE: 8pt; FONT-FAMILY: 'Segoe UI', helvetica, arial, sans-serif; PADDING-BOTTOM: 0px; TEXT-ALIGN: center; PADDING-TOP: 9px; PADDING-LEFT: 0px; MARGIN: 0px; PADDING-RIGHT: 0px">
<table style="BORDER-TOP-STYLE: none; WIDTH: auto; BORDER-COLLAPSE: collapse; BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; TEXT-ALIGN: center; PADDING-TOP: 0px; BORDER-RIGHT-STYLE: none; OUTLINE-STYLE: none; PADDING-LEFT: 0px; MARGIN-LEFT: auto; BORDER-LEFT-STYLE: none; PADDING-RIGHT: 0px; MARGIN-RIGHT: auto" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td style="BORDER-TOP-STYLE: none; VERTICAL-ALIGN: top; BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 6px; PADDING-TOP: 6px; BORDER-RIGHT-STYLE: none; OUTLINE-STYLE: none; PADDING-LEFT: 0px; MARGIN: 0px; BORDER-LEFT-STYLE: none; PADDING-RIGHT: 12px"><a style="BORDER-TOP-STYLE: none; FONT-SIZE: 8pt; TEXT-DECORATION: none; FONT-FAMILY: 'Segoe UI', helvetica, arial, sans-serif; BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; BORDER-RIGHT-STYLE: none; OUTLINE-STYLE: none; PADDING-LEFT: 0px; MARGIN: 0px; BORDER-LEFT-STYLE: none; PADDING-RIGHT: 0px" target="_blank" border="0" href="https://skydrive.live.com/redir.aspx?cid=ada7c80f0c2f057b&amp;page=play&amp;resid=ADA7C80F0C2F057B!329&amp;type=5&amp;authkey=!AGnKkw_CO4KXRsw&amp;Bsrc=Photomail&amp;Bpub=SDX.Photos">VIEW SLIDE SHOW</a></td>
<td style="BORDER-TOP-STYLE: none; VERTICAL-ALIGN: top; BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 6px; PADDING-TOP: 6px; BORDER-RIGHT-STYLE: none; OUTLINE-STYLE: none; PADDING-LEFT: 0px; MARGIN: 0px; BORDER-LEFT-STYLE: none; PADDING-RIGHT: 0px"><a style="BORDER-TOP-STYLE: none; FONT-SIZE: 8pt; TEXT-DECORATION: none; FONT-FAMILY: 'Segoe UI', helvetica, arial, sans-serif; BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; BORDER-RIGHT-STYLE: none; OUTLINE-STYLE: none; PADDING-LEFT: 0px; MARGIN: 0px; BORDER-LEFT-STYLE: none; PADDING-RIGHT: 0px" target="_blank" border="0" href="https://skydrive.live.com/redir.aspx?cid=ada7c80f0c2f057b&amp;page=downloadphotos&amp;resid=ADA7C80F0C2F057B!329&amp;type=5&amp;Bsrc=Photomail&amp;Bpub=SDX.Photos&amp;authkey=!AGnKkw_CO4KXRsw">DOWNLOAD ALL</a></td>
</tr>
</tbody>
</table></div>
</p></div>
</td>
</tr>
</tbody>
</table>
</div>
<p>Den Haag photos</p>
<div id="scid:66721397-FF69-4ca6-AEC4-17E6B3208830:f806c4dc-0190-46a0-8c2a-1827d6e1f627" class="wlWriterEditableSmartContent" style="FLOAT: none; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; PADDING-LEFT: 0px; MARGIN: 0px; DISPLAY: inline; PADDING-RIGHT: 0px">
<table style="BORDER-TOP-STYLE: none; WIDTH: 410px; BORDER-COLLAPSE: collapse; BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; BORDER-RIGHT-STYLE: none; OUTLINE-STYLE: none; PADDING-LEFT: 0px; MARGIN: 0px; BORDER-LEFT-STYLE: none; PADDING-RIGHT: 0px" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td style="BORDER-TOP-STYLE: none; WIDTH: auto; BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; BORDER-RIGHT-STYLE: none; OUTLINE-STYLE: none; PADDING-LEFT: 0px; MARGIN: 0px; BORDER-LEFT-STYLE: none; PADDING-RIGHT: 0px"><a style="BORDER-TOP-STYLE: none; BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; BORDER-RIGHT-STYLE: none; OUTLINE-STYLE: none; PADDING-LEFT: 0px; MARGIN: 0px; BORDER-LEFT-STYLE: none; PADDING-RIGHT: 0px" target="_blank" href="https://skydrive.live.com/redir.aspx?cid=ada7c80f0c2f057b&amp;page=play&amp;resid=ADA7C80F0C2F057B!333&amp;type=5&amp;authkey=!AKVkGdn_c73mAuk&amp;Bsrc=Photomail&amp;Bpub=SDX.Photos"><img title="View album" style="BORDER-LEFT-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px; VERTICAL-ALIGN: bottom; BACKGROUND: none transparent scroll repeat 0% 0%; BORDER-BOTTOM-WIDTH: 0px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; OUTLINE-STYLE: none; PADDING-LEFT: 0px; MARGIN: 0px; PADDING-RIGHT: 0px; BORDER-TOP-WIDTH: 0px" alt="View album" src="http://raffaeu.com/wp-content/uploads/2013/03/9886c372-7427-4394-943e-b13128c68ae6Den%20Haag.jpg"></a></p>
<div style="WIDTH: 410px; OVERFLOW: visible; PADDING-BOTTOM: 0px; TEXT-ALIGN: center; PADDING-TOP: 0px; PADDING-LEFT: 0px; MARGIN: 0px; PADDING-RIGHT: 0px">
<div style="WIDTH: 410px; OVERFLOW: visible"><a style="TEXT-DECORATION: none" target="_blank" href="Photomail&amp;Bpub=SDX.Photos"><span style="FONT-SIZE: 26pt; FONT-FAMILY: 'Segoe UI', helvetica, arial, sans-serif; WIDTH: 410px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; PADDING-LEFT: 0px; LINE-HEIGHT: 1.26em; PADDING-RIGHT: 0px" defaulttext="Enter album name here">Den Haag</span></a></div>
<div style="FONT-SIZE: 8pt; FONT-FAMILY: 'Segoe UI', helvetica, arial, sans-serif; PADDING-BOTTOM: 0px; TEXT-ALIGN: center; PADDING-TOP: 9px; PADDING-LEFT: 0px; MARGIN: 0px; PADDING-RIGHT: 0px">
<table style="BORDER-TOP-STYLE: none; WIDTH: auto; BORDER-COLLAPSE: collapse; BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; TEXT-ALIGN: center; PADDING-TOP: 0px; BORDER-RIGHT-STYLE: none; OUTLINE-STYLE: none; PADDING-LEFT: 0px; MARGIN-LEFT: auto; BORDER-LEFT-STYLE: none; PADDING-RIGHT: 0px; MARGIN-RIGHT: auto" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td style="BORDER-TOP-STYLE: none; VERTICAL-ALIGN: top; BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 6px; PADDING-TOP: 6px; BORDER-RIGHT-STYLE: none; OUTLINE-STYLE: none; PADDING-LEFT: 0px; MARGIN: 0px; BORDER-LEFT-STYLE: none; PADDING-RIGHT: 12px"><a style="BORDER-TOP-STYLE: none; FONT-SIZE: 8pt; TEXT-DECORATION: none; FONT-FAMILY: 'Segoe UI', helvetica, arial, sans-serif; BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; BORDER-RIGHT-STYLE: none; OUTLINE-STYLE: none; PADDING-LEFT: 0px; MARGIN: 0px; BORDER-LEFT-STYLE: none; PADDING-RIGHT: 0px" target="_blank" border="0" href="https://skydrive.live.com/redir.aspx?cid=ada7c80f0c2f057b&amp;page=play&amp;resid=ADA7C80F0C2F057B!333&amp;type=5&amp;authkey=!AKVkGdn_c73mAuk&amp;Bsrc=Photomail&amp;Bpub=SDX.Photos">VIEW SLIDE SHOW</a></td>
<td style="BORDER-TOP-STYLE: none; VERTICAL-ALIGN: top; BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 6px; PADDING-TOP: 6px; BORDER-RIGHT-STYLE: none; OUTLINE-STYLE: none; PADDING-LEFT: 0px; MARGIN: 0px; BORDER-LEFT-STYLE: none; PADDING-RIGHT: 0px"><a style="BORDER-TOP-STYLE: none; FONT-SIZE: 8pt; TEXT-DECORATION: none; FONT-FAMILY: 'Segoe UI', helvetica, arial, sans-serif; BORDER-BOTTOM-STYLE: none; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; BORDER-RIGHT-STYLE: none; OUTLINE-STYLE: none; PADDING-LEFT: 0px; MARGIN: 0px; BORDER-LEFT-STYLE: none; PADDING-RIGHT: 0px" target="_blank" border="0" href="https://skydrive.live.com/redir.aspx?cid=ada7c80f0c2f057b&amp;page=downloadphotos&amp;resid=ADA7C80F0C2F057B!333&amp;type=5&amp;Bsrc=Photomail&amp;Bpub=SDX.Photos&amp;authkey=!AKVkGdn_c73mAuk">DOWNLOAD ALL</a></td>
</tr>
</tbody>
</table></div>
</p></div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=d-rN10ImsKU:QaqyNjO5Y1Q:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=d-rN10ImsKU:QaqyNjO5Y1Q:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=d-rN10ImsKU:QaqyNjO5Y1Q:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=d-rN10ImsKU:QaqyNjO5Y1Q:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=d-rN10ImsKU:QaqyNjO5Y1Q:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=d-rN10ImsKU:QaqyNjO5Y1Q:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=d-rN10ImsKU:QaqyNjO5Y1Q:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/d-rN10ImsKU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.raffaeu.com/archive/2012/03/12/leaving-bermuda-for-good.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.raffaeu.com/archive/2012/03/12/leaving-bermuda-for-good.aspx</feedburner:origLink></item>
		<item>
		<title>NHibernate cache system. Part 3</title>
		<link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/gRtJXykUfNQ/nhibernate-cache-system-part-3.aspx</link>
		<comments>http://blog.raffaeu.com/archive/2011/12/29/nhibernate-cache-system-part-3.aspx#comments</comments>
		<pubDate>Thu, 29 Dec 2011 20:24:43 +0000</pubDate>
		<dc:creator>raffaeu</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://raffaeu.com/?p=74</guid>
		<description><![CDATA[In this series of articles we saw how the cache system is implemented in NHibernate and what can we do in order to use it. We also saw that we can choose a cache provider but we didn’t have a look yet at what providers we can use. I personally have my own opinion about <span class="ellipsis">&#8230;</span> <span class="more-link-wrap"><a href="http://blog.raffaeu.com/archive/2011/12/29/nhibernate-cache-system-part-3.aspx" class="more-link"><span>Read More &#8594;</span></a></span>]]></description>
				<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_button">
										<a name="fcbk_share"	href="http://www.facebook.com/raffaeu"	target="blank">
											<img src="http://blog.raffaeu.com/wp-content/plugins/facebook-button-plugin/img/standart-facebook-ico.jpg" alt="Fb-Button" />
										</a>	
									</div><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://blog.raffaeu.com/archive/2011/12/29/nhibernate-cache-system-part-3.aspx" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>In this <a href="http://blog.raffaeu.com/archive/2011/12/31/nhibernate-cache-system-part-1.aspx" target="_blank">series</a> of <a href="http://blog.raffaeu.com/archive/2011/12/31/nhibernate-cache-system-part-2.aspx" target="_blank">articles</a> we saw how the cache system is implemented in NHibernate and what can we do in order to use it. We also saw that we can choose a cache provider but we didn’t have a look yet at what providers we can use.</p>
<p>I personally have my own opinion about the 2nd level cache providers available for NHibernate 3.2 and I am more than happy if you would like to share with me your experience about it.</p>
<p>Below is a list of <strong>the major and the most famous </strong>2nd level cache providers I know:</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/c5eb0517-92b7-4c7f-b006-12431131291dimage_2.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/393cba97-be0a-42ac-8e52-74b4e762a248image_thumb.png" width="876" height="257"></a></p>
<p>I would personally suggest you to answer the following questions in order to understand what is the cache provider you need for your project:</p>
<ul>
<li>Size of you project (small, standard, enterprise) </li>
<li>Cache technology you have already in place </li>
<li>Quality attributes required by your solution (scalability, security, …) </li>
</ul>
<h3>SysCache</h3>
<div>SysCache and the most recent SysCache2 is a cache provider built on top of the old ASP.NET cache system. It is available from ASP.NET cache provider (<strong>NHibernate.Cache.SysCache.dll</strong>)</div>
<p>It is an abstraction over ASP.NET cache so it can’t be used in a non-web application. It works but Microsoft suggest to do not use it for non-web applications.</p>
<p>The cache space is not configurable so it is the same for different session factories … really dangerous on a web application that requires isolation between the various users (<a href="http://ayende.com/blog/1708/nhibernate-caching-the-secong-level-cache-space-is-shared">http://</a><a href="http://ayende.com/blog/1708/nhibernate-caching-the-secong-level-cache-space-is-shared">ayende.com/blog/1708/nhibernate-caching-the-secong-level-cache-space-is-shared</a>)</p>
<p><strong>Useful for</strong>: small in house projects, better for web projects hosted in IIS</p>
<h3>NCache</h3>
<p>NCache is a distributed in-memory Object cache and a distributed ASP.NET Session State manager product.</p>
<p>It is able to synchronizes cache across multiple servers so it is designed also for the enterprise.</p>
<p>It provides dynamic clustering &amp; cache configuration for 100% uptime for a real scalable architecture.</p>
<p>Cache reliability through data replication across servers</p>
<p>InProc/OutProc cache for multiple processes on same machine</p>
<p>API identical to ASP.NET Cache</p>
<p>It is available for download and trial here <a href="http://www.alachisoft.com/ncache/edition-comparison.html">http://</a><a href="http://www.alachisoft.com/ncache/edition-comparison.html">www.alachisoft.com/ncache/edition-comparison.html</a>, it is a third party provider and <strong>it is not free</strong>.</p>
<p><strong>Useful for:</strong> medium to big applications that are designed to be scalable</p>
<h3>MemCache</h3>
<p>MemCache is a famous Linux cache system designed exclusively for the enterprise. It is a complex enterprise cache system based on Linux platform that provide a cache mechanism also for NHibernate.    <br />It is pretty easy to be scaled on a big server farm because it is designed to do so     <br />It does not require licensing cost because it’s an OSS and it is a well known system with a big community.</p>
<p>The following picture represents the core logic of MemCache:</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/d13fc473-b318-45e9-bd04-10126f2dc26aimage_4.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/6cf9e1d4-2ae6-4f92-a36f-002bb590e58dimage_thumb_1.png" width="515" height="251"></a></p>
<p>The only downside is that it requires a medium knowledge of Linux OS in order to be able to install and configured it.</p>
<p><strong>Useful for:</strong> enterprise applications that are designed to be scalable</p>
<h3>Velocity, a.k.a. AppFabric</h3>
<p>Velocity has been now integrated in AppFabric and it is the cache system implemented by Microsoft for the enterprise. It requires AppFabric and IIS and it can be used locally or with Azure (does it make sense to cache in the cloud?? <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-flirtmale" alt="Flirt male" src="http://raffaeu.com/wp-content/uploads/2013/03/33acf3f0-fcc1-4c4c-98a8-869dfde42629wlEmoticon-flirtmale_2.png">).</p>
<ul>
<li>AppFabric Caching, provides local caching, bulk updates, callbacks for updates, etc&#8230; so this is why it&#8217;s exciting over something like MemCache which doesn&#8217;t provide these features Out of the Box. </li>
<li>For enterprise architectures, really scalable, Microsoft product (there may be a license requirement) </li>
</ul>
<p><strong>Useful for:</strong> enterprise applications that are designed to be scalable</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=gRtJXykUfNQ:I4DWHZgMmgg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=gRtJXykUfNQ:I4DWHZgMmgg:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=gRtJXykUfNQ:I4DWHZgMmgg:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=gRtJXykUfNQ:I4DWHZgMmgg:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=gRtJXykUfNQ:I4DWHZgMmgg:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=gRtJXykUfNQ:I4DWHZgMmgg:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=gRtJXykUfNQ:I4DWHZgMmgg:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/gRtJXykUfNQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.raffaeu.com/archive/2011/12/29/nhibernate-cache-system-part-3.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.raffaeu.com/archive/2011/12/29/nhibernate-cache-system-part-3.aspx</feedburner:origLink></item>
		<item>
		<title>NHibernate cache system. Part 2</title>
		<link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/W5wc09xo9lI/nhibernate-cache-system-part-2.aspx</link>
		<comments>http://blog.raffaeu.com/archive/2011/12/29/nhibernate-cache-system-part-2.aspx#comments</comments>
		<pubDate>Thu, 29 Dec 2011 20:23:27 +0000</pubDate>
		<dc:creator>raffaeu</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://raffaeu.com/?p=68</guid>
		<description><![CDATA[In the previous post we saw how the cache system is structured in NHibernate and how it works. We saw that we have different methods to play with the cache (Evict, Clear, Flush …) and they are all associated with the ISession object because the cache of level 1 is associated with the lifecycle of <span class="ellipsis">&#8230;</span> <span class="more-link-wrap"><a href="http://blog.raffaeu.com/archive/2011/12/29/nhibernate-cache-system-part-2.aspx" class="more-link"><span>Read More &#8594;</span></a></span>]]></description>
				<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_button">
										<a name="fcbk_share"	href="http://www.facebook.com/raffaeu"	target="blank">
											<img src="http://blog.raffaeu.com/wp-content/plugins/facebook-button-plugin/img/standart-facebook-ico.jpg" alt="Fb-Button" />
										</a>	
									</div><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://blog.raffaeu.com/archive/2011/12/29/nhibernate-cache-system-part-2.aspx" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>In the <a href="http://blog.raffaeu.com/archive/2011/12/31/nhibernate-cache-system-part-1.aspx" target="_blank">previous post</a> we saw how the cache system is structured in NHibernate and how it works. We saw that we have different methods to play with the cache (Evict, Clear, Flush …) and they are all associated with the <em>ISession</em> object because the cache of level 1 is associated with the lifecycle of an <em>ISession</em> object.</p>
<p>In this second article we will see how the second level cache works and how it is associated with the <em>ISessionFactory</em> object that is in charge of controlling this cache mechanism.</p>
<h3>Second Level cache architecture</h3>
<p>How does the second level cache work?</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/c7541729-c217-48c6-9521-2f847c12224cimage_2.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/5af1d94f-76f4-423e-be21-61645d96c6f2image_thumb.png" width="520" height="325"></a></p>
<p>First of all, when an entity is cached in the second level cache, the entity is disassembled into a collection of keys/values pair, like a dictionary and persisted in the cache repository. This mechanism is accomplished because most of the second level cache providers are able to persist serialized dictionary collections and because in the same time NHibernate does not force you to make serializable your entities (something that IMHO, should never be done!!).</p>
<p>A second mechanism happens when we cache the result of a query (Linq, HQL, ICriteria) because these results can’t be cached using the first level cache (see previous blog post). After we cache a query result, NHibernate will cache <strong>only</strong> the unique identifiers of the entities involved in the result of the query.</p>
<p>Third, NHibernate has an internal mechanism that allows him to know and keep track of a timestamp value used to write tables or to work with sessions. How does it work? Well the mechanism is pretty clear, it keeps track of when the last table was written too. A series of mechanism will update this timestamp information and you can find a better explanation of Ayende’s blog: <a title="http://ayende.com/blog/3112/nhibernate-and-the-second-level-cache-tips" href="http://ayende.com/blog/3112/nhibernate-and-the-second-level-cache-tips">http://ayende.com/blog/3112/nhibernate-and-the-second-level-cache-tips</a>.</p>
<h3>Configuration of the second level cache</h3>
<p>By default the second level cache is disabled. If you need to use the second level cache you have to let NHibernate know about that. The hibernate.cfg file has a dedicated section of parameters that should be used to enable the second level cache:</p>
<div class="csharpcode">   <pre class="crayon-plain-tag"><span class="kwrd">&lt;</span><span class="html">property</span> <span class="attr">name</span><span class="kwrd">="cache.provider_class"</span><span class="kwrd">&gt;</span></pre></p>
<p>  </p><pre class="crayon-plain-tag">NHibernate.Cache.HashtableCacheProvider</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">&lt;/</span><span class="html">property</span><span class="kwrd">&gt;</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><font color="#9bbb59"><span class="kwrd">&lt;!</span><span class="html">--</span> <span class="attr">You</span> <span class="attr">have</span> <span class="attr">to</span> <span class="attr">explicitly</span> <span class="attr">enable</span> <span class="attr">the</span> <span class="attr">second</span> <span class="attr">level</span> <span class="attr">cache</span> <span class="attr">-</span><span class="kwrd">&gt;</span></font></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">&lt;</span><span class="html">property</span> <span class="attr">name</span><span class="kwrd">="cache.use_second_level_cache"</span><span class="kwrd">&gt;</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag">true</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">&lt;/</span><span class="html">property</span><span class="kwrd">&gt;</span></pre><p>
</p></div>
<style type="text/css"><![CDATA[</p>
<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; }]]&gt;</style>
<p>First of all we specify the cache provider we are using, in this case I am using the standard hashtable provider, but I will show you in the next article what are the real providers you should use. Second we say that the cache should be enabled; this part is really important because if you do not specify that the cache is enable, it simply won’t work … <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-confusedsmile" alt="Confused smile" src="http://raffaeu.com/wp-content/uploads/2013/03/65b8fdde-07ca-41a3-89ce-af1e8f4a143ewlEmoticon-confusedsmile_2.png"></p>
<p>Then you may provide to the cache a default expiration in seconds:</p>
<div class="csharpcode">
  <pre class="crayon-plain-tag"><span class="rem">&lt;!-- cache will expire in 2 minutes --&gt;</span></pre></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">&lt;</span><span class="html">property</span> <span class="attr">name</span><span class="kwrd">="cache.default_expiration"</span><span class="kwrd">&gt;</span>120<span class="kwrd">&lt;/</span><span class="html">property</span><span class="kwrd">&gt;</span></pre><p>
</p></div>
<style type="text/css"><![CDATA[</p>
<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; }]]&gt;</style>
<p><font color="#4d4d4d">If you want to add additional configuration properties, they will be cache provider specific!</font></p>
<h3>Cache by mapping</h3>
<p>One of the possible configuration is to enable the cache at the entity level. This means that we are marking our entity as <em>“cachable”</em>.</p>
<div class="csharpcode">
  <pre class="crayon-plain-tag"><span class="kwrd">&lt;</span><span class="html">class</span></pre></p>
<p>  </p><pre class="crayon-plain-tag"><span class="attr">name</span><span class="kwrd">="CachableProduct“</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag">table="[<span class="attr">CachableProduct</span>]“</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="attr">dynamic-insert</span><span class="kwrd">="true“</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag">dynamic-update="<span class="attr">true</span>"<span class="kwrd">&gt;</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">&lt;</span><span class="html">cache</span> <span class="attr">usage</span><span class="kwrd">="read-write"</span><span class="kwrd">/&gt;</span></pre><p>
</p></div>
<style type="text/css"><![CDATA[</p>
<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; }]]&gt;</style>
<p>In order to do that we have to introduce a new tag, the <strong>&lt;cache&gt;</strong> tag. In this tag we can specify different type of &#8220;<em>”usage”:</em></p>
<ul>
<li><strong>Read-write</strong>
<p>It should be used if you plan also to update the data (no with serializable transaction) </li>
<li><strong>Read-only</strong>
<p>Simplest and best performing, for read only access </li>
<li><strong>Nonstrict-read-write</strong>
<p>If you need to occasionally update the data. You must commit the transaction </li>
<li><strong>Transactional</strong>
<p>not documented/implemented yet because no one cache provider allows transactional cache. It is implemented in the Java version because J2EE allow transactional second level cache </li>
</ul>
<p>Now, if we write a simple test that will create some entities and will try to retrieve them using two different <em>ISession</em> generated by the same <em>ISessionFactory</em> we will get the following behavior:</p>
<div class="csharpcode">
  <pre class="crayon-plain-tag"><span class="kwrd">using</span> (var session = factory.OpenSession())</pre></p>
<p>  </p><pre class="crayon-plain-tag">{</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="rem">// create the products</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">using</span> (var tx = session.BeginTransaction(IsolationLevel.ReadCommitted))</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">{</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">Console.WriteLine(<span class="str">"*** FIRST SESSION ***"</span>);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">var expectedProduct1 = session.Get&lt;CachableProduct&gt;(productId);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">Assert.That(expectedProduct1, Is.Not.Null);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">tx.Commit();</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="rem">// retrieve the number of hits we did to the 2nd level cache</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag">Console.WriteLine(<span class="str">"Second level hits {0}"</span>, <br>           factory.Statistics.SecondLevelCacheHitCount);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">}</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">}</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">using</span> (var session = factory.OpenSession())</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">{</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">using</span> (var tx = session.BeginTransaction(IsolationLevel.ReadCommitted))</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">{</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">Console.WriteLine(<span class="str">"*** SECOND SESSION ***"</span>);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">var expectedProduct1 = session.Get&lt;CachableProduct&gt;(productId);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">Assert.That(expectedProduct1, Is.Not.Null);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">tx.Commit();</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="rem">// retrieve the number of hits we did to the 2nd level cache</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag">Console.WriteLine(<span class="str">"Second level hits {0}"</span>, <br>           factory.Statistics.SecondLevelCacheHitCount);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">}</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">}</pre><p>
</p></div>
<p>
<style type="text/css"><![CDATA[</p>
<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; }]]&gt;</style>
<p>The result will be the following:</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/e9f2aea8-57a1-4d43-9eb2-19e6f576b6c3image_4.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/e725d3f4-a5af-42ff-882d-0f46dd98bebeimage_thumb_1.png" width="544" height="256"></a></p>
<p>As you can see the second session will access the 2nd level cache using a transaction and will not use the database at all. This has been accomplished just by mapping the entity with the <strong>&lt;cache&gt;</strong> tag and by using the GET&lt;T&gt; method.</p>
<p>Let’s make everything a little bit more complex. Let’s assume for a second that our object is an aggregate root and it is more complex than the previous one. If we want to cache also a collection of child or a parent reference we will need to change our mapping in the following way:</p>
<div class="csharpcode">
  <pre class="crayon-plain-tag"><span class="rem">&lt;!-- inside the product mapping file --&gt;</span></pre></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">&lt;</span><span class="html">bag</span> <span class="attr">name</span><span class="kwrd">="Attributes"</span> <span class="attr">cascade</span><span class="kwrd">="all"</span> <span class="attr">inverse</span> <span class="kwrd">="true"</span><span class="kwrd">&gt;</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">&lt;</span><span class="html">cache</span> <span class="attr">usage</span><span class="kwrd">="read-write"</span><span class="kwrd">/&gt;</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">&lt;</span><span class="html">key</span> <span class="attr">column</span><span class="kwrd">="ProductId"</span> <span class="kwrd">/&gt;</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">&lt;</span><span class="html">one-to-many</span> <span class="attr">class</span><span class="kwrd">="CacheAttribute"</span><span class="kwrd">/&gt;</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">&lt;/</span><span class="html">bag</span><span class="kwrd">&gt;</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="rem">&lt;!-- inside theCacheAttribute file --&gt;</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">&lt;</span><span class="html">class</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="attr">name</span><span class="kwrd">="CacheAttribute"</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="attr">table</span><span class="kwrd">="[CacheAttribute]"</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="attr">dynamic-insert</span><span class="kwrd">="true"</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="attr">dynamic-update</span><span class="kwrd">="true"</span><span class="kwrd">&gt;</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">&lt;</span><span class="html">cache</span> <span class="attr">usage</span><span class="kwrd">="read-write"</span><span class="kwrd">/&gt;</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="rem">&lt;!-- omit --&gt;</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">&lt;</span><span class="html">many-to-one</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="attr">class</span><span class="kwrd">="CachableProduct"</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="attr">name</span><span class="kwrd">="Product"</span> <span class="attr">cascade</span><span class="kwrd">="all"</span><span class="kwrd">&gt;</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">&lt;</span><span class="html">column</span> <span class="attr">name</span><span class="kwrd">="ProductId"</span> <span class="kwrd">/&gt;</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">&lt;/</span><span class="html">many-to-one</span><span class="kwrd">&gt;</span></pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">&lt;/</span><span class="html">class</span><span class="kwrd">&gt;</span></pre><p>
</p></div>
<style type="text/css"><![CDATA[</p>
<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; }]]&gt;</style>
<p>Now we can execute the following test (I am omitting some parts for saving space, I hope you don’t mind …)</p>
<div class="csharpcode">
  <pre class="crayon-plain-tag"><span class="kwrd">using</span> (var session = factory.OpenSession())</pre></p>
<p>  </p><pre class="crayon-plain-tag">{</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">using</span> (var tx = session.BeginTransaction(IsolationLevel.ReadCommitted))</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">{</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">Console.WriteLine(<span class="str">"*** FIRST SESSION ***"</span>);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">var expectedProduct1 = session.Get&lt;CachableProduct&gt;(productId);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">Assert.That(expectedProduct1, Is.Not.Null);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">Assert.That(expectedProduct1.Attributes, Has.Count.GreaterThan(0));</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">tx.Commit();</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">Console.WriteLine(<span class="str">"Second level hits {0}"</span>,</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">factory.Statistics.SecondLevelCacheHitCount);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">}</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"> </pre><p></p>
<p>  </p><pre class="crayon-plain-tag">}</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">using</span> (var session = factory.OpenSession())</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">{</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">using</span> (var tx = session.BeginTransaction(IsolationLevel.ReadCommitted))</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">{</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">Console.WriteLine(<span class="str">"*** SECOND SESSION ***"</span>);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">var expectedProduct1 = session.Get&lt;CachableProduct&gt;(productId);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">Assert.That(expectedProduct1, Is.Not.Null);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">Assert.That(expectedProduct1.Attributes, Has.Count.GreaterThan(0));</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">tx.Commit();</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">Console.WriteLine(<span class="str">"Second level hits {0}"</span>,</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">factory.Statistics.SecondLevelCacheHitCount);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">}</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">}</pre><p>
</p></div>
<style type="text/css"><![CDATA[</p>
<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; }]]&gt;</style>
<p>And this is the result from the profiled SQL:</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/d47c4d1b-ccdd-4361-8d22-5bb6c27fd48bimage_6.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/31644fe9-2066-4e15-b6b2-bf7baf31aab7image_thumb_2.png" width="536" height="449"></a></p>
<p>In this case the second <em>ISession</em> is calling the cache 4 times in order to resolve all the objects (2 products x 2 categories).</p>
<h3>Cache a query result</h3>
<p>Another way to cache our result is by creating a <em>cachable query</em> that is slightly different than creating a cachable object.</p>
<div style="border-bottom: #666666 1px solid; border-left: #666666 1px solid; padding-bottom: 3px; padding-left: 3px; padding-right: 3px; background: #efefef; border-top: #666666 1px solid; border-right: #666666 1px solid; padding-top: 3px"><strong>Important note: </strong></p>
<p><em>In order to cache a query we need to set the query as “cachable” and then set the corresponding entity as “cachable” too. Otherwise NHB will cache the ID of the entity but then it will always fetch the entity and cache only the query result.</em></p>
</div>
<p>To write a cachable query we need to implement an <em>IQuery</em> object in the following way:</p>
<div class="csharpcode">
  <pre class="crayon-plain-tag"><span class="kwrd">using</span> (var session = factory.OpenSession()) {</pre></p>
<p>  </p><pre class="crayon-plain-tag">     <span class="kwrd">using</span> (var tx = session.BeginTransaction(IsolationLevel.ReadCommitted))</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">     {</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">        var result = session</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">             .CreateQuery(<span class="str">"from CachableProduct p where p.Name = :name"</span>)</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">             .SetString(<span class="str">"name"</span>, <span class="str">"PC"</span>)</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">             .SetCacheable(<span class="kwrd">true</span>)</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">             .List&lt;CachableProduct&gt;();</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">        tx.Commit();</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">     }</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">}</pre><p>
</p></div>
<style type="text/css"><![CDATA[
.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; }]]&gt;</style>
<p>Now, let’s try to write a unit test for this:</p>
<div class="csharpcode">
  <pre class="crayon-plain-tag"><span class="kwrd">using</span> (var session = factory.OpenSession())</pre></p>
<p>  </p><pre class="crayon-plain-tag">{</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">using</span> (var tx = session.BeginTransaction(IsolationLevel.ReadCommitted))</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">{</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">Console.WriteLine(<span class="str">"*** FIRST SESSION ***"</span>);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">var result = session</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">.CreateQuery(<span class="str">"from CachableProduct p where p.Name = :name"</span>)</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">.SetString(<span class="str">"name"</span>, <span class="str">"PC"</span>)</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">.SetCacheable(<span class="kwrd">true</span>)</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">.List&lt;CachableProduct&gt;();</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">Console.WriteLine(<span class="str">"Cached queries {0}"</span>,</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">factory.Statistics.QueryCacheHitCount);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">Console.WriteLine(<span class="str">"Second level hits {0}"</span>,</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">factory.Statistics.SecondLevelCacheHitCount);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">tx.Commit();</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">}</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">}</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">using</span> (var session = factory.OpenSession())</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">{</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="kwrd">using</span> (var tx = session.BeginTransaction(IsolationLevel.ReadCommitted))</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">{</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">Console.WriteLine(<span class="str">"*** SECOND SESSION ***"</span>);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">var result = session</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">.CreateQuery(<span class="str">"from CachableProduct p where p.Name = :name"</span>)</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">.SetString(<span class="str">"name"</span>, <span class="str">"PC"</span>)</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">.SetCacheable(<span class="kwrd">true</span>)</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">.List&lt;CachableProduct&gt;();</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">Console.WriteLine(<span class="str">"Cached queries {0}"</span>,</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">factory.Statistics.QueryCacheHitCount);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">Console.WriteLine(<span class="str">"Second level hits {0}"</span>,</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">factory.Statistics.SecondLevelCacheHitCount);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">tx.Commit();</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">}</pre><p></p>
<p>  </p><pre class="crayon-plain-tag">}</pre><p>
</p></div>
<style type="text/css"><![CDATA[
.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; }]]&gt;</style>
<p>And this is the expected result:</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/f4b21697-4e04-47bb-843c-57f02c801e6bimage_8.png"><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="image" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/89bfa0cb-ad90-47a1-a2a3-e9da8ed726c8image_thumb_3.png" width="409" height="286"></a></p>
<p>In this case the cache is telling us that the second session has <strong>1 query result cached</strong> and that we called it once.</p>
<h3>Final advice</h3>
<p>As you saw using the 1st and 2nd level cache is a pretty straightforward process but it requires time and understanding of NHibernate cache mechanism. Below are some final advice that you should keep in consideration when working with the 2nd level cache:</p>
<ul>
<li>2nd Level Cache is never aware of external database changes!</li>
<li>Default cache system is hashtable, you must use a different one</li>
<li>Wrong implementation of the 2nd level cache may result in a non expected performance degrade (i.e. hashtable doc)</li>
<li>First level cache is shared across same ISession, second level is shared across same ISessionFactory</li>
</ul>
<p>In the <a href="http://blog.raffaeu.com/archive/2011/12/29/nhibernate-cache-system-part-3.aspx" target="_blank">next article</a> we will see what are the available cache providers.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=W5wc09xo9lI:_W8ipyCer1M:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=W5wc09xo9lI:_W8ipyCer1M:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=W5wc09xo9lI:_W8ipyCer1M:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=W5wc09xo9lI:_W8ipyCer1M:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=W5wc09xo9lI:_W8ipyCer1M:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=W5wc09xo9lI:_W8ipyCer1M:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=W5wc09xo9lI:_W8ipyCer1M:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/W5wc09xo9lI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.raffaeu.com/archive/2011/12/29/nhibernate-cache-system-part-2.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.raffaeu.com/archive/2011/12/29/nhibernate-cache-system-part-2.aspx</feedburner:origLink></item>
		<item>
		<title>NHibernate cache system. Part 1</title>
		<link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/LHprF0klWKU/nhibernate-cache-system-part-1.aspx</link>
		<comments>http://blog.raffaeu.com/archive/2011/12/29/nhibernate-cache-system-part-1.aspx#comments</comments>
		<pubDate>Thu, 29 Dec 2011 20:22:49 +0000</pubDate>
		<dc:creator>raffaeu</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://raffaeu.com/?p=58</guid>
		<description><![CDATA[In this series of articles I will try to explain you how NHibernate cache system works and how it should be used in order to get the best performance/configuration from this product. Introduction  Architecture Cache Level 1 mechanism Load and Get, what’s the difference Session maintenance: Evict, Flush and Clear 2nd Level Cache Architecture Configuration <span class="ellipsis">&#8230;</span> <span class="more-link-wrap"><a href="http://blog.raffaeu.com/archive/2011/12/29/nhibernate-cache-system-part-1.aspx" class="more-link"><span>Read More &#8594;</span></a></span>]]></description>
				<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_button">
										<a name="fcbk_share"	href="http://www.facebook.com/raffaeu"	target="blank">
											<img src="http://blog.raffaeu.com/wp-content/plugins/facebook-button-plugin/img/standart-facebook-ico.jpg" alt="Fb-Button" />
										</a>	
									</div><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://blog.raffaeu.com/archive/2011/12/29/nhibernate-cache-system-part-1.aspx" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>In this series of articles I will try to explain you how NHibernate cache system works and how it should be used in order to get the best performance/configuration from this product.</p>
<ul>
<li><a href="#" target="_blank">Introduction</a> 
<ul>
<li>Architecture </li>
<li>Cache Level 1 mechanism </li>
<li>Load and Get, what’s the difference </li>
<li>Session maintenance: Evict, Flush and Clear </li>
</ul>
</li>
<li><a href="http://blog.raffaeu.com/archive/2011/12/31/nhibernate-cache-system-part-2.aspx" target="_blank">2nd Level Cache</a>
<ul>
<li>Architecture </li>
<li>Configuration</li>
<li>Cache by mapping</li>
<li>Cache by query</li>
<li>Final advice</li>
</ul>
</li>
<li><a href="http://blog.raffaeu.com/archive/2011/12/29/nhibernate-cache-system-part-3.aspx" target="_blank">Cache providers (most known)</a></li>
</ul>
<h3>NHibernate Cache architecture</h3>
<p>NHibernate has an internal cache architecture that I will define <strong>absolutely well done</strong>. On an architectural point of view, it is designed for the enterprise and it is 100% configurable. Consider that it allows you to create also your custom cache provider!</p>
<p>The following picture show the cache architecture overview of NHibernate (actually the version I am talking about is the 3.2 GA).</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/6d7183df-843c-45a9-9dfb-c3ee5fe2b94eimage_2.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/9333692a-0d14-40dd-bcbc-fc5ce4a9e01eimage_thumb.png" width="260" height="221"></a></p>
<p>The cache system is composed by two <strong>levels</strong>, the cache of level 1 that <em>usually</em> it is configured by default if you are working with the <em>ISession</em> object, and the cache of level 2 that by default <strong>is disabled</strong>.</p>
<p>The cache of level 1 is provided by the ISession data context and it is maintained by the lifecycle of the <em>ISession</em> object, this means that as soon as you destroy (dispose) an <em>ISession</em> object, also the cache of level 1 will be destroyed and all the corresponding objects will be detached from the ISession. This cache system works on a per transaction basis and it is designed to reduce the number of database calls during the lifecycle of an <em>ISession</em>. As an example, you should use this cache if you have the need to access and modify an object in a transaction, multiple times.</p>
<p>The cache of level 2 is provided by the <em>ISessionFactory</em> component and it is shared across <strong>all the session created using the same factory</strong>. Its lifecycle correspond to the lifecycle of the session factory and it provides a more powerful <strong>but also dangerous </strong>set of features. It allows you to keep objects in cache across multiple transactions and sessions; the objects are available <strong>everywhere</strong> and not only on the client that is using a specific <em>ISession</em>.  </p>
<h3>Cache Level 1 mechanism</h3>
<p>As soon as you start to create a new <em>ISession</em> (not an <em>IStatelessSession!!</em>) NHibernate starts to holds in memory, using a specific mechanism, all the objects that are involved with the current session. The methods used by NHibernate to load the data into the cache are two: <strong>Get&lt;T&gt;(id)</strong> and <strong>Load&lt;T&gt;(id)</strong>. This means that if you try to load one or more entities using: LinQ, HQL, ICriteria … NHibernate <strong>will not put them into the cache of level 1</strong>.</p>
<p>Another way to put an object into the lvl1 cache is to use persistence methods like Save, Delete, Update and SaveOrUpdate. </p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/0dc3762d-9ba3-4f45-b0d7-f0c7b9e269c9image_4.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/e57d1c34-00a9-4918-9262-04729cc6ba06image_thumb_1.png" width="251" height="260"></a></p>
<p>As you can see from the previous picture, the <em>ISession</em> object is able to contains two different categories of entities, the one that we define “loaded” using Get or Load and the one that we define “dirty”, which means that they were somehow modified and associated with a session.</p>
<h3>Load and Get, what’s the difference?</h3>
<p>A major confusion I personally noticed while working with NHibernate is the not correct usage of the two methods Get and Load so let’s see for a moment how they work and when they should or should not be used.</p>
<table border="1" cellspacing="0" cellpadding="2" width="547">
<tbody>
<tr>
<td valign="top" width="88">
<p align="left">       </td>
<td valign="top" width="181">
<h4 align="left">Get</h4>
</td>
<td valign="top" width="11">
<p align="left">       </td>
<td valign="top" width="254">
<h4 align="left">Load</h4>
</td>
<td valign="top" width="11"> </td>
</tr>
<tr>
<td valign="top" width="93">
<h4 align="left">Fetch method</h4>
</td>
<td valign="top" width="190">
<p align="left">Retrieve the entire entity in one SELECT statement and puts the entity in the cache.</p>
</td>
<td valign="top" width="11">
<p align="left">       </td>
<td valign="top" width="262">
<p align="left">Retrieve only the ID of the entity and returns a non fetched proxy instance of the entity. As soon as you “hit” a property, the entity is loaded.</p>
</td>
<td valign="top" width="11">
<p align="left">       </td>
</tr>
<tr>
<td valign="top" width="94">
<h4 align="left">How it loads</h4>
</td>
<td valign="top" width="193">
<p align="left">It verifies if the entity is in the cache, otherwise it tries to execute a SELECT</p>
</td>
<td valign="top" width="11">
<p align="left">       </td>
<td valign="top" width="264">
<p align="left">It verifies if the entity is in the cache, otherwise it tries to execute a SELECT</p>
</td>
<td valign="top" width="11">
<p align="left">       </td>
</tr>
<tr>
<td valign="top" width="94">
<h4 align="left">Not Available</h4>
</td>
<td valign="top" width="194">
<p align="left">If the entity does not exist, it returns NULL</p>
</td>
<td valign="top" width="11">
<p align="left">       </td>
<td valign="top" width="265">
<p align="left">If the entity does not exist, it THROW an exception</p>
</td>
<td valign="top" width="11">
<p align="left">       </td>
</tr>
<tr>
<td valign="top" width="94">
<p align="left">       </td>
<td valign="top" width="194">
<p align="left">       </td>
<td valign="top" width="11">
<p align="left">       </td>
<td valign="top" width="265">
<p align="left">       </td>
<td valign="top" width="11"> </td>
</tr>
</tbody>
</table>
<p>I personally prefer Get because it returns NULL instead of throwing a nasty exception, but this is a personal choice; while some of you may prefer to use Load because you want to avoid a database call until is really needed.</p>
<p>Below I wrote a couple of very simple tests to show you how the Get and Load methods work across the same <em>ISession</em>. </p>
<h3>Get&lt;T&gt;()</h3>
<div class="csharpcode">   <pre class="crayon-plain-tag"><span class="lnum">   1:  </span>[Test]</pre></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">   2:  </span>[Category(<span class="str">"Database"</span>)]</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">   3:  </span><span class="kwrd">public</span> <span class="kwrd">void</span> UsingGetThePersonIsFullyCached()</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">   4:  </span>{</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">   5:  </span>    <span class="kwrd">using</span> (var session = factory.OpenSession())</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">   6:  </span>    {</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">   7:  </span>        <span class="kwrd">using</span> (var tx = session.BeginTransaction(IsolationLevel.ReadCommitted))</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">   8:  </span>        {</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">   9:  </span>            var persons = MockFactory.MakePersons();</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">  10:  </span>            persons.ForEach(p =&gt; session.Save(p));</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">  11:  </span>            tx.Commit();</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">  12:  </span>            session.Clear();</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">  13:  </span>            Console.WriteLine(<span class="str">"*** FIRST SELECT ***"</span>);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">  14:  </span>            var expectedPerson1 = session.Get&lt;Person&gt;(persons[0].PersonId);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">  15:  </span>            Assert.That(expectedPerson1, Is.Not.Null);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">  16:  </span>            Console.WriteLine(<span class="str">"*** SECOND SELECT ***"</span>);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">  17:  </span>            var expectedPerson2 = session.Get&lt;Person&gt;(persons[0].PersonId);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">  18:  </span>            Assert.That(expectedPerson2, Is.Not.Null);</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">  19:  </span>            Assert.That(expectedPerson2.FirstName, Is.Not.EqualTo(<span class="kwrd">string</span>.Empty));</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">  20:  </span>        }</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">  21:  </span>    }</pre><p></p>
<p>  </p><pre class="crayon-plain-tag"><span class="lnum">  22:  </span>}</pre><p>
</p></div>
<style type="text/css"><![CDATA[</p>
<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; }]]&gt;</style>
<p>In this test I have created a list of Persons in one transaction and then I cleared the session in order to be sure that nothing was left in the cache. Then I loaded one of the Person entities using the Get&lt;T&gt; method and then I load it again using the same method call in order to verify that the SELECT statement was issued only once.</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/d6927ff4-0600-48e4-a344-19ff630e002dimage_6.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/ddd309af-52e6-44de-b6f8-8670f5c2ad40image_thumb_2.png" width="531" height="248"></a></p>
<p>As you can see, NHibernate is loading the entire entity from the database in the first call, and in the second one is simply loading it again from the level 1 cache. You should notice here that NHibernate is loading <strong>the entire entity</strong> in the first Get&lt;T&gt; call.</p>
<h3>Load&lt;T&gt;()</h3>
<p></p><pre class="crayon-plain-tag">[Test]
[Category(<span class="str">"Database"</span>)]
<span class="kwrd">public</span> <span class="kwrd">void</span> UsingLoadThePersonIsPartiallyCached()
{
    <span class="kwrd">using</span> (var session = factory.OpenSession())
    {
        <span class="kwrd">using</span> (var tx = session.BeginTransaction(IsolationLevel.ReadCommitted))
        {
            var persons = MockFactory.MakePersons();
            persons.ForEach(p =&gt; session.Save(p));
            tx.Commit();
            session.Clear();
            Console.WriteLine(<span class="str">"*** FIRST SELECT ***"</span>);
            var expectedPerson1 = session.Load&lt;Person&gt;(persons[0].PersonId);
            Assert.That(expectedPerson1, Is.Not.Null);
            Console.WriteLine(<span class="str">"*** SECOND SELECT ***"</span>);
            var expectedPerson2 = session.Load&lt;Person&gt;(persons[0].PersonId);
            Assert.That(expectedPerson2, Is.Not.Null);
            Assert.That(expectedPerson2.FirstName, Is.Not.EqualTo(<span class="kwrd">string</span>.Empty));
        }
    }
}</pre><p></p>
<p>In this second test I am executing the same exact steps of the previous one, but this time I am using the Load&lt;T&gt; method and the result is completely different! Look at the SQL log below:</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/cbda39a0-6f1a-4347-8e98-6c8eec217ec5image_8.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/f749fce2-2e94-4d25-ae2d-b28ba814da65image_thumb_3.png" width="536" height="242"></a></p>
<style type="text/css"><![CDATA[</p>
<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; }]]&gt;</style>
<p>Now NHibernate is not loading the entity from the database at all, it is loading it only in the second call, when I try to hit one of the Person properties. If you debug this code you will notice that NHibernate issues the database call at the line Assert.That(expectedPerson2.FirstName, Is.Not.EqualTo(<span class="kwrd">string</span>.Empty)); and not before!</p>
<h3>Session maintenance</h3>
<p>If you are working with the <em>ISession</em> object in a Client application or if you are keeping it alive in a web application using some strange behaviors like keeping it saved inside the <em>HttpContext</em> you will realize, soon or later, that sometimes the cache of level 1 needs to be cleared.</p>
<p>Now, despite the fact that these methods (based on my personal experience) should never be used, because it means that you are wrongly implementing your data layer, and despite the fact that the behavior of these methods may result in something <em>unexpected</em>, NHibernate provides three different methods to <em>clear</em> the cache of level 1 content.</p>
<table border="0" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td valign="top" width="10"> </td>
<td valign="top" width="117">
<h4>Session.Clear</h4>
</td>
<td valign="top" width="10"> </td>
<td valign="top" width="108">
<h4>Session.Evict</h4>
</td>
<td valign="top" width="10"> </td>
<td valign="top" width="169">
<h4>Session.Flush</h4>
</td>
<td valign="top" width="10"> </td>
</tr>
<tr>
<td valign="top" width="10"> </td>
<td valign="top" width="117"> </td>
<td valign="top" width="10"> </td>
<td valign="top" width="108"> </td>
<td valign="top" width="10"> </td>
<td valign="top" width="169"> </td>
<td valign="top" width="10"> </td>
</tr>
<tr>
<td valign="top" width="10"> </td>
<td valign="top" width="117">
<p align="left">Removed all the existing objects from the <em>ISession</em> <strong>without</strong> syncing them with the database</p>
</td>
<td valign="top" width="10">
<p align="left">
      </td>
<td valign="top" width="108">
<p align="left">Remove a specific object from the <em>ISession</em> <strong>without</strong> syncing it with the database</p>
</td>
<td valign="top" width="10">
<p align="left">
      </td>
<td valign="top" width="169">
<p align="left">Remove all the existing objects from the session <strong>by syncing</strong> them with the database</p>
</td>
<td valign="top" width="10">
<p align="left">
      </td>
</tr>
</tbody>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr></tr>
</tbody>
</table>
<p>I will probably write more about these three methods in some future post but if you need to investigate more about them, I would suggest you to read <strong>carefully</strong> the NHibernate docs available here: <a title="http://www.nhforge.org/doc/nh/en/index.html" href="http://www.nhforge.org/doc/nh/en/index.html">http://www.nhforge.org/doc/nh/en/index.html</a></p>
<p>In the next article we talk about the level 2 cache.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=LHprF0klWKU:u9oGb_pmaNo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=LHprF0klWKU:u9oGb_pmaNo:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=LHprF0klWKU:u9oGb_pmaNo:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=LHprF0klWKU:u9oGb_pmaNo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=LHprF0klWKU:u9oGb_pmaNo:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=LHprF0klWKU:u9oGb_pmaNo:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=LHprF0klWKU:u9oGb_pmaNo:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/LHprF0klWKU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.raffaeu.com/archive/2011/12/29/nhibernate-cache-system-part-1.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.raffaeu.com/archive/2011/12/29/nhibernate-cache-system-part-1.aspx</feedburner:origLink></item>
		<item>
		<title>Sharing assembly version in Visual Studio 2010.</title>
		<link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/bz7zkWA3eyY/sharing-assembly-version-in-visual-studio-2010.aspx</link>
		<comments>http://blog.raffaeu.com/archive/2011/12/11/sharing-assembly-version-in-visual-studio-2010.aspx#comments</comments>
		<pubDate>Sun, 11 Dec 2011 17:58:05 +0000</pubDate>
		<dc:creator>raffaeu</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[NET World]]></category>
		<category><![CDATA[TFS]]></category>

		<guid isPermaLink="false">http://raffaeu.com/?p=88</guid>
		<description><![CDATA[Last week I came up with a fancy requirement that forced me to struggle a little bit in order to find an appropriate solution. Let’s say that we have a massive solution file, containing something like 100ish projects and we would like to keep the same assembly version number for all these projects. In this <span class="ellipsis">&#8230;</span> <span class="more-link-wrap"><a href="http://blog.raffaeu.com/archive/2011/12/11/sharing-assembly-version-in-visual-studio-2010.aspx" class="more-link"><span>Read More &#8594;</span></a></span>]]></description>
				<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_button">
										<a name="fcbk_share"	href="http://www.facebook.com/raffaeu"	target="blank">
											<img src="http://blog.raffaeu.com/wp-content/plugins/facebook-button-plugin/img/standart-facebook-ico.jpg" alt="Fb-Button" />
										</a>	
									</div><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://blog.raffaeu.com/archive/2011/12/11/sharing-assembly-version-in-visual-studio-2010.aspx" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>Last week I came up with a fancy requirement that forced me to struggle a little bit in order to find an appropriate solution. Let’s say that we have a massive solution file, containing something like 100ish projects and we would like to keep the same assembly version number for all these projects.</p>
<p>In this article I will show you how the assembly version number works in .NET and what are the possible solutions, using Visual Studio.</p>
<h3>Assembly version in .NET</h3>
<p>As soon as you add a new project (of any type) in Visual Studio 2010, you will come up with a default template that contains also a file <em>“AssemblyInfo.cs”</em> if you are working with C# or <em>“AssemblyInfo.vb”</em> if you are working with VB.NET.</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/c67498fc-1ff4-4ae5-a87c-44380db74011image_2.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/4950d5cf-38ca-461b-8e36-67e72984cb26image_thumb.png" width="260" height="119"></a></p>
<p>If we look at the content of this file we will discover that it contains a set of attributes used by MSBuild to prepare the assembly file (.dll or .EXE) with the information provided in this file. In order to change this information we have two options:</p>
<ol>
<li>Edit the AssemblyInfo.cs using the Visual Studio editor.      <br />In this case we are interested in the following attributes, that we will need to change every time we want to increase the assembly version number:       <br /> 
<div class="csharpcode">       <pre class="crayon-plain-tag"><span class="lnum">   1:  </span><span class="kwrd">using</span> System.Reflection;</pre></p>
<p>      </p><pre class="crayon-plain-tag"><span class="lnum">   2:  </span><span class="kwrd">using</span> System.Runtime.CompilerServices;</pre><p></p>
<p>      </p><pre class="crayon-plain-tag"><span class="lnum">   3:  </span><span class="kwrd">using</span> System.Runtime.InteropServices;</pre><p></p>
<p>      </p><pre class="crayon-plain-tag"><span class="lnum">   4:  </span> </pre><p></p>
<p>      </p><pre class="crayon-plain-tag"><span class="lnum">   5:  </span>[assembly: AssemblyVersion(<span class="str">"1.0.0.0"</span>)]</pre><p></p>
<p>      </p><pre class="crayon-plain-tag"><span class="lnum">   6:  </span>[assembly: AssemblyFileVersion(<span class="str">"1.0.0.0"</span>)]</pre><p>
    </p></div>
</li>
<style type="text/css"><![CDATA[</p>
<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; }]]&gt;</style>
<li>Or, we can open the Project properties window from Visual Studio using the shortcut ALT+ENTER or by choosing “properties” of a VS project file from the Solution Explorer<br />
    <br /><a href="http://raffaeu.com/wp-content/uploads/2013/03/f137c3a4-ac11-4b7b-afe9-4bab7fe508c5image_4.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/c0256692-f910-4a63-9b83-1656f930083aimage_thumb_1.png" width="260" height="182"></a> </li>
</ol>
<h3>How does the versioning work?</h3>
<p>The first thing that I tried was to understand exactly how this magic number works in .NET.</p>
<p>If you go to the <a href="http://msdn.microsoft.com/en-us/library/51ket42z.aspx?ppud=4" target="_blank">online MSDN article</a>, you will find out that the version number of an assembly is composed by 4 numbers, and each one has a specific mean</p>
<p><strong>1.</strong> <strong>Major =</strong> manually incremented for major releases, such as adding many new features to the solution. </p>
<p><strong>0.</strong> <strong>Minor =</strong> manually incremented for minor releases, such as introducing small changes to existing features. </p>
<p><strong>0.</strong> <strong>Build =</strong> typically incremented automatically as part of every build performed on the Build Server. This allows each build to be tracked and tested. </p>
<p><strong>0</strong> <strong>Revision =</strong> incremented for QFEs (a.k.a. “hotfixes” or patches) to builds released into the Production environment (PROD). This is set to zero for the initial release of any major/minor version of the solution.</p>
<h3>Two different assembly version attributes, why?</h3>
<p>I noticed that the <em>[assembly]</em> attribute class exposes two different properties, Assembly Version and Assembly File Version. </p>
<p><strong>AssemblyFileVersion</strong></p>
<p><font color="#2e2e2e">This attribute should be incremented every time our build server (TFS) runs a build. Based on the previous description you should increase the third number, the build version number. This attribute should be placed in a different .cs file for each project to allow full control of it. </font></p>
<p><strong>AssemblyVersion</strong></p>
<p><font color="#2e2e2e">This attributes represents the version of the NET assembly you are referencing in your projects. If you increase this number in every TFS build, you will incur in the problem of changing your reference redirect every time the assembly version is increased.</font></p>
<p><font color="#2e2e2e">This number should be increased <strong>only</strong> when you release a new version of your assembly and it should be increase following the assembly versioning terminology (major, minor, …)</font></p>
<h3><font color="#2e2e2e">Control the Versioning in Visual Studio</font></h3>
<p><font color="#2e2e2e">As I said before VS allows us to control the version number in different ways and in my opinion using the properties window is the easiest one. As soon as you change one of the version numbers from the properties window, also the AssembliInfo.cs file will be automatically changed.</font></p>
<p><font color="#2e2e2e">But what happens if we delete the version attributes from the assembly info file? </font>As expected VS will create an assembly with version 0.0.0.0 like the picture below:</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/f3305793-affa-44dc-9335-d8529e7954acimage_6.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/9ae2db4f-d0ca-4147-a573-972ab31ad770image_thumb_2.png" width="260" height="230"></a></p>
<div style="border-bottom: #666666 1px solid; border-left: #666666 1px solid; padding-bottom: 3px; padding-left: 3px; padding-right: 3px; background: #efefef; border-top: #666666 1px solid; border-right: #666666 1px solid; padding-top: 3px">
<p><strong>Note:</strong> if we open the Visual Studio properties window for the project and we write down the version 1.0.0.1 for both, Assembly and AssemblyFile attribute, VS will re-create these two attributes in the AssemblyInfo.cs file.</p>
</div>
<h3>Sharing a common Assembly version on multiple projects</h3>
<p>Going back to the request I got, how can we setup a configuration in Visual Studio that allows us to share on multiple projects the same assembly version? A partial solution can be accomplished using shared linked files on Visual Studio.</p>
<p>Ok, what’s a shared linked file, first of all? A linked file is a file shortcut that points in multiple projects to the same single file instance. A detailed explanation of this mechanism is available on <a href="http://blogs.msdn.com/b/jjameson/archive/2009/04/02/linked-files-in-visual-studio-solutions.aspx" target="_blank">Jeremy Jameson’s blog at this page</a>.</p>
<p>Now, this is the solution I have created as an example where I share an AssemblyVersion.cs file and an AssemblyFileVersion.cs file to the entire Visual Studio solution.</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/4b4a64ba-72e2-4ac0-ad51-dcb865381154image_8.png"><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="image" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/0640c08e-6764-48d7-8ee0-beea94e7f6e7image_thumb_3.png" width="233" height="260"></a></p>
<p>Using this approach we have one single place where we can edit the AssemblyFileVersion and the AssemblyVersion attributes. In order to accomplish this solution you need to perform the following steps:</p>
<ol>
<li>Delete the assembly version and the assembly file version attributes for all the existing AssemblyInfo.cs files</li>
<li>Create in one project (the root project) a file called AssemblyFileVersion.cs containing <strong>only</strong> the attribute AssemblyFileVersion</li>
<li>Create in one project (the root project) a file called AssemblyVersion.cs containing <strong>only</strong> the attribute AssenblyVersion</li>
<li>Add as linked files these two files to all the existing projects</li>
<li>Re-Build everything</li>
</ol>
<h3>Final note on Visual Studio properties window</h3>
<p>Even if my root project has now two files with the attributes AssemblyFileVersion and AssemblyVersion, when I open the Visual Studio properties window, it tries to search for these attributes in the AssemblyInfo.cs file, and clearly, it can’t find them anymore, so it does not display anything:</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/c016850a-aaeb-4fa7-99ce-b578571c943aimage_10.png"><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="image" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/d24f2dce-5a08-410f-b32e-f1314db722b6image_thumb_4.png" width="260" height="74"></a></p>
<p>If you add a value to these textboxes Visual Studio will re-create the two attributes in the AssemblyInfo.cs file without taking care of the two new files we have created and as soon as you try to compile the project you will receive this nice error:</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/528f6cf2-da4e-4b59-a36c-3948b34f81aaimage_12.png"><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="image" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/3e98ef87-c024-46c4-ba5d-e882b1c9636fimage_thumb_5.png" width="260" height="93"></a></p>
<p>So, in order to use this solution you need to keep in mind that you <strong>can’t edit the AssemblyFileVersion and the AssemblyVersion attributes from the VS properties window if they are not saved in the AssemblyInfo.cs file!</strong></p>
<p><font color="#2e2e2e">I believe that MS should change this in the next versions of Visual Studio.</font></p>
<p><img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://raffaeu.com/wp-content/uploads/2013/03/3e03e19c-bbf7-475a-a2ef-e4b770dca612wlEmoticon-winkingsmile_2.png"></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=bz7zkWA3eyY:ZhYA7BNFq-Y:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=bz7zkWA3eyY:ZhYA7BNFq-Y:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=bz7zkWA3eyY:ZhYA7BNFq-Y:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=bz7zkWA3eyY:ZhYA7BNFq-Y:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=bz7zkWA3eyY:ZhYA7BNFq-Y:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=bz7zkWA3eyY:ZhYA7BNFq-Y:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=bz7zkWA3eyY:ZhYA7BNFq-Y:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/bz7zkWA3eyY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.raffaeu.com/archive/2011/12/11/sharing-assembly-version-in-visual-studio-2010.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.raffaeu.com/archive/2011/12/11/sharing-assembly-version-in-visual-studio-2010.aspx</feedburner:origLink></item>
		<item>
		<title>NET Event–Migrating WinForm application</title>
		<link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/_OPxbr7z-zc/net-eventmigrating-winform-application.aspx</link>
		<comments>http://blog.raffaeu.com/archive/2011/08/14/net-eventmigrating-winform-application.aspx#comments</comments>
		<pubDate>Sun, 14 Aug 2011 13:45:47 +0000</pubDate>
		<dc:creator>raffaeu</dc:creator>
				<category><![CDATA[ALT]]></category>
		<category><![CDATA[Bermuda]]></category>
		<category><![CDATA[NET World]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://raffaeu.com/?p=89</guid>
		<description><![CDATA[Last month (21st of July 2011) I spoke at the Bermuda NET Event “Migrating WinForm applications to WPF/Silverlight”. This has been for me the first NET Event in Bermuda but for sure it will not be the last one. We are planning to have a new event this autumn where we will touch other topics <span class="ellipsis">&#8230;</span> <span class="more-link-wrap"><a href="http://blog.raffaeu.com/archive/2011/08/14/net-eventmigrating-winform-application.aspx" class="more-link"><span>Read More &#8594;</span></a></span>]]></description>
				<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_button">
										<a name="fcbk_share"	href="http://www.facebook.com/raffaeu"	target="blank">
											<img src="http://blog.raffaeu.com/wp-content/plugins/facebook-button-plugin/img/standart-facebook-ico.jpg" alt="Fb-Button" />
										</a>	
									</div><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://blog.raffaeu.com/archive/2011/08/14/net-eventmigrating-winform-application.aspx" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>Last month (21st of July 2011) I spoke at the Bermuda NET Event “Migrating WinForm applications to WPF/Silverlight”. This has been for me the first NET Event in Bermuda but for sure it will not be the last one. We are planning to have a new event this autumn where we will touch other topics like: ALM, Parallels and more.</p>
<p>Thanks to <a href="http://www.facebook.com/alessio.bellisomi" target="_blank">Alessio Bellisomi</a>, the web developer that works in my company, I am able to share with you some nice pictures of the event and three short movie of the event. Unfortunately, for this event, we were not super organized so I do not have with me the full video of the entire event. I promise that for the next event we will provide the entire video and maybe we will be also able to stream the content.</p>
<p>The audience, considering that we were in Bermuda and considering that it was end of July, was more than expected. I believe we were around a 30/40 ish attendees. The feedback has been really positive and we expect a very fast grow of this UserGroup by having more events and more speakers.</p>
<h2>Pictures</h2>
<p>The pictures are available through Google photos </p>
<p> <embed type="application/x-shockwave-flash" src="https://picasaweb.google.com/s/c/bin/slideshow.swf" width="144" height="96" flashvars="host=picasaweb.google.com&amp;captions=1&amp;hl=en_US&amp;feat=flashalbum&amp;RGB=0x000000&amp;feed=https%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2Fraffaeu%2Falbumid%2F5640743268896206417%3Falt%3Drss%26kind%3Dphoto%26hl%3Den_US" pluginspage="http://www.macromedia.com/go/getflashplayer"><br />
<h2>Slides</h2>
<div style="width:425px" id="__ss_8848318"><strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/raffaeu/net-event-migrating-winform" title="NET Event - Migrating WinForm">NET Event &#8211; Migrating WinForm</a></strong><object id="__sse8848318" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=presentation1-110814120211-phpapp02&amp;stripped_title=net-event-migrating-winform&amp;userName=raffaeu"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed name="__sse8848318" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=presentation1-110814120211-phpapp02&amp;stripped_title=net-event-migrating-winform&amp;userName=raffaeu" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></object>
<div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/raffaeu"><a href="http://blog.raffaeu.com" title="Raffaeu's blog" rel="">raffaeu</a></a>.</div>
</div>
<h2>Videos</h2>
<p>The videos have been hosted on my Vimeo account and they can be viewed through their web site</p>
<p>  <iframe src="http://player.vimeo.com/video/27398653?title=0&amp;byline=0&amp;portrait=0" width="400" height="300" frameborder="0"></iframe>
<p><a href="http://vimeo.com/27398653">Bermuda WinForm event, part 01</a> from <a href="http://vimeo.com/user7379626">Raffaele Garofalo</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>  <iframe src="http://player.vimeo.com/video/27399835?title=0&amp;byline=0&amp;portrait=0" width="400" height="300" frameborder="0"></iframe>
<p><a href="http://vimeo.com/27399835">Bermuda WinForm event, part 02</a> from <a href="http://vimeo.com/user7379626">Raffaele Garofalo</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>  <iframe src="http://player.vimeo.com/video/27509545?title=0&amp;byline=0&amp;portrait=0" width="400" height="300" frameborder="0"></iframe>
<p><a href="http://vimeo.com/27509545">Bermuda WinForm, part 03</a> from <a href="http://vimeo.com/user7379626">Raffaele Garofalo</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<h2>Thanks</h2>
<p>Special thanks need to go to Sandra de Silva (president of the UG and owner of <a href="http://www.nova.bm/" target="_blank">Nova Ltd</a>) and to the other members of the committee. I want also to thank all the participants and I hope this autumn there will be more!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=_OPxbr7z-zc:AFSG7mxTcIQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=_OPxbr7z-zc:AFSG7mxTcIQ:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=_OPxbr7z-zc:AFSG7mxTcIQ:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=_OPxbr7z-zc:AFSG7mxTcIQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=_OPxbr7z-zc:AFSG7mxTcIQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=_OPxbr7z-zc:AFSG7mxTcIQ:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=_OPxbr7z-zc:AFSG7mxTcIQ:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/_OPxbr7z-zc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.raffaeu.com/archive/2011/08/14/net-eventmigrating-winform-application.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.raffaeu.com/archive/2011/08/14/net-eventmigrating-winform-application.aspx</feedburner:origLink></item>
		<item>
		<title>Speaking about WPF in Bermuda.</title>
		<link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/JFHz6aQM2Xc/speaking-about-wpf-in-bermuda.aspx</link>
		<comments>http://blog.raffaeu.com/archive/2011/07/09/speaking-about-wpf-in-bermuda.aspx#comments</comments>
		<pubDate>Sat, 09 Jul 2011 12:31:10 +0000</pubDate>
		<dc:creator>raffaeu</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://raffaeu.com/?p=90</guid>
		<description><![CDATA[Last year in Bermuda we had a new born, a NET community. The community has been created by some locals companies to attract developers, architects and analyst; but also anybody passionate of development. You can check-out the web site here: http://www.dnug.bm/. This month I will have the opportunity to present my two books: Applied WPF <span class="ellipsis">&#8230;</span> <span class="more-link-wrap"><a href="http://blog.raffaeu.com/archive/2011/07/09/speaking-about-wpf-in-bermuda.aspx" class="more-link"><span>Read More &#8594;</span></a></span>]]></description>
				<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_button">
										<a name="fcbk_share"	href="http://www.facebook.com/raffaeu"	target="blank">
											<img src="http://blog.raffaeu.com/wp-content/plugins/facebook-button-plugin/img/standart-facebook-ico.jpg" alt="Fb-Button" />
										</a>	
									</div><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://blog.raffaeu.com/archive/2011/07/09/speaking-about-wpf-in-bermuda.aspx" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>Last year in Bermuda we had a new born, a NET community. The community has been created by some locals companies to attract developers, architects and analyst; but also anybody passionate of development.</p>
<p>You can check-out the web site here: <a href="http://www.dnug.bm/">http://www.dnug.bm/</a>.</p>
<p>This month I will have the opportunity to present my two books:</p>
<ul>
<li>
<div align="left"><a href="http://www.apress.com/catalogsearch/result/?q=1430234709&amp;submit=Go" target="_blank">Applied WPF in context (APRESS)</a></div>
</li>
<li><a href="http://oreilly.com/catalog/9780735650923/" target="_blank">Build enterprise application with WPF and MVVM (MS PRESS)</a></li>
</ul>
<p>and to talk about WPF/Silverlight.</p>
<p>During this event I will explain what are the common problems you may encounter when moving from legacy applications to WPF/Silverlight. When you should and when you should not migrate an application to a new UI technology. When you should use WPF and when you should use Silverlight. Oh and I will also give some free copies of my books plus some additional discounts.</p>
<p>This is the page of the event: <a href="http://www.dnug.bm/index.php?option=com_jevents&amp;task=icalrepeat.detail&amp;evid=5&amp;Itemid=58&amp;year=2011&amp;month=07&amp;day=21&amp;title=july-2011-dot-net-user-group-event&amp;uid=a620ff387a7449aaad68443c9780f7c2">http://www.dnug.bm/index.php?option=com_jevents&amp;task=icalrepeat.detail&amp;evid=5&amp;Itemid=58&amp;year=2011&amp;month=07&amp;day=21&amp;title=july-2011-dot-net-user-group-event&amp;uid=a620ff387a7449aaad68443c9780f7c2</a></p>
<p>If you are planning a vacation around the 21st of July, please come here and join us in this first event about WPF/Silverlight.</p>
<p>Hope to see you there!</p>
<p>PS: I forgot to mention that one of the amazing price for the attendees is to win a 1 year subscription to MSDN.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=JFHz6aQM2Xc:sBDAv85nqmQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=JFHz6aQM2Xc:sBDAv85nqmQ:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=JFHz6aQM2Xc:sBDAv85nqmQ:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=JFHz6aQM2Xc:sBDAv85nqmQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=JFHz6aQM2Xc:sBDAv85nqmQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=JFHz6aQM2Xc:sBDAv85nqmQ:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=JFHz6aQM2Xc:sBDAv85nqmQ:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/JFHz6aQM2Xc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.raffaeu.com/archive/2011/07/09/speaking-about-wpf-in-bermuda.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.raffaeu.com/archive/2011/07/09/speaking-about-wpf-in-bermuda.aspx</feedburner:origLink></item>
		<item>
		<title>TypeMock tutorial #03. Control behaviors.</title>
		<link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/Tkmw1jD8ML0/typemock-tutorial-03-control-behaviors.aspx</link>
		<comments>http://blog.raffaeu.com/archive/2011/07/01/typemock-tutorial-03-control-behaviors.aspx#comments</comments>
		<pubDate>Fri, 01 Jul 2011 23:49:36 +0000</pubDate>
		<dc:creator>raffaeu</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Pattern]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[TypeMock]]></category>

		<guid isPermaLink="false">http://raffaeu.com/?p=96</guid>
		<description><![CDATA[Note for purists: In this tutorial I am showing you a simplified example of a Unit of Work and a Repository, please do not care about the complexity or simplicity of these objects but look at the TypeMock implementations. We are now at the third post of this series and I found out that there <span class="ellipsis">&#8230;</span> <span class="more-link-wrap"><a href="http://blog.raffaeu.com/archive/2011/07/01/typemock-tutorial-03-control-behaviors.aspx" class="more-link"><span>Read More &#8594;</span></a></span>]]></description>
				<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_button">
										<a name="fcbk_share"	href="http://www.facebook.com/raffaeu"	target="blank">
											<img src="http://blog.raffaeu.com/wp-content/plugins/facebook-button-plugin/img/standart-facebook-ico.jpg" alt="Fb-Button" />
										</a>	
									</div><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://blog.raffaeu.com/archive/2011/07/01/typemock-tutorial-03-control-behaviors.aspx" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p style="border-bottom: #666666 1px solid; border-left: #666666 1px solid; padding-bottom: 3px; margin: 3px; padding-left: 3px; padding-right: 3px; background: #eee; border-top: #666666 1px solid; border-right: #666666 1px solid; padding-top: 3px; border-radius: 5px; -moz-border-radius: 5px"><strong>Note for purists: </strong>In this tutorial I am showing you a <strong>simplified example of a Unit of Work and a Repository</strong>, please do not care about the complexity or simplicity of these objects but look at the TypeMock implementations.</p>
<p>We are now at the third post of this series and I found out that there are a lot of readers interested in learning <a href="http://www.typemock.com" target="_blank">TypeMock</a>, which means that series will have to continue! </p>
<p><a href="http://blog.raffaeu.com/archive/2011/06/25/typemock-tutorial-02-object-creation.aspx" target="_blank">Last time</a>, we have created some object’s mocks using TypeMock but they were simple Value Objects with nothing or very few business logic in it. This time I want to show you how you can control the behaviors of a mock so that you do not have to control or fake the entire object if you are testing a single method.</p>
<h2>Testing a IUnitOfWork</h2>
<p>I do not know if you have already created a data layer in your career of software developer; if you did not, you can have a look at one of my tutorials or books about layering an application. </p>
<p>First of all we have a <a href="http://martinfowler.com/eaaCatalog/unitOfWork.html" target="_blank">Unit of Work</a>, which allows us to <em>“Save”</em>, <em>“Update”</em> or <em>“Delete”</em> the object we are passing it using a generic signature. The contract for a Unit of Work is represented by the following image:</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/1e9c5526-c5c8-4e89-8a12-ed3e9f1fe12fimage_2.png" rel="lightbox"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" align="left" src="http://raffaeu.com/wp-content/uploads/2013/03/9f0daf1e-cb0b-4e24-b105-2dbb45f9463aimage_thumb.png" width="187" height="183"></a></p>
<p>As you can see we have a simple interface with three methods and we still do not have an implementation for it but we have some <strong>expectations</strong> that we would like to pre-test using a mock in order to be sure that the next step will be properly handled by TypeMock.</p>
<p>The <strong>pre-requisite</strong> is that every <strong>entity</strong> in our domain has some properties inherited by a base class DomainObject; these properties can tell us the <strong>ID</strong> of the entity, if the <strong>entity</strong> is <strong>new, modified</strong> or <strong>deleted</strong>.</p>
<p>The following object represents the base class for a domain entity.</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/d87286f6-9d66-4aa5-b7e2-1b061e376543image_4.png" rel="lightbox"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" align="left" src="http://raffaeu.com/wp-content/uploads/2013/03/f56de5eb-b024-48d5-80fb-40f39276e70bimage_thumb_1.png" width="187" height="200"></a></p>
<p>The 3 properties are of type boolean while the UniqueId is of type Guid, so by default we will have a Guid.Empty value and after we mark dirty or updated the object we should have them populated.</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<h2>Test the interface</h2>
<p>If we test the interface we can start by writing three different expectations like the three following snippets:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c6d23991-ac79-4ca3-995d-8795a3b0c70b" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Mark a new entity</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #000000; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#ffffff">[</span><span style="color:#ffc66d">Test</span><span style="color:#ffffff">]</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">[</span><span style="color:#ffc66d">Category</span><span style="color:#ffffff">(</span><span style="color:#a5c25c">"DataLayer"</span><span style="color:#ffffff">)]</span></li>
<li><span style="color:#ffffff"></span><span style="color:#cc7832">public</span><span style="color:#ffffff"> </span><span style="color:#cc7832">void</span><span style="color:#ffffff"> CanMarkANewEntityToNewAndChangeItsId()</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">{</span></li>
<li>    <span style="color:#ffffff"></span><span style="color:#ffc66d">Person</span><span style="color:#ffffff"> person = </span><span style="color:#ffc66d">Isolate</span><span style="color:#ffffff">.Fake.Instance&lt;</span><span style="color:#ffc66d">Person</span><span style="color:#ffffff">&gt;();</span></li>
<li style="background: #0c0c0c">    <span style="color:#ffffff"></span><span style="color:#6897bb">IUnitOfWork</span><span style="color:#ffffff"> uow = </span><span style="color:#ffc66d">Isolate</span><span style="color:#ffffff">.Fake.Instance&lt;</span><span style="color:#6897bb">IUnitOfWork</span><span style="color:#ffffff">&gt;();</span></li>
<li>    <span style="color:#ffffff">uow.MarkNew(person);</span></li>
<li style="background: #0c0c0c">    <span style="color:#ffffff"></span><span style="color:#ffc66d">Assert</span><span style="color:#ffffff">.That(person, </span><span style="color:#ffc66d">Has</span><span style="color:#ffffff">.Property(</span><span style="color:#a5c25c">&#8220;UniqueId&#8221;</span><span style="color:#ffffff">).Not.EqualTo(</span><span style="color:#6897bb">Guid</span><span style="color:#ffffff">.Empty));</span></li>
<li>    <span style="color:#ffffff"></span><span style="color:#ffc66d">Assert</span><span style="color:#ffffff">.That(person, </span><span style="color:#ffc66d">Has</span><span style="color:#ffffff">.Property(</span><span style="color:#a5c25c">&#8220;IsNew&#8221;</span><span style="color:#ffffff">).True);</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">}</span></li>
</ol></div>
</p></div>
</p></div>
<p>And as soon as we run this test it simply fails because of course TypeMock is not able to properly mock the method MarkNew as we did not instruct it on how to do it …</p>
<p>The solution in this case is pretty straightforward, before invoking the MarkNew&lt;T&gt; method we need to teach to TypeMock what is our expectation for this method when we add a Person object to it.</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:21544d38-b692-48fe-8fcb-5c9b88216386" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">DoInstead()</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #000000; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#ffffff"></span><span style="color:#ffc66d">Isolate</span><span style="color:#ffffff">.WhenCalled(() =&gt; </span></li>
<li style="background: #0c0c0c">    <span style="color:#ffffff">uow.MarkNew(person))</span></li>
<li>    <span style="color:#ffffff">.DoInstead(callContext =&gt;</span></li>
<li style="background: #0c0c0c">                   <span style="color:#ffffff">{</span></li>
<li>                       <span style="color:#ffffff"></span><span style="color:#cc7832">var</span><span style="color:#ffffff"> p = callContext.Parameters[</span><span style="color:#6897bb">0</span><span style="color:#ffffff">] </span><span style="color:#cc7832">as</span><span style="color:#ffffff"> </span><span style="color:#ffc66d">Person</span><span style="color:#ffffff">;</span></li>
<li style="background: #0c0c0c">                       <span style="color:#ffffff">p.UniqueId = </span><span style="color:#6897bb">Guid</span><span style="color:#ffffff">.NewGuid();</span></li>
<li>                       <span style="color:#ffffff">p.IsNew = </span><span style="color:#cc7832">true</span><span style="color:#ffffff">;</span></li>
<li style="background: #0c0c0c">                       <span style="color:#ffffff"></span><span style="color:#cc7832">return</span><span style="color:#ffffff"> p;</span></li>
<li>                   <span style="color:#ffffff">});</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff"></span><span style="color:#cc7832">var</span><span style="color:#ffffff"> expectedPerson = uow.MarkNew(person);</span></li>
</ol></div>
</p></div>
</p></div>
<p>In this case we have informed TypeMock that when we will call the method MarkNew&lt;T&gt; passing as a generic paramenter the Person object, it will have to modify the person object and return it with a new ID and the IsNew property populated.</p>
<p>Another way to do that is to use the WillReturn method of TypeMock that can be used, like in this case when we have functions and not void methods.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4f4ecd34-ef1c-4561-aedb-94b6e0e8e8c0" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">WillReturn</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #000000; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li><span style="color:#ffffff">person.UniqueId = </span><span style="color:#6897bb">Guid</span><span style="color:#ffffff">.NewGuid();</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">person.IsNew = </span><span style="color:#cc7832">true</span><span style="color:#ffffff">;</span></li>
<li><span style="color:#ffffff"></span><span style="color:#ffc66d">Isolate</span><span style="color:#ffffff">.WhenCalled(() =&gt; uow.MarkNew&lt;</span><span style="color:#ffc66d">Person</span><span style="color:#ffffff">&gt;(person)).WillReturn(person);</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff"></span><span style="color:#cc7832">var</span><span style="color:#ffffff"> expectedPerson = uow.MarkNew(person);</span></li>
</ol></div>
</p></div>
</p></div>
<p>In the same way we can test that the method may also return an unexpected exception, so we can inform TypeMock to force the mock interface to throw an exception.</p>
<p>This section of type mock is called <strong><em>Controlling method behaviors</em></strong> and you can find a detailed documentation about it at this address:</p>
<p><a href="http://docs.typemock.com/isolator/##typemock.chm/Documentation/SettingBehaviorAAA.html" target="_blank">controlling methods</a></p>
<p>In the next tutorial we will see how to customize a chain of mockup object and faking the methods so that the IUnitOfWork will be used as a dependency for a Repository class.</p>
<p>If you want you can also download the code of every tutorial at this address on Codeplex:</p>
<p><a href="http://typemock.codeplex.com/">http://typemock.codeplex.com/</a></p>
<p><img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://raffaeu.com/wp-content/uploads/2013/03/9eccd053-31b7-4db9-8840-b8d53e965552wlEmoticon-winkingsmile_2.png"></p>
<p><strong>Encrypted string of the week: </strong>IHcKGzESRVs= <strong>     <br />using Blowfish CBC 64bit</strong></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=Tkmw1jD8ML0:CcNPg-dpX_E:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=Tkmw1jD8ML0:CcNPg-dpX_E:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=Tkmw1jD8ML0:CcNPg-dpX_E:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=Tkmw1jD8ML0:CcNPg-dpX_E:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=Tkmw1jD8ML0:CcNPg-dpX_E:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=Tkmw1jD8ML0:CcNPg-dpX_E:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=Tkmw1jD8ML0:CcNPg-dpX_E:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/Tkmw1jD8ML0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.raffaeu.com/archive/2011/07/01/typemock-tutorial-03-control-behaviors.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.raffaeu.com/archive/2011/07/01/typemock-tutorial-03-control-behaviors.aspx</feedburner:origLink></item>
		<item>
		<title>TypeMock tutorial #02. Object creation.</title>
		<link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/u-RRN9ROLvc/typemock-tutorial-02-object-creation.aspx</link>
		<comments>http://blog.raffaeu.com/archive/2011/06/25/typemock-tutorial-02-object-creation.aspx#comments</comments>
		<pubDate>Sat, 25 Jun 2011 00:01:13 +0000</pubDate>
		<dc:creator>raffaeu</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Pattern]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[TypeMock]]></category>

		<guid isPermaLink="false">http://raffaeu.com/?p=104</guid>
		<description><![CDATA[In this new  part of the TypeMock series I am going to show you how to deal with objects and classes in general, how you can create them and what are (honestly aren’t) the limit of TypeMock on dealing with objects. First of all I have just drawn down a little domain that I have <span class="ellipsis">&#8230;</span> <span class="more-link-wrap"><a href="http://blog.raffaeu.com/archive/2011/06/25/typemock-tutorial-02-object-creation.aspx" class="more-link"><span>Read More &#8594;</span></a></span>]]></description>
				<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_button">
										<a name="fcbk_share"	href="http://www.facebook.com/raffaeu"	target="blank">
											<img src="http://blog.raffaeu.com/wp-content/plugins/facebook-button-plugin/img/standart-facebook-ico.jpg" alt="Fb-Button" />
										</a>	
									</div><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://blog.raffaeu.com/archive/2011/06/25/typemock-tutorial-02-object-creation.aspx" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>In this new  part of the <a href="http://www.typemock.com" target="_blank">TypeMock</a> series I am going to show you how to deal with objects and classes in general, how you can create them and what are (honestly aren’t) the limit of TypeMock on dealing with objects.</p>
<p>First of all I have just drawn down a little domain that I have added to the demo application. I am planning to upload this demo the next week on Codeplex.com so that every geek reading this blog can just go there and download the source code.</p>
<h2>The Demo domain</h2>
<p>The domain is a very simple one, we have an abstract base class called <strong>Person, </strong>then we have two concrete classes, an <strong>Employee</strong> and a <strong>Customer</strong> that right now do not have any differences (we will see in the next tutorials why we have two different concrete classes) and then we have a value object <strong>Address</strong> that is composed <strong>only if we provide to it a parent Person object in the constructor. </strong>The Person entity exposes a <strong>read-only IEnumerable</strong> collection of Addresses, so in order to add or remove an address we must use the provided methods AddAddress and RemoveAddress.</p>
<p>The following picture shows the corresponding class diagram of this small domain.</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/32c85ac2-b89f-4a77-8c5c-9df9c2f1d0caClassDiagram_2.png" rel="lightbox[Part02]"><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="ClassDiagram" border="0" alt="ClassDiagram" src="http://raffaeu.com/wp-content/uploads/2013/03/50bce218-58f4-4557-999d-cc87776227bbClassDiagram_thumb.png" width="420" height="292"></a></p>
<p>These are the most important piece of code that you may be interested in:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0670ad2f-6c4c-455b-8de2-148b4577bcb1" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Read-only collection Addresses</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #000000; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#ffffff"></span><span style="color:#cc7832">private</span><span style="color:#ffffff"> </span><span style="color:#6897bb">IList</span><span style="color:#ffffff">&lt;</span><span style="color:#ffc66d">Address</span><span style="color:#ffffff">&gt; addresses = </span><span style="color:#cc7832">new</span><span style="color:#ffffff"> </span><span style="color:#ffc66d">List</span><span style="color:#ffffff">&lt;</span><span style="color:#ffc66d">Address</span><span style="color:#ffffff">&gt;();</span></li>
<li style="background: #0c0c0c"> </li>
<li><span style="color:#ffffff"></span><span style="color:#cc7832">public</span><span style="color:#ffffff"> </span><span style="color:#6897bb">IEnumerable</span><span style="color:#ffffff">&lt;</span><span style="color:#ffc66d">Address</span><span style="color:#ffffff">&gt; Addresses</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">{</span></li>
<li>    <span style="color:#ffffff"></span><span style="color:#cc7832">get</span><span style="color:#ffffff"> { </span><span style="color:#cc7832">return</span><span style="color:#ffffff"> </span><span style="color:#cc7832">this</span><span style="color:#ffffff">.addresses; }</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">}</span></li>
<li> </li>
<li style="background: #0c0c0c"><span style="color:#ffffff"></span><span style="color:#cc7832">public</span><span style="color:#ffffff"> </span><span style="color:#cc7832">void</span><span style="color:#ffffff"> AddAddress(</span><span style="color:#ffc66d">Address</span><span style="color:#ffffff"> address)</span></li>
<li><span style="color:#ffffff">{</span></li>
<li style="background: #0c0c0c">    <span style="color:#ffffff"></span><span style="color:#cc7832">if</span><span style="color:#ffffff"> (</span><span style="color:#cc7832">this</span><span style="color:#ffffff">.addresses.Contains(address))</span></li>
<li>    <span style="color:#ffffff">{</span></li>
<li style="background: #0c0c0c">        <span style="color:#ffffff"></span><span style="color:#cc7832">throw</span><span style="color:#ffffff"> </span><span style="color:#cc7832">new</span><span style="color:#ffffff"> </span><span style="color:#ffc66d">InvalidOperationException</span><span style="color:#ffffff">(</span><span style="color:#a5c25c">&#8220;The address is already in the collection.&#8221;</span><span style="color:#ffffff">);</span></li>
<li>    <span style="color:#ffffff">}</span></li>
<li style="background: #0c0c0c">    <span style="color:#ffffff"></span><span style="color:#cc7832">this</span><span style="color:#ffffff">.addresses.Add(address);</span></li>
<li><span style="color:#ffffff">}</span></li>
<li style="background: #0c0c0c"> </li>
<li><span style="color:#ffffff"></span><span style="color:#cc7832">public</span><span style="color:#ffffff"> </span><span style="color:#cc7832">void</span><span style="color:#ffffff"> RemoveAddress(</span><span style="color:#ffc66d">Address</span><span style="color:#ffffff"> address)</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">{</span></li>
<li>    <span style="color:#ffffff"></span><span style="color:#cc7832">if</span><span style="color:#ffffff"> (!</span><span style="color:#cc7832">this</span><span style="color:#ffffff">.addresses.Contains(address))</span></li>
<li style="background: #0c0c0c">    <span style="color:#ffffff">{</span></li>
<li>        <span style="color:#ffffff"></span><span style="color:#cc7832">throw</span><span style="color:#ffffff"> </span><span style="color:#cc7832">new</span><span style="color:#ffffff"> </span><span style="color:#ffc66d">InvalidOperationException</span><span style="color:#ffffff">(</span><span style="color:#a5c25c">&#8220;The address is not in the collection.&#8221;</span><span style="color:#ffffff">);</span></li>
<li style="background: #0c0c0c">    <span style="color:#ffffff">}</span></li>
<li>    <span style="color:#ffffff"></span><span style="color:#cc7832">this</span><span style="color:#ffffff">.addresses.Add(address);</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">}</span></li>
</ol></div>
</p></div>
</p></div>
<p>and</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e93a584f-920b-4a56-8d5f-3c7c7ea1b07a" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Constructor of an Address obj</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #000000; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li><span style="color:#ffffff"></span><span style="color:#cc7832">public</span><span style="color:#ffffff"> Address(</span><span style="color:#ffc66d">Person</span><span style="color:#ffffff"> person)</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">{</span></li>
<li>    <span style="color:#ffffff">Person = person;</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">}</span></li>
<li> </li>
<li style="background: #0c0c0c"><span style="color:#ffffff"></span><span style="color:#cc7832">public</span><span style="color:#ffffff"> </span><span style="color:#ffc66d">Person</span><span style="color:#ffffff"> Person { </span><span style="color:#cc7832">get</span><span style="color:#ffffff">; </span><span style="color:#cc7832">private</span><span style="color:#ffffff"> </span><span style="color:#cc7832">set</span><span style="color:#ffffff">; }</span></li>
</ol></div>
</p></div>
</p></div>
<p>As you can see we have few things that need to be tested but in order to do that we have to create new instances of these objects in order to run our tests, which is pretty <strong>verbose</strong> and <strong>boring</strong> …</p>
<h2>Create the test project</h2>
<p>The first step is to create a new Visual Studio 2010 Visual C# class library project and call it <strong>TypeMockDemo.Fixture</strong> and add the following references to it:</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/56c66638-2e69-48ef-8822-f476c4673195image_2.png" rel="lightbox[part02]"><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="image" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/44aeceac-b4af-43b6-9f51-06d5f2170c01image_thumb.png" width="244" height="260"></a></p>
<p>The references are pointing to:</p>
<ul>
<li>my TDD framework nUnit (you can work with any TDD framework but I personally found nUnit to be the best out there …)</li>
<li>TypeMock assemblies, installed in the GAC of your machine</li>
<li>The TypeMockDemo project (the one we have the domain entities in)</li>
</ul>
<p>Now we can start to create the first class fixture and verify that we can create a new Person, a new Employee and a new Customer. But <strong>hold on a second!</strong> How can we mock an abstract and two sealed class with a mocking framework? We simply can’t <em>if we are not using TypeMock … <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://raffaeu.com/wp-content/uploads/2013/03/fb39f43a-4d46-45e4-aad4-8191e69d4557wlEmoticon-winkingsmile_2.png"></em></p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c7c837bc-b77c-4224-b2da-49766df8eb76" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Create new abstract and Sealed</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #000000; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#ffffff">[</span><span style="color:#ffc66d">Test</span><span style="color:#ffffff">]</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">[</span><span style="color:#ffc66d">Category</span><span style="color:#ffffff">(</span><span style="color:#a5c25c">"Domain.Isolated"</span><span style="color:#ffffff">)]</span></li>
<li><span style="color:#ffffff"></span><span style="color:#cc7832">public</span><span style="color:#ffffff"> </span><span style="color:#cc7832">void</span><span style="color:#ffffff"> AssertThatCanCreateANewPerson()</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">{</span></li>
<li>    <span style="color:#ffffff"></span><span style="color:#ffc66d">Person</span><span style="color:#ffffff"> person = </span><span style="color:#ffc66d">Isolate</span><span style="color:#ffffff">.Fake.Instance&lt;</span><span style="color:#ffc66d">Person</span><span style="color:#ffffff">&gt;();</span></li>
<li style="background: #0c0c0c">    <span style="color:#ffffff"></span><span style="color:#ffc66d">Assert</span><span style="color:#ffffff">.That(person, </span><span style="color:#ffc66d">Is</span><span style="color:#ffffff">.Not.Null);</span></li>
<li><span style="color:#ffffff">}</span></li>
<li style="background: #0c0c0c"> </li>
<li><span style="color:#ffffff">[</span><span style="color:#ffc66d">Test</span><span style="color:#ffffff">]</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">[</span><span style="color:#ffc66d">Category</span><span style="color:#ffffff">(</span><span style="color:#a5c25c">"Domain.Isolated"</span><span style="color:#ffffff">)]</span></li>
<li><span style="color:#ffffff"></span><span style="color:#cc7832">public</span><span style="color:#ffffff"> </span><span style="color:#cc7832">void</span><span style="color:#ffffff"> AssertThatCanCreateANewEmployee()</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">{</span></li>
<li>    <span style="color:#ffffff"></span><span style="color:#ffc66d">Person</span><span style="color:#ffffff"> person = </span><span style="color:#ffc66d">Isolate</span><span style="color:#ffffff">.Fake.Instance&lt;</span><span style="color:#ffc66d">Employee</span><span style="color:#ffffff">&gt;();</span></li>
<li style="background: #0c0c0c">    <span style="color:#ffffff"></span><span style="color:#ffc66d">Assert</span><span style="color:#ffffff">.That(person, </span><span style="color:#ffc66d">Is</span><span style="color:#ffffff">.Not.Null);</span></li>
<li><span style="color:#ffffff">}</span></li>
<li style="background: #0c0c0c"> </li>
<li><span style="color:#ffffff">[</span><span style="color:#ffc66d">Test</span><span style="color:#ffffff">]</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">[</span><span style="color:#ffc66d">Category</span><span style="color:#ffffff">(</span><span style="color:#a5c25c">"Domain.Isolated"</span><span style="color:#ffffff">)]</span></li>
<li><span style="color:#ffffff"></span><span style="color:#cc7832">public</span><span style="color:#ffffff"> </span><span style="color:#cc7832">void</span><span style="color:#ffffff"> AssertThatCanCreateANewCustomer()</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">{</span></li>
<li>    <span style="color:#ffffff"></span><span style="color:#ffc66d">Person</span><span style="color:#ffffff"> person = </span><span style="color:#ffc66d">Isolate</span><span style="color:#ffffff">.Fake.Instance&lt;</span><span style="color:#ffc66d">Customer</span><span style="color:#ffffff">&gt;();</span></li>
<li style="background: #0c0c0c">    <span style="color:#ffffff"></span><span style="color:#ffc66d">Assert</span><span style="color:#ffffff">.That(person, </span><span style="color:#ffc66d">Is</span><span style="color:#ffffff">.Not.Null);</span></li>
<li><span style="color:#ffffff">}</span></li>
</ol></div>
</p></div>
</p></div>
<p>Looking at the code we have introduced the new method <strong>Isolate.Fake.Instance&lt;T&gt;</strong> that is coming from TypeMock. With this method we can simply inform TypeMock that we want it will create for us a <strong>Proxy of the object we want to mock</strong> and it will return a derived class of the tested one, <strong>even if we are mocking a sealed class</strong>.</p>
<p>If the class is sealed TypeMock will create a new instance of the original object while if the object is abstract, TypeMock will create a proxy version of that object. Same thing will be done for all the child properties, complex or not …</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/913bdef2-3b28-4efa-a508-29d04966dff4image_4.png" rel="lightbox[part02]"><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="image" border="0" alt="image" src="http://raffaeu.com/wp-content/uploads/2013/03/37a7c4e4-f12f-4923-8bb5-b509cc07851dimage_thumb_1.png" width="420" height="163"></a></p>
<p>That’s simply <strong>wow</strong>, we just used two lines of code to create a mockup and test it.</p>
<p>Now let’s move forward and let’s verify that we will not be able to add the same address twice and to remove the same address twice from a Person object.</p>
<h2>Working with Instances or Proxy?</h2>
<p>First of all we start to create this simple test but the result is not the one we expect … </p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:20c172ff-a4df-4603-a19d-dc40d2650852" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Test a collection</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #000000; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#ffffff">[</span><span style="color:#ffc66d">Test</span><span style="color:#ffffff">]</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">[</span><span style="color:#ffc66d">Category</span><span style="color:#ffffff">(</span><span style="color:#a5c25c">"Domain.Isolated"</span><span style="color:#ffffff">)]</span></li>
<li><span style="color:#ffffff"></span><span style="color:#cc7832">public</span><span style="color:#ffffff"> </span><span style="color:#cc7832">void</span><span style="color:#ffffff"> AssertThatCanAddTheSameAddressTwice()</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">{</span></li>
<li>    <span style="color:#ffffff"></span><span style="color:#ffc66d">Person</span><span style="color:#ffffff"> person = </span><span style="color:#ffc66d">Isolate</span><span style="color:#ffffff">.Fake.Instance&lt;</span><span style="color:#ffc66d">Person</span><span style="color:#ffffff">&gt;();</span></li>
<li style="background: #0c0c0c">    <span style="color:#ffffff"></span><span style="color:#ffc66d">Address</span><span style="color:#ffffff"> address = </span><span style="color:#ffc66d">Isolate</span><span style="color:#ffffff">.Fake.Instance&lt;</span><span style="color:#ffc66d">Address</span><span style="color:#ffffff">&gt;();</span></li>
<li>    <span style="color:#ffffff">person.AddAddress(address);</span></li>
<li style="background: #0c0c0c">    <span style="color:#ffffff"></span><span style="color:#ffc66d">Assert</span><span style="color:#ffffff">.That(person.Addresses.Count(), </span><span style="color:#ffc66d">Is</span><span style="color:#ffffff">.EqualTo(</span><span style="color:#6897bb">1</span><span style="color:#ffffff">));</span></li>
<li>    <span style="color:#ffffff"></span><span style="color:#ffc66d">Assert</span><span style="color:#ffffff">.Throws&lt;</span><span style="color:#ffc66d">InvalidOperationException</span><span style="color:#ffffff">&gt;(() =&gt; person.AddAddress(address));</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">}</span></li>
</ol></div>
</p></div>
</p></div>
<p>nUnit bombs saying that at line 8 the expected result is supposed to be 1 but in reality is 0. Why? This happens because TypeMock has created a full mockup proxy of the person object so also the methods AddAddress and RemoveAddress are mocks and they do not point to the real code we have implemented …</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:de815cd7-9a0d-4757-8662-3c16e300f808" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Control the creation</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #000000; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#ffffff">[</span><span style="color:#ffc66d">Test</span><span style="color:#ffffff">]</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">[</span><span style="color:#ffc66d">Category</span><span style="color:#ffffff">(</span><span style="color:#a5c25c">"Domain.Isolated"</span><span style="color:#ffffff">)]</span></li>
<li><span style="color:#ffffff"></span><span style="color:#cc7832">public</span><span style="color:#ffffff"> </span><span style="color:#cc7832">void</span><span style="color:#ffffff"> AssertThatCanAddTheSameAddressTwice()</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">{</span></li>
<li>    <span style="color:#ffffff"></span><span style="color:#ffc66d">Person</span><span style="color:#ffffff"> person = </span><span style="color:#ffc66d">Isolate</span><span style="color:#ffffff">.Fake.Instance&lt;</span><span style="color:#ffc66d">Person</span><span style="color:#ffffff">&gt;(</span><span style="color:#6897bb">Members</span><span style="color:#ffffff">.CallOriginal, </span><span style="color:#6897bb">ConstructorWillBe</span><span style="color:#ffffff">.Called);</span></li>
<li style="background: #0c0c0c">    <span style="color:#ffffff"></span><span style="color:#ffc66d">Address</span><span style="color:#ffffff"> address = </span><span style="color:#ffc66d">Isolate</span><span style="color:#ffffff">.Fake.Instance&lt;</span><span style="color:#ffc66d">Address</span><span style="color:#ffffff">&gt;();</span></li>
<li>    <span style="color:#ffffff">person.AddAddress(address);</span></li>
<li style="background: #0c0c0c">    <span style="color:#ffffff"></span><span style="color:#ffc66d">Assert</span><span style="color:#ffffff">.That(person.Addresses.Count(), </span><span style="color:#ffc66d">Is</span><span style="color:#ffffff">.EqualTo(</span><span style="color:#6897bb">1</span><span style="color:#ffffff">));</span></li>
<li>    <span style="color:#ffffff"></span><span style="color:#ffc66d">Assert</span><span style="color:#ffffff">.Throws&lt;</span><span style="color:#ffc66d">InvalidOperationException</span><span style="color:#ffffff">&gt;(() =&gt; person.AddAddress(address));</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">}</span></li>
</ol></div>
</p></div>
</p></div>
<p>If we change the way TypeMock is creating the object Person, we can now say to it:</p>
<p>“<strong><em>Dear TypeMock, I want that you create an instance of my object and that you call its constructor so that I can test the code I have implemented in this abstract class …</em></strong>”</p>
<p>Et voila’, the test will pass! Same thing for the remove address and so on …</p>
<p>Now, the last test we may require is that we want to be sure that when we create a new address, the constructor is properly injecting the parent Person object so that we can keep a back-forward reference from the parent object and the collection of children.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:40df3ac7-2e44-4b2e-a0b0-e9dbb29f9d91" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Test injection in constructor</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #000000; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#ffffff">[</span><span style="color:#ffc66d">Test</span><span style="color:#ffffff">]</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">[</span><span style="color:#ffc66d">Category</span><span style="color:#ffffff">(</span><span style="color:#a5c25c">"Domain.Isolated"</span><span style="color:#ffffff">)]</span></li>
<li><span style="color:#ffffff"></span><span style="color:#cc7832">public</span><span style="color:#ffffff"> </span><span style="color:#cc7832">void</span><span style="color:#ffffff"> AssertThatWhenCreateAnAddressTheParentPersonIsInjected()</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">{</span></li>
<li>    <span style="color:#ffffff"></span><span style="color:#ffc66d">Person</span><span style="color:#ffffff"> person = </span><span style="color:#ffc66d">Isolate</span><span style="color:#ffffff">.Fake.Instance&lt;</span><span style="color:#ffc66d">Person</span><span style="color:#ffffff">&gt;(</span><span style="color:#6897bb">Members</span><span style="color:#ffffff">.CallOriginal, </span><span style="color:#6897bb">ConstructorWillBe</span><span style="color:#ffffff">.Called);</span></li>
<li style="background: #0c0c0c">    <span style="color:#ffffff"></span><span style="color:#ffc66d">Address</span><span style="color:#ffffff"> address = </span><span style="color:#ffc66d">Isolate</span><span style="color:#ffffff">.Fake.Instance&lt;</span><span style="color:#ffc66d">Address</span><span style="color:#ffffff">&gt;();</span></li>
<li>    <span style="color:#ffffff"></span><span style="color:#ffc66d">Assert</span><span style="color:#ffffff">.That(person, </span><span style="color:#ffc66d">Is</span><span style="color:#ffffff">.Not.Null);</span></li>
<li style="background: #0c0c0c">    <span style="color:#ffffff"></span><span style="color:#ffc66d">Assert</span><span style="color:#ffffff">.That(address, </span><span style="color:#ffc66d">Is</span><span style="color:#ffffff">.Not.Null);</span></li>
<li>    <span style="color:#ffffff"></span><span style="color:#ffc66d">Assert</span><span style="color:#ffffff">.That(address, </span><span style="color:#ffc66d">Has</span><span style="color:#ffffff">.Property(</span><span style="color:#a5c25c">&#8220;Person&#8221;</span><span style="color:#ffffff">).EqualTo(person));</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">}</span></li>
</ol></div>
</p></div>
</p></div>
<p>We run the test and kabum! It fails again. This time it fails on the address side because the <strong>Person</strong> instance TypeMock is injecting is not the same it returned to use in the previous line of code. So what can we do now?</p>
<p>We can manually create an Address and inject the parent Person but it sucks … or we can do this:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e31a1af5-a8c2-4c43-8be2-9ba621b1db9f" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Customize constructor</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #000000; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#ffffff">[</span><span style="color:#ffc66d">Test</span><span style="color:#ffffff">]</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">[</span><span style="color:#ffc66d">Category</span><span style="color:#ffffff">(</span><span style="color:#a5c25c">"Domain.Isolated"</span><span style="color:#ffffff">)]</span></li>
<li><span style="color:#ffffff"></span><span style="color:#cc7832">public</span><span style="color:#ffffff"> </span><span style="color:#cc7832">void</span><span style="color:#ffffff"> AssertThatWhenCreateAnAddressTheParentPersonIsInjected()</span></li>
<li style="background: #0c0c0c"><span style="color:#ffffff">{</span></li>
<li>    <span style="color:#ffffff"></span><span style="color:#ffc66d">Person</span><span style="color:#ffffff"> person = </span><span style="color:#ffc66d">Isolate</span><span style="color:#ffffff">.Fake.Instance&lt;</span><span style="color:#ffc66d">Person</span><span style="color:#ffffff">&gt;(</span><span style="color:#6897bb">Members</span><span style="color:#ffffff">.CallOriginal, </span><span style="color:#6897bb">ConstructorWillBe</span><span style="color:#ffffff">.Called);</span></li>
<li style="background: #0c0c0c">    <span style="color:#ffffff"></span><span style="color:#ffc66d">Address</span><span style="color:#ffffff"> address = </span><span style="color:#ffc66d">Isolate</span><span style="color:#ffffff">.Fake.Instance&lt;</span><span style="color:#ffc66d">Address</span><span style="color:#ffffff">&gt;(</span><span style="color:#6897bb">Members</span><span style="color:#ffffff">.CallOriginal, </span><span style="color:#6897bb">ConstructorWillBe</span><span style="color:#ffffff">.Called, person);</span></li>
<li>    <span style="color:#ffffff"></span></li>
<li style="background: #0c0c0c">    <span style="color:#ffffff"></span><span style="color:#ffc66d">Assert</span><span style="color:#ffffff">.That(person, </span><span style="color:#ffc66d">Is</span><span style="color:#ffffff">.Not.Null);</span></li>
<li>    <span style="color:#ffffff"></span><span style="color:#ffc66d">Assert</span><span style="color:#ffffff">.That(address, </span><span style="color:#ffc66d">Is</span><span style="color:#ffffff">.Not.Null);</span></li>
<li style="background: #0c0c0c">    <span style="color:#ffffff"></span><span style="color:#ffc66d">Assert</span><span style="color:#ffffff">.That(address, </span><span style="color:#ffc66d">Has</span><span style="color:#ffffff">.Property(</span><span style="color:#a5c25c">&#8220;Person&#8221;</span><span style="color:#ffffff">).EqualTo(person));</span></li>
<li><span style="color:#ffffff">}</span></li>
</ol></div>
</p></div>
</p></div>
<p> </p>
<p>We simply inject the person value we want to use (the one created by TypeMock) because this is what it is going to happen with live code. What we care here is to be sure that inside the Address class constructor, the Person parameter is passed to the read-only property Person of the Address class, nothing more, nothing less!</p>
<h2>Conclusion</h2>
<p>As you can see, TypeMock is pretty cool and it allows you to control the way we can create and fake objects. Even if we use proxies we can still ask to TypeMock to create a real mock that reflect our code so that we can still test the business logic included in our objects without the need of creating complex objects manually.</p>
<p>If you want to read more about this topic I kindly suggest you this:</p>
<ul>
<li><a href="http://docs.typemock.com/Isolator/#%23typemock.chm/Documentation/CreatingFakesWithAAA.html" target="_blank">Faking instances of an object</a></li>
<li><a href="http://docs.typemock.com/Isolator/#%23typemock.chm/Documentation/ConstructorArgumentsAAA.html" target="_blank">Handling object constructor</a></li>
</ul>
<p>In the next tutorial we will see how to customize the methods and other behaviors of an object and I will also publish the first part of the quiz that will allow you to win almost 1,000 USD value of TypeMock license!</p>
<p>Stay tuned</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=u-RRN9ROLvc:XlmSiFxkICU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=u-RRN9ROLvc:XlmSiFxkICU:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=u-RRN9ROLvc:XlmSiFxkICU:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=u-RRN9ROLvc:XlmSiFxkICU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=u-RRN9ROLvc:XlmSiFxkICU:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=u-RRN9ROLvc:XlmSiFxkICU:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=u-RRN9ROLvc:XlmSiFxkICU:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/u-RRN9ROLvc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.raffaeu.com/archive/2011/06/25/typemock-tutorial-02-object-creation.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.raffaeu.com/archive/2011/06/25/typemock-tutorial-02-object-creation.aspx</feedburner:origLink></item>
		<item>
		<title>A Devil in the house …</title>
		<link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/_mpWJ-qzhhc/a-devil-in-the-house.aspx</link>
		<comments>http://blog.raffaeu.com/archive/2011/06/19/a-devil-in-the-house.aspx#comments</comments>
		<pubDate>Sun, 19 Jun 2011 18:59:08 +0000</pubDate>
		<dc:creator>raffaeu</dc:creator>
				<category><![CDATA[Private]]></category>

		<guid isPermaLink="false">http://raffaeu.com/?p=107</guid>
		<description><![CDATA[Just a little OT to keep you up to date also about my private life (if anyone of you cares … ). Last Friday we got a new member in our family, after we lost our precious Doberman after 10 years, we decided to move forward and forget the drama by getting a new dog. <span class="ellipsis">&#8230;</span> <span class="more-link-wrap"><a href="http://blog.raffaeu.com/archive/2011/06/19/a-devil-in-the-house.aspx" class="more-link"><span>Read More &#8594;</span></a></span>]]></description>
				<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_button">
										<a name="fcbk_share"	href="http://www.facebook.com/raffaeu"	target="blank">
											<img src="http://blog.raffaeu.com/wp-content/plugins/facebook-button-plugin/img/standart-facebook-ico.jpg" alt="Fb-Button" />
										</a>	
									</div><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://blog.raffaeu.com/archive/2011/06/19/a-devil-in-the-house.aspx" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>Just a little OT to keep you up to date also about my private life (if anyone of you cares … <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://raffaeu.com/wp-content/uploads/2013/03/fd1c585b-3684-4051-9c5f-d68f30a656a8wlEmoticon-winkingsmile_2.png">).</p>
<p>Last Friday we got a new member in our family, after we lost our precious Doberman after 10 years, we decided to move forward and forget the drama by getting a new dog. This time we bought a <a href="http://www.jack-russell-terrier.co.uk/" target="_blank">Jack Russell Terrier</a> … what a Devil!</p>
<p>Her name is Sophie, she is now 3 months old and she is the alpha of her litter … so a little bit a “devil dog”. Really energetic and with a strong character! A nice challenge for me and my wife.</p>
<p>The first thing we want to teach her is to jump on a surf board and surf! I will publish a video of her soon.</p>
<p>For now, enjoy this:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:66721397-FF69-4ca6-AEC4-17E6B3208830:6aaca974-d303-4af4-9d47-844a58451339" class="wlWriterEditableSmartContent">
<table border="0" cellspacing="0" cellpadding="0" style="outline:none;border-style:none;margin:0px;padding:0px;width:410px;border-collapse:collapse;">
<tbody>
<tr>
<td style="margin:0px;padding:0px;outline:none;border-style:none;width:auto"><a style="outline:none;border-style:none;margin:0px;padding:0px;" target="_blank" href="https://cid-ada7c80f0c2f057b.skydrive.live.com/redir.aspx?page=play&amp;resid=ADA7C80F0C2F057B!266&amp;type=5&amp;authkey=aNHTc7Bamz4%24&amp;Bsrc=Photomail&amp;Bpub=SDX.Photos"><img style="outline:none;border-style:none;padding:0px;margin:0px;border:0px;background:none;background-image:none;vertical-align:bottom;" alt="View album" title="View album" src="http://raffaeu.com/wp-content/uploads/2013/03/7f8a8868-2b8e-4b6e-a2db-cf949db5f640Sophie%20little%20devil.jpg"></a>
<div style="width:410px;text-align:center;overflow:visible;padding:0px;margin:0px;">
<div style="width:410px;overflow:visible;"><a style="text-decoration:none;" href="https://cid-ada7c80f0c2f057b.skydrive.live.com/redir.aspx?page=browse&amp;resid=ADA7C80F0C2F057B!266&amp;type=5&amp;authkey=aNHTc7Bamz4%24&amp;Bsrc=Photomail&amp;Bpub=SDX.Photos" target="_blank"><span style="line-height:1.26em;padding:0px;width:410px;font-size:26pt;font-family:'Segoe UI', helvetica, arial, sans-serif;" defaulttext="Enter album name here">Sophie (little devil)</span></a></div>
<div style="text-align:center;padding:9px 0px 0px 0px;margin:0px 0px 0px 0px;font-family:'Segoe UI', helvetica, arial, sans-serif;font-size:8pt;">
<table border="0" cellspacing="0" cellpadding="0" style="text-align:center;width:auto;margin-left:auto;margin-right:auto;padding:0px;outline:none;border-style:none;border-collapse:collapse;">
<tr>
<td style="vertical-align:top;outline:none;border-style:none;margin:0px;padding:6px 12px 6px 0px;"><a href="https://cid-ada7c80f0c2f057b.skydrive.live.com/redir.aspx?page=play&amp;resid=ADA7C80F0C2F057B!266&amp;type=5&amp;authkey=aNHTc7Bamz4%24&amp;Bsrc=Photomail&amp;Bpub=SDX.Photos" border="0" target="_blank" style="font-family:'Segoe UI', helvetica, arial, sans-serif;font-size:8pt;outline:none;border-style:none;text-decoration: none;padding:0px;margin:0px;">VIEW SLIDE SHOW</a></td>
<td style="vertical-align:top;outline:none;border-style:none;margin:0px;padding:6px 0px 6px 0px;"><a href="https://cid-ada7c80f0c2f057b.skydrive.live.com/redir.aspx?page=downloadphotos&amp;resid=ADA7C80F0C2F057B!266&amp;type=5&amp;Bsrc=Photomail&amp;Bpub=SDX.Photos&amp;authkey=aNHTc7Bamz4%24" border="0" target="_blank" style="font-family:'Segoe UI', helvetica, arial, sans-serif;font-size:8pt;outline:none;border-style:none;text-decoration: none;padding:0px;margin:0px;">DOWNLOAD ALL</a></td>
</tr>
</table></div>
</p></div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=_mpWJ-qzhhc:J1V4A0H0fQ4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=_mpWJ-qzhhc:J1V4A0H0fQ4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=_mpWJ-qzhhc:J1V4A0H0fQ4:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=_mpWJ-qzhhc:J1V4A0H0fQ4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=_mpWJ-qzhhc:J1V4A0H0fQ4:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=_mpWJ-qzhhc:J1V4A0H0fQ4:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=_mpWJ-qzhhc:J1V4A0H0fQ4:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/_mpWJ-qzhhc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.raffaeu.com/archive/2011/06/19/a-devil-in-the-house.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.raffaeu.com/archive/2011/06/19/a-devil-in-the-house.aspx</feedburner:origLink></item>
		<item>
		<title>TypeMock tutorial #01. Startup.</title>
		<link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/1JDvzphbjfc/typemock-tutorial-01-startup.aspx</link>
		<comments>http://blog.raffaeu.com/archive/2011/06/19/typemock-tutorial-01-startup.aspx#comments</comments>
		<pubDate>Sun, 19 Jun 2011 18:48:47 +0000</pubDate>
		<dc:creator>raffaeu</dc:creator>
				<category><![CDATA[ALT]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[TypeMock]]></category>

		<guid isPermaLink="false">http://raffaeu.com/?p=114</guid>
		<description><![CDATA[The best way to learn a tool is to try it, test it and then finally use it over your code. Of course if the tool provides also a great community support and a great documentation the task will be easier. Some weeks ago we started to adopt a wonderful tool to create mockups and <span class="ellipsis">&#8230;</span> <span class="more-link-wrap"><a href="http://blog.raffaeu.com/archive/2011/06/19/typemock-tutorial-01-startup.aspx" class="more-link"><span>Read More &#8594;</span></a></span>]]></description>
				<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_button">
										<a name="fcbk_share"	href="http://www.facebook.com/raffaeu"	target="blank">
											<img src="http://blog.raffaeu.com/wp-content/plugins/facebook-button-plugin/img/standart-facebook-ico.jpg" alt="Fb-Button" />
										</a>	
									</div><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://blog.raffaeu.com/archive/2011/06/19/typemock-tutorial-01-startup.aspx" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>The best way to learn a tool is to try it, test it and then finally use it over your code. Of course if the tool provides also a great community support and a great documentation the task will be easier.</p>
<p>Some weeks ago we started to adopt a wonderful tool to create mockups and other TDD fancy stuff, the tool is <a href="http://www.typemock.com" target="_blank">TypeMock</a>.</p>
<p>The idea I got is to create a series of tutorials about <a href="http://www.typemock.com" target="_blank">TypeMock</a> and provide to you a piece of a code to download a full license of this tool. At the end of the series (probably 1 month) you will be able to enable your 10 days trial into a full working license. I will create a sort of bid and from all my readers that will contact me to get the license I will come up with one or two free licenses.</p>
<p><strong>Guys, consider that one license of TypeMock is 800 $ !! </strong></p>
<h2><font color="#2e2e2e">Setup and Installation</font></h2>
<p><font color="#2e2e2e">In order to start right away with TypeMock you need to download the latest version of the tool (at this time they have the version 6.0.10) but be careful because they upload new versions often. The product you need to download for .NET is <a href="http://www.typemock.com/isolator-product-page" target="_blank">Isolator.NET</a>. They also provide additional tools that we will analyze during this series, like:</font></p>
<ul>
<li><font color="#2e2e2e">TestDriven.NET, an integrated test runner for Visual Studio</font> </li>
<li><font color="#2e2e2e">Isolator for Sharepoint</font> </li>
<li><font color="#2e2e2e">Isolator for ASP.NET and ASP.NET MVC</font> </li>
<li><font color="#2e2e2e">TeamMate, a useful tool to monitor your TDD approach</font> </li>
<li><font color="#2e2e2e">Isolator ++, the same version but for C++</font> </li>
<li><font color="#2e2e2e">TestLint, a nice tool that will help you to develop your TDD skill</font> </li>
</ul>
<p><font color="#2e2e2e">and more.</font></p>
<p><font color="#2e2e2e">After you have downloaded the setup (7 Mb) you will have to follow a very straightforward setup wizard with only two options available; use the advanced option and install everything including the samples for .NET.</font></p>
<p><font color="#2e2e2e">That’s it, you are now ready to go!</font></p>
<h2><font color="#2e2e2e">File Location</font></h2>
<p><font color="#2e2e2e"><a href="http://www.typemock.com" target="_blank">TypeMock</a> is installed on your C:\ drive and depending on where you choose to install it, you should have a folder called TypeMock/Isolator/6.0 on your Program Files directory. Inside this folder you can find all the <strong>assemblies </strong>available from <a href="http://www.typemock.com" target="_blank">TypeMock</a>.</font></p>
<p><font color="#2e2e2e">You do not need to use them directly as <a href="http://www.typemock.com" target="_blank">TypeMock</a> is also installed on your GAC folder but if you plan to work with C.I. (<a href="http://martinfowler.com/articles/continuousIntegration.html" target="_blank">Continuous Integration</a>) you may probably need to add a reference to these files instead of pointing directly to the GAC, depending on what type of build server you are working with … <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://raffaeu.com/wp-content/uploads/2013/03/f0838511-0549-4876-a881-3aef8bab45e4wlEmoticon-winkingsmile_2.png"></font></p>
<p><font color="#2e2e2e">Inside the folder Examples you will find a set of useful examples to start to learn TypeMock quickly but do not worry as I will go through all these examples in this series. </font></p>
<p><font color="#2e2e2e">If you want to make your experience with TypeMock easier and smoother, I kindly suggest you to download and install also TestDriven.NET or <a href="http://www.jetbrains.com/resharper/" target="_blank">Resharper</a> with <a href="http://www.gallio.org/" target="_blank">Gallio</a>. I personally use and love Resharper so you will find in this series all the reference examples pointing to the Resharper UI inside Visual Studio. The choice is up to you but I personally believe R# is the best tool so far for Visual Studio (IMHO)</font></p>
<h2>Visual Studio integration</h2>
<p>After the installation you can open Visual Studio and this is the surprise you will find in the IDE:</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/c6d99adc-d002-4db0-8098-5c82ed17ae31Screen%20shot%202011-06-13%20at%2011.56.00%20PM_2.png" rel="lightbox[Tutorial01]"><img style="background-image: none; border-right-width: 0px; margin: 0px 8px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Screen shot 2011-06-13 at 11.56.00 PM" border="0" alt="Screen shot 2011-06-13 at 11.56.00 PM" align="left" src="http://raffaeu.com/wp-content/uploads/2013/03/9e0378c8-7d6b-4cfb-8806-820ea4ea1178Screen%20shot%202011-06-13%20at%2011.56.00%20PM_thumb.png" width="260" height="198"></a> You will find a new menu on Visual Studio called TypeMock; in this menu you can setup the license, the profiler to use with TypeMock and few other options for a better Visual Studio experience.</p>
<p>There aren’t a lot of other ways to easily configure TypeMock but we will see together how you can tackle each of the common tasks you may encounter while working with TypeMock.</p>
<p>From this menu you have also the easy option of enabling/disabling TypeMock at anytime so that you can or cannot work with it without the need to restarting Visual Studio every time (like you have to do with other plugins of Visual Studio).</p>
<h2>The Demo Project</h2>
<p>I have created a very small project for this series of tutorials to show you how you can test every single layer of a .NET application using TypeMock to separate the dependencies. The structure of the demo project is in the following way:</p>
<p><a href="http://raffaeu.com/wp-content/uploads/2013/03/fec3dce1-0174-4cdb-acaf-26d704cafb06Screen%20shot%202011-06-19%20at%204.26.58%20PM_2.png" rel="lightbox[Tutorial01]"><img style="background-image: none; border-right-width: 0px; margin: 0px 3px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Screen shot 2011-06-19 at 4.26.58 PM" border="0" alt="Screen shot 2011-06-19 at 4.26.58 PM" align="left" src="http://raffaeu.com/wp-content/uploads/2013/03/26181d70-4fb1-42fd-834c-f4673accbb9aScreen%20shot%202011-06-19%20at%204.26.58%20PM_thumb.png" width="251" height="260"></a></p>
<p>The project is composed by 4 different layers:</p>
<ol>
<li>TypeMockDemo: the project that contains the Domain Model of the tutorial</li>
<li>TypeMockDemo.DataLayer: a data layer built around NHibernate 3.2</li>
<li>TypeMockDemo.ServiceLayer: the service layer used to write the business logic around the domain and the data layer</li>
<li>TypeMockDemo.UserInterface: an application developed using WPF 4.</li>
</ol>
<p> </p>
<p> </p>
<p>For each project there is a corresponding “fixtures” project that includes all the fixtures related to the project. With fixture I mean “test” … <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://raffaeu.com/wp-content/uploads/2013/03/0c1a5626-a881-4b3c-8e55-dd17ac3248e5wlEmoticon-winkingsmile_2.png"></p>
<h2>Tutorials and resources</h2>
<p>Before starting to follow this series I kindly suggest you to have a look at the <a href="http://www.typemock.com" target="_blank">TypeMock</a> web site learning content, so that you will follow better my tutorials. As you know, I do not usually go too deep into a specific topic, so if you need to learn also what TDD is, I kindly suggest you to read also the following tutorials about TDD and testing in general.</p>
<p><strong><u>TypeMock learning content:</u></strong></p>
<ul>
<li>Introduction to TypeMock <a title="http://www.typemock.com/getting-started-step-1-set/" href="http://www.typemock.com/getting-started-step-1-set/">http://www.typemock.com/getting-started-step-1-set/</a></li>
<li>General articles and web casts <a title="http://www.typemock.com/general-unit-testing-pages/" href="http://www.typemock.com/general-unit-testing-pages/">http://www.typemock.com/general-unit-testing-pages/</a></li>
<li>TypeMock <a href="http://docs.typemock.com/racer/##RacerHelp.chm/html/4734a51a-c37e-4d7b-aa7e-836a34fa7e23.htm" target="_blank">documentation</a></li>
</ul>
<p><strong><u>TDD learning content:</u></strong></p>
<ul>
<li>TDD     <br /><a title="http://en.wikipedia.org/wiki/Test-driven_development" href="http://en.wikipedia.org/wiki/Test-driven_development">http://en.wikipedia.org/wiki/Test-driven_development</a>      <br /><a title="http://www.agiledata.org/essays/tdd.html" href="http://www.agiledata.org/essays/tdd.html">http://www.agiledata.org/essays/tdd.html</a></li>
<li>Tutorials     <br />This is a very complete introduction to TDD in .NET      <br /><a title="http://www.codeproject.com/KB/dotnet/tdd_in_dotnet.aspx" href="http://www.codeproject.com/KB/dotnet/tdd_in_dotnet.aspx">http://www.codeproject.com/KB/dotnet/tdd_in_dotnet.aspx</a></li>
</ul>
<p> </p>
<p>So stay tuned and I’ll see you next Friday for the next part of this series.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=1JDvzphbjfc:r_qQr7mSAZw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=1JDvzphbjfc:r_qQr7mSAZw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=1JDvzphbjfc:r_qQr7mSAZw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=1JDvzphbjfc:r_qQr7mSAZw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=1JDvzphbjfc:r_qQr7mSAZw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=1JDvzphbjfc:r_qQr7mSAZw:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=1JDvzphbjfc:r_qQr7mSAZw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/1JDvzphbjfc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.raffaeu.com/archive/2011/06/19/typemock-tutorial-01-startup.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.raffaeu.com/archive/2011/06/19/typemock-tutorial-01-startup.aspx</feedburner:origLink></item>
		<item>
		<title>New content for my Microsoft book</title>
		<link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/TWSuLA4Podo/new-content-for-my-microsoft-book.aspx</link>
		<comments>http://blog.raffaeu.com/archive/2011/06/12/new-content-for-my-microsoft-book.aspx#comments</comments>
		<pubDate>Sun, 12 Jun 2011 22:32:49 +0000</pubDate>
		<dc:creator>raffaeu</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Pattern]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[NET World]]></category>
		<category><![CDATA[Technical Documents]]></category>

		<guid isPermaLink="false">http://raffaeu.com/?p=116</guid>
		<description><![CDATA[The Microsoft’s book I have published few months ago: “Building Enterprise Applications with WPF and MVVM” has been a success but I still got some negative feedbacks that me and my editor we want to get rid off. This book is my first real book and of course it was my first experience on writing <span class="ellipsis">&#8230;</span> <span class="more-link-wrap"><a href="http://blog.raffaeu.com/archive/2011/06/12/new-content-for-my-microsoft-book.aspx" class="more-link"><span>Read More &#8594;</span></a></span>]]></description>
				<content:encoded><![CDATA[<div id="fcbk_share"><div class="fcbk_button">
										<a name="fcbk_share"	href="http://www.facebook.com/raffaeu"	target="blank">
											<img src="http://blog.raffaeu.com/wp-content/plugins/facebook-button-plugin/img/standart-facebook-ico.jpg" alt="Fb-Button" />
										</a>	
									</div><div class="fcbk_like">
										<div id="fb-root"></div>
										<script src="http://connect.facebook.net/en_US/all.js#appId=224313110927811&amp;xfbml=1"></script>
										<fb:like href="http://blog.raffaeu.com/archive/2011/06/12/new-content-for-my-microsoft-book.aspx" send="false" layout="button_count" width="450" show_faces="false" font=""></fb:like>
									</div></div><p>The Microsoft’s book I have published few months ago: “<a href="http://www.amazon.com/Enterprise-Applications-Presentation-Foundation-ViewModel/dp/0735650926/ref=sr_1_1?ie=UTF8&amp;qid=1307928213&amp;sr=8-1" target="_blank">Building Enterprise Applications with WPF and MVVM</a>” has been a success but I still got some negative feedbacks that me and my editor we want to get rid off.</p>
<p>This book is my first <strong>real</strong> book and of course it was my first experience on writing a book (for this reason we kept the price of the book very low). Anyway .. I got some bad feedbacks about missing parts, parts not explained as expected and a misunderstanding of the book audience and target.</p>
<p>I personally believe that the biggest problem is in the title of book, it drives you a little bit out of the topic of the book, if you buy this book you will believe to get the “bible to LOB applications with MVVM”, which is not.</p>
<p>For this reasons and also to keep high the audience of the book, we have decided to deliver <strong>for free</strong> new additional content for the book! <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-openmouthedsmile" alt="Open-mouthed smile" src="http://raffaeu.com/wp-content/uploads/2013/03/958381da-5f11-4cf3-9b47-b40ebf2ac029wlEmoticon-openmouthedsmile_2.png"></p>
<p>The list of the new content is still under discussion with my editor but this is a rough list of the topics I will touch or expand in this new context that should be composed by 3 additional chapters!</p>
<ul>
<li>Design patterns     <br />I am planning to add 20/30 additional pages on the second chapter in order to exhaustively cover everything related to the most known design patterns</li>
<li>Advanced MVVM     <br />I will add a new chapter where I will explain some “well known” problems you may find when the adoption of the MVVM pattern starts to get tricky!</li>
<li>Composite Frameworks for MVVM in practice     <br />In this chapter we will build the same Master-Detail UI logic using the three most famous frameworks for WPF/Silverlight: PRISM, Caliburn and Light Toolkit</li>
</ul>
<p>If you believe that the book is still missing other information, feel free to send me an e-mail and I will be glad to discuss this with my editor.</p>
<p><strong>Note: </strong>Remember also that we are planning to distribute the source code of the book as an Open Source project on Codeplex.com before the end of the year. </p>
<p>Hope this will help!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=TWSuLA4Podo:z8Zw7y6lBqU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=TWSuLA4Podo:z8Zw7y6lBqU:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=TWSuLA4Podo:z8Zw7y6lBqU:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=TWSuLA4Podo:z8Zw7y6lBqU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=TWSuLA4Podo:z8Zw7y6lBqU:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=TWSuLA4Podo:z8Zw7y6lBqU:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=TWSuLA4Podo:z8Zw7y6lBqU:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/TWSuLA4Podo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.raffaeu.com/archive/2011/06/12/new-content-for-my-microsoft-book.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.raffaeu.com/archive/2011/06/12/new-content-for-my-microsoft-book.aspx</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 13.391 seconds. --><!-- Cached page generated by WP-Super-Cache on 2013-05-21 06:50:32 -->
