<?xml version="1.0" encoding="utf-8"?>
<rss
 xmlns:dc="http://purl.org/dc/elements/1.1/"
 xmlns:content="http://purl.org/rss/1.0/modules/content/"
 version="2.0">
	<channel>
		<title>Nikos Baxevanis</title>
		<link>http://nikosbaxevanis.com</link>
		<description>(I should have written something here.)</description>
		<language>en-GB</language>
		
		<item>
			<title>The GitHub way of blog discussion and commenting</title>
			<link>http://nikosbaxevanis.com/2013/04/28/the-github-way-of-blog-discussion-and-commenting</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2013/04/28/the-github-way-of-blog-discussion-and-commenting</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Using the underlying power of &lt;a href=&quot;http://github.com/&quot;&gt;GitHub&lt;/a&gt;, blog authors often take a step further and roll their own discussion and commeting systems.&lt;/p&gt;

&lt;p&gt;The best examples are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://blog.ploeh.dk/2013/03/03/moving-the-blog-to-jekyll/&quot;&gt;Add a comment by sending a pull request&lt;/a&gt; by &lt;a href=&quot;http://blog.ploeh.dk/&quot;&gt;Mark Seemann&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://ivanzuzak.info/2011/02/18/github-hosted-comments-for-github-hosted-blogs.html&quot;&gt;Add a comment through the GitHub API&lt;/a&gt; by &lt;a href=&quot;http://ivanzuzak.info&quot;&gt;Ivan Zuzak&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/holman/feedback&quot;&gt;Add a comment as a GitHub issue&lt;/a&gt; by &lt;a href=&quot;http://zachholman.com/&quot;&gt;Zach Holman&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;With the evolution of blog-aware static site generators, like &lt;a href=&quot;http://jekyllrb.com/&quot;&gt;Jekyll&lt;/a&gt;, GitHub is becoming a central part for hosting both blog content and comments.&lt;/p&gt;
</description>
			<pubDate>Sun, 28 Apr 2013 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Hackers, Developers, Programmers</title>
			<link>http://nikosbaxevanis.com/2013/04/18/hackers-developers-programmers</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2013/04/18/hackers-developers-programmers</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;The definitions about Hackers, Developers, and Programmers, that I like best are:&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;&amp;ldquo;Hackers are generally loners who don&amp;rsquo;t care if others can figure out their code (at least while they are in the mode or role of hacking). Thus, they build their own little world in it that fits themselves nicely so that they can hack fast, but the rest of the world be damned.&amp;rdquo; &amp;mdash; &lt;em&gt;&lt;a href=&quot;http://c2.com/cgi/wiki?LispIsTooPowerful&quot;&gt;c2.com/wiki&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&amp;ldquo;On the &amp;lsquo;programmer&amp;rsquo; vs. &amp;lsquo;developer&amp;rsquo; debate: &amp;lsquo;Programmer&amp;rsquo; focuses on the &amp;lsquo;craft&amp;rsquo;. &amp;lsquo;Developer&amp;rsquo; focuses on the business. Both are valuable.&amp;rdquo; &amp;mdash; &lt;em&gt;&lt;a href=&quot;https://twitter.com/ploeh/status/297803382050140160&quot;&gt;@ploeh on twitter&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;I am a programmer &amp;mdash; You?&lt;/p&gt;
</description>
			<pubDate>Thu, 18 Apr 2013 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>xUnit.net Attributes Execution Order</title>
			<link>http://nikosbaxevanis.com/2013/03/10/xunit-net-attributes-execution-order</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2013/03/10/xunit-net-attributes-execution-order</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;The test below uses the &lt;a href=&quot;http://xunit.codeplex.com/&quot;&gt;xUnit.net&lt;/a&gt; framework and executes twice, since it is decorated with two data sources. The first data source is the built-in &lt;code&gt;[InlineData]&lt;/code&gt; and the second data source is the custom &lt;code&gt;[StringData]&lt;/code&gt;.&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Theory]
[InlineData(&amp;quot;foo&amp;quot;, &amp;quot;bar&amp;quot;)]
[StringData]
[Intercept]
public void Test(string a, string b)
{
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;xUnit.net invokes in exact order:&lt;/p&gt;

&lt;h3&gt;Initialization&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;[InlineData]&lt;/code&gt; consturctor&lt;/li&gt;
&lt;li&gt;&lt;code&gt;[StringData]&lt;/code&gt; consturctor&lt;/li&gt;
&lt;li&gt;&lt;code&gt;[InlineData]&lt;/code&gt; &lt;code&gt;IEnumerable&amp;lt;object[]&amp;gt; GetData(MethodInfo, Type[])&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;[StringData]&lt;/code&gt; &lt;code&gt;IEnumerable&amp;lt;object[]&amp;gt; GetData(MethodInfo, Type[])&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;h3&gt;1st Run&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;[Intercept]&lt;/code&gt; consturctor&lt;/li&gt;
&lt;li&gt;&lt;code&gt;[Intercept]&lt;/code&gt; &lt;code&gt;void Before(MethodInfo)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;[Theory]&lt;/code&gt; supplying values for &lt;em&gt;a&lt;/em&gt; and &lt;em&gt;b&lt;/em&gt; taken from either &lt;code&gt;[InlineData]&lt;/code&gt; or &lt;code&gt;[StringData]&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;[Intercept]&lt;/code&gt; &lt;code&gt;void After(MethodInfo)&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;h3&gt;2nd Run&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;[Intercept]&lt;/code&gt; .ctor&lt;/li&gt;
&lt;li&gt;&lt;code&gt;[Intercept]&lt;/code&gt; &lt;code&gt;void Before(MethodInfo)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;[Theory]&lt;/code&gt; supplying values for &lt;em&gt;a&lt;/em&gt; and &lt;em&gt;b&lt;/em&gt; taken from either &lt;code&gt;[InlineData]&lt;/code&gt; or &lt;code&gt;[StringData]&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;[Intercept]&lt;/code&gt; &lt;code&gt;void After(MethodInfo)&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;h2&gt;Remarks&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;[Intercept]&lt;/code&gt; is defined as:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;internal class InterceptAttribute : BeforeAfterTestAttribute
{
    public override void Before(MethodInfo methodUnderTest)
    {
    }

    public override void After(MethodInfo methodUnderTest)
    {
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;It allows code to be run before and after each test is run.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;[StringData]&lt;/code&gt; is defined as:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;internal class StringDataAttribute : DataAttribute
{
    public override IEnumerable&amp;lt;object[]&amp;gt; GetData(
        MethodInfo methodUnderTest,
        Type[] parameterTypes)
    {
        yield return new object[] { &amp;quot;cow&amp;quot;, &amp;quot;zoo&amp;quot; };
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

</description>
			<pubDate>Sun, 10 Mar 2013 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>XCOPY deployment for Code Contracts</title>
			<link>http://nikosbaxevanis.com/2013/03/04/xcopy-deployment-for-code-contracts</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2013/03/04/xcopy-deployment-for-code-contracts</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;If you don&amp;rsquo;t wish to install &lt;a href=&quot;http://research.microsoft.com/en-us/projects/contracts/&quot;&gt;Code Contracts&lt;/a&gt; through the Windows Installer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to &lt;code&gt;\Program Files (x86)\MSBuild\4.0\Microsoft.Common.Targets\ImportAfter&lt;/code&gt; folder.&lt;/li&gt;
&lt;li&gt;Create a new file with name &lt;code&gt;CodeContractsAfter.targets&lt;/code&gt; and paste the following XML:&lt;/li&gt;
&lt;/ul&gt;


&lt;div&gt;
  &lt;pre&gt;&lt;code class='xml'&gt;&amp;lt;Project xmlns=&amp;quot;http://schemas.microsoft.com/developer/msbuild/2003&amp;quot;&amp;gt;
  &amp;lt;PropertyGroup&amp;gt;
    &amp;lt;CodeContractsInstallDir Condition=&amp;quot;'$(CodeContractsInstallDir)'==''&amp;quot;&amp;gt;CONTRACTS_PATH&amp;lt;/CodeContractsInstallDir&amp;gt;
  &amp;lt;/PropertyGroup&amp;gt;
  &amp;lt;Import Condition=&amp;quot;'$(CodeContractsImported)' != 'true' AND '$(DontImportCodeContracts)' != 'true'&amp;quot; 
          Project=&amp;quot;$(CodeContractsInstallDir)MsBuild\v4.0\Microsoft.CodeContracts.targets&amp;quot; /&amp;gt;
&amp;lt;/Project&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Extract the contents from the Code Contracts Windows Installer using the &lt;a href=&quot;https://code.google.com/p/lessmsi/&quot;&gt;lessmsi&lt;/a&gt; tool.&lt;/li&gt;
&lt;li&gt;Locate the &lt;code&gt;Contracts&lt;/code&gt; folder in the extracted contents.&lt;/li&gt;
&lt;li&gt;Replace the &lt;code&gt;CONTRACTS_PATH&lt;/code&gt; in &lt;code&gt;CodeContractsAfter.targets&lt;/code&gt; with the actual &lt;code&gt;Contracts&lt;/code&gt; folder location.&lt;/li&gt;
&lt;/ul&gt;

</description>
			<pubDate>Mon, 04 Mar 2013 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Legacy Code Risk</title>
			<link>http://nikosbaxevanis.com/2013/03/03/legacy-code-risk</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2013/03/03/legacy-code-risk</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Taking the risk to adjust the architecture of a  &lt;a href=&quot;http://c2.com/cgi/wiki?WorkingEffectivelyWithLegacyCode&quot;&gt;legacy&lt;/a&gt; system and extend it in a nice and clean way.&lt;/p&gt;

&lt;p&gt;Creating a context:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Complex domain (e.g. life insurance)&lt;/li&gt;
&lt;li&gt;Many technologies are used, tightly coupled (e.g. Redis, db40, iBATIS, Quartz,  Sparks, etc).&lt;/li&gt;
&lt;li&gt;The model has been designed around the &lt;a href=&quot;http://en.wikipedia.org/wiki/Active_record_pattern&quot;&gt;Active Record&lt;/a&gt; (&lt;a href=&quot;http://programmers.stackexchange.com/questions/119352/does-the-activerecord-pattern-follow-encourage-the-solid-design-principles&quot;&gt;anti&lt;/a&gt;)pattern.&lt;/li&gt;
&lt;li&gt;In a few places there are also DAOs and/or Repositories.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;http://en.wikipedia.org/wiki/Service_locator_pattern&quot;&gt;Service Locator&lt;/a&gt; (&lt;a href=&quot;http://blog.ploeh.dk/2010/02/03/ServiceLocatorIsAnAntiPattern.aspx&quot;&gt;anti&lt;/a&gt;)pattern has been applied everywhere.&lt;/li&gt;
&lt;li&gt;Almost everywhere, the &lt;a href=&quot;http://en.wikipedia.org/wiki/Single_responsibility_principle&quot;&gt;SRP&lt;/a&gt; has been violated.&lt;/li&gt;
&lt;li&gt;Communication with any external Web Service is not guarded with a &lt;a href=&quot;http://en.wikipedia.org/wiki/Circuit_breaker_design_pattern&quot;&gt;Circuit Breaker&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;And yes.. there are no tests..&lt;/li&gt;
&lt;/ul&gt;


&lt;blockquote&gt;&lt;p&gt;(All the above yield sad customers, bugs, and slow performance.)&lt;/p&gt;&lt;/blockquote&gt;

&lt;h2&gt;Against messy, tightly coupled, legacy code.&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Strive toward &lt;a href=&quot;http://blog.ploeh.dk/2012/01/03/SOLIDIsAppendonly.aspx&quot;&gt;real SOLID&lt;/a&gt; principles&lt;/li&gt;
&lt;li&gt;Instead of doing &lt;a href=&quot;http://localhost:4000/2012/01/28/test-after-development-sins/&quot;&gt;Test-After Development Sins&lt;/a&gt; write &lt;strong&gt;test code&lt;/strong&gt; &lt;em&gt;trying&lt;/em&gt; to &lt;strong&gt;drive the&lt;/strong&gt; &lt;a href=&quot;http://xunitpatterns.com/SUT.html&quot;&gt;SUT&lt;/a&gt; &lt;strong&gt;API&lt;/strong&gt; and safely refactoring afterwards. The non-relevant &lt;a href=&quot;http://xunitpatterns.com/test%20fixture%20-%20xUnit.html&quot;&gt;Test Fixture&lt;/a&gt; setup is automated with &lt;a href=&quot;https://github.com/AutoFixture&quot;&gt;AutoFixture&lt;/a&gt; &lt;a href=&quot;http://blog.ploeh.dk/2010/10/08/AutoDataTheoriesWithAutoFixture.aspx&quot;&gt;decleratively&lt;/a&gt; with the xUnit.net &lt;a href=&quot;http://nuget.org/packages/AutoFixture.Xunit/&quot;&gt;extension&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Instead of using the Service Locator &lt;strong&gt;use Dependency Injection patterns&lt;/strong&gt;, such is &lt;a href=&quot;http://blog.ploeh.dk/2011/03/03/InjectionConstructorsShouldBeSimple.aspx&quot;&gt;Constructor Injection&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Instead of using Active Record, Repositories and DAOs consider using &lt;strong&gt;Queries and Commands&lt;/strong&gt; &lt;em&gt;(as described in the first half of &lt;a href=&quot;http://codebetter.com/gregyoung/2010/02/16/cqrs-task-based-uis-event-sourcing-agh/&quot;&gt;this post&lt;/a&gt;&lt;/em&gt;). This might result in more classes but each class is going to have one responsibility instead of two or more.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;Why it is a risk?&lt;/h2&gt;

&lt;p&gt;The above require a few changes in the system architecture (e.g. in order to be possible to &lt;em&gt;not&lt;/em&gt; use Service Locators, in order to be possible to use &lt;em&gt;Services&lt;/em&gt; to query from the database instead of the Active Record way, etc.).&lt;/p&gt;

&lt;p&gt;While the required changes are going to (initially) &lt;a href=&quot;http://butunclebob.com/ArticleS.UncleBob.SpeedKills&quot;&gt;slow down the development process&lt;/a&gt; at the end the overall development is going to be faster.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Would &lt;em&gt;you&lt;/em&gt; take the risk?&lt;/p&gt;&lt;/blockquote&gt;
</description>
			<pubDate>Sun, 03 Mar 2013 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Database Schema Synchronization with SqlPackage.exe</title>
			<link>http://nikosbaxevanis.com/2013/02/11/database-schema-synchronization-with-sql-server-data-tools</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2013/02/11/database-schema-synchronization-with-sql-server-data-tools</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/hh550080.aspx&quot;&gt;SqlPackage&lt;/a&gt; is the descendant of &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/dd193283.aspx&quot;&gt;VsDbCmd&lt;/a&gt; command-line tool. It creates, deploys, and packages SQL Server databases snapshots into a portable artifact called a DAC package, also known as a DACPAC.&lt;/p&gt;

&lt;h2&gt;Manual Database Schema Synchronization&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create a New &lt;code&gt;SQL Server Database Project&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;On the newly created SQL Server Database Project:

&lt;ul&gt;
&lt;li&gt;Right Click, Import, Database&amp;hellip;&lt;/li&gt;
&lt;li&gt;Right Click, Properties

&lt;ul&gt;
&lt;li&gt;In the Project Settings tab select target platform &lt;em&gt;(e.g. SQL Server 2008)&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;In the SQLCMD Variables tab enter in the &lt;code&gt;Local&lt;/code&gt; column the path of SQL Server installation folder. Notice that the Local path overrides the &lt;code&gt;Default&lt;/code&gt; path.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Go to &lt;code&gt;SQL &amp;gt; Schema Compare &amp;gt; New Schema Comparison&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;Select as source the newly created SQL Server Database Project.&lt;/li&gt;
&lt;li&gt;Select as target the database containing the schema to be synchronized.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;Automatic Database Schema Synchronization&lt;/h2&gt;

&lt;p&gt;When there is no network access in production environment, the synchronization process can be automated.&lt;/p&gt;

&lt;p&gt;Thanks to &lt;a href=&quot;mailto:jimikar@gmail.com&quot;&gt;Dimitris Charalampidis&lt;/a&gt; who provided the steps below, the database schema synchronization can be automated as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Copy the created &amp;lsquo;.dacpac&amp;rsquo; file from SQL Server Database Project build output path to the same folder as SqlPackage.&lt;/li&gt;
&lt;li&gt;Open a command console and execute the following command:&lt;/li&gt;
&lt;/ul&gt;


&lt;div&gt;
  &lt;pre&gt;&lt;code class='python'&gt;sqlpackage.exe /a:Script /sf:$Yourdatabaseproject.dacpac$ /tcs:&amp;quot;Data Source=$ServerName$;Database=$DatabaseName$;User id=$userid$;password=$password$;Trusted_Connection=false;&amp;quot; /op:DBSchemaCompareScript.sql /p:ScriptDeployStateChecks=True /p:BackupDatabaseBeforeChanges=True /p:IgnoreExtendedProperties=True /p:IgnorePermissions=True /p:IgnoreRoleMembership=True /v:Path1=&amp;quot;$Path1$&amp;quot; /v:Path2=&amp;quot;$Path2$&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Replace:

&lt;ul&gt;
&lt;li&gt;$Yourdatabaseproject.dacpac$ with the database project snapshot name you copied in the folder earlier.&lt;/li&gt;
&lt;li&gt;$ServerName$ with the target SQL Server instance name.&lt;/li&gt;
&lt;li&gt;$DatabaseName$ with the target database name.&lt;/li&gt;
&lt;li&gt;$userid$ and $password$ with the SQL Server Authentication credentials.&lt;/li&gt;
&lt;li&gt;$Path1$ and $Path2$ with the path to the SQL Server installation folder.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;blockquote&gt;&lt;p&gt;At this point you may want to add also the &lt;code&gt;/p:GenerateSmartDefaults=True&lt;/code&gt; switch to provide a default value when updating a table that contains data with for columns that do not allow null values.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;After a few seconds a file named &lt;em&gt;DBSchemaCompareScript.sql&lt;/em&gt; will be created (you can change the name with the &lt;code&gt;/op:&lt;/code&gt; switch value).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open the script file with Microsoft SQL Server Management Studio.&lt;/li&gt;
&lt;li&gt;Select &lt;code&gt;Query &amp;gt; SQLCMD Mode&lt;/code&gt; and execute the query.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;After the query executes without errors, the database schema will be synchronized with the latest changes.&lt;/p&gt;

&lt;h2&gt;Remarks&lt;/h2&gt;

&lt;p&gt;The following files are required by the SqlPackage if the &lt;a href=&quot;http://msdn.microsoft.com/en-us/data/tools.aspx&quot;&gt;Microsoft SQL Server Data Tools&lt;/a&gt; is not installed in production environment:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SqlPackage.exe&lt;/li&gt;
&lt;li&gt;Microsoft.Data.Tools.Schema.Sql.dll&lt;/li&gt;
&lt;li&gt;Microsoft.Data.Tools.Utilities.dll&lt;/li&gt;
&lt;li&gt;Microsoft.SqlServer.Dac.dll&lt;/li&gt;
&lt;li&gt;Microsoft.SqlServer.TransactSql.ScriptDom.dll&lt;/li&gt;
&lt;/ul&gt;

</description>
			<pubDate>Mon, 11 Feb 2013 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Compiling .NET projects in Sublime Text</title>
			<link>http://nikosbaxevanis.com/2013/02/07/compiling-net-projects-in-sublime-text</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2013/02/07/compiling-net-projects-in-sublime-text</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;blockquote&gt;&lt;p&gt;The subject of this post is the compilation of .NET projects and solutions in Sublime Text using the Build Systems feature.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;&lt;a href=&quot;http://www.sublimetext.com/&quot;&gt;Sublime Text&lt;/a&gt; supports custom &lt;a href=&quot;http://docs.sublimetext.info/en/latest/file_processing/build_systems.html&quot;&gt;Build Systems&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;By adding &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/wea2sca5.aspx&quot;&gt;MSBuild&lt;/a&gt; as a new Build System, it is possible to build Visual Studio projects and solutions without the Visual Studio IDE installed.&lt;/p&gt;

&lt;h2&gt;Adding the Source Code&lt;/h2&gt;

&lt;blockquote&gt;&lt;p&gt;The following steps require a folder with MSBuild project files. In order to be pragmatic, the custom Build System is going to compile the source code of &lt;a href=&quot;https://github.com/AutoFixture/AutoFixture&quot;&gt;AutoFixture&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Go to &lt;code&gt;File&lt;/code&gt; menu, click &lt;code&gt;Open Folder...&lt;/code&gt; and select the root folder of the project to be compiled.&lt;/p&gt;

&lt;h2&gt;Adding the new Build System&lt;/h2&gt;

&lt;p&gt;Go to &lt;code&gt;Tools&lt;/code&gt; menu, &lt;code&gt;Build System&lt;/code&gt;, and click &lt;code&gt;New Build System...&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Paste the following code to a file:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='json'&gt;{
    &amp;quot;cmd&amp;quot;: [&amp;quot;C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\MSBuild.exe&amp;quot;, &amp;quot;AutoFixture.sln&amp;quot;],
    &amp;quot;working_dir&amp;quot;: &amp;quot;${project_path:${folder:${file_path}}}\\Src&amp;quot;
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Save the file as &lt;code&gt;AutoFixture.sublime-build&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Go to &lt;code&gt;Tools&lt;/code&gt; menu, &lt;code&gt;Build System&lt;/code&gt;, and select &lt;code&gt;AutoFixture&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;The above steps are per MBSuild project file. Repeat the above steps by creating a Build System per MSBuild project file.&lt;/p&gt;&lt;/blockquote&gt;

&lt;h2&gt;Running the Build&lt;/h2&gt;

&lt;p&gt;Go to &lt;code&gt;Tools&lt;/code&gt; menu, and select &lt;code&gt;Build&lt;/code&gt;. Alternatively, use the &lt;code&gt;Ctrl+B&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8371/8454681575_f36c89b618_o.png&quot; alt=&quot;The compiler detects a missing semicolon.&quot;/&gt;&lt;/p&gt;


&lt;p&gt;In the above screenshot, on line &lt;em&gt;38&lt;/em&gt; a semicolon has been intentionally removed for the demo. After running a build, the compiler detects the missing semicolon.&lt;/p&gt;

&lt;h2&gt;What about the Tests?&lt;/h2&gt;

&lt;p&gt;Currently, the easiest way to run the tests is by using a command-line interface version of the test runner.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;On my machine, attempting to add a new Build System for the tests resulted in &lt;a href=&quot;https://twitter.com/nikosbaxevanis/status/298701966945693696&quot;&gt;high memory usage&lt;/a&gt;. This has been tested while Sublime Text 3 was in beta (Build 3010).&lt;/p&gt;&lt;/blockquote&gt;
</description>
			<pubDate>Thu, 07 Feb 2013 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Commit to Revision Control with Care</title>
			<link>http://nikosbaxevanis.com/2013/01/01/commit-to-revision-control-with-care</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2013/01/01/commit-to-revision-control-with-care</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;We should always commit to &lt;a href=&quot;http://en.wikipedia.org/wiki/Revision_control&quot;&gt;revision control&lt;/a&gt; with care.&lt;/p&gt;

&lt;p&gt;Often, developers provide commit messages that are &lt;em&gt;incomplete&lt;/em&gt;, &lt;em&gt;lowercase&lt;/em&gt;, with &lt;em&gt;orthographic permutations&lt;/em&gt;. Even worse, snapshots can contain code that doesn&amp;rsquo;t even compile.&lt;/p&gt;

&lt;p&gt;In a signed document the rules and regulations can be altered and then another document is going to be created and signed, but the original document will always remain signed.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;As signatures in documents can&amp;rsquo;t be erased so do recorded snapshots, at least it is not always an easy task.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;After a snapshot has been recorded it acts like a signature for the developer &amp;ndash; should we ever put our signature roughly?&lt;/p&gt;
</description>
			<pubDate>Tue, 01 Jan 2013 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>ReSharper - The Good Parts (Static Code Analysis)</title>
			<link>http://nikosbaxevanis.com/2012/12/06/resharper-the-good-parts</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2012/12/06/resharper-the-good-parts</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;&lt;em&gt;What I really like about ReSharper is the Static code analysis, and the quick-fixes. What I really don&amp;rsquo;t like is pretty much everything else.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;Keeping only the Static code analysis&lt;/h2&gt;

&lt;p&gt;Go to ReSharper menu and clik Options&amp;hellip;&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;Environment &amp;gt; General&lt;/code&gt; tab uncheck:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Show tips on startup&lt;/li&gt;
&lt;li&gt;Loop selection around ends of a list&lt;/li&gt;
&lt;li&gt;Show managed memory usage in status bar&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8074/8397465683_d51c48ceb6_o.png&quot; alt=&quot;ReSharper, Options, Environment, General&quot;/&gt;&lt;/p&gt;


&lt;p&gt;In the &lt;code&gt;Environment &amp;gt; Keyboard &amp;amp; Menus&lt;/code&gt; tab select:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hide overridden Visual Studio menu items &lt;em&gt;(from Menus &amp;amp; Toolbars)&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;None &lt;em&gt;(from Keyboard Shortcuts)&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8094/8397465095_bbb7ddf76f_o.png&quot; alt=&quot;ReSharper, Options, Environment, Keyboard and Menus&quot;/&gt;&lt;/p&gt;


&lt;p&gt;In the &lt;code&gt;Environment &amp;gt; Editor&lt;/code&gt; tab uncheck:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Highlight current line&lt;/li&gt;
&lt;li&gt;Auto-format on semicolon brace&lt;/li&gt;
&lt;li&gt;Auto-format on closing brace&lt;/li&gt;
&lt;li&gt;Use CamelHumps&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;From &lt;em&gt;Braces and Parentheses&lt;/em&gt; uncheck:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Highlight matching delimiters when care is ..&lt;/li&gt;
&lt;li&gt;Auto-insert pair brackets, parentheses and quotes&lt;/li&gt;
&lt;li&gt;Auto-insert closing brace&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8231/8398552804_0eb198dd4e_o.png&quot; alt=&quot;ReSharper, Options, Environment, Editor&quot;/&gt;&lt;/p&gt;


&lt;p&gt;In the &lt;code&gt;Environment &amp;gt; IntelliSense &amp;gt; General&lt;/code&gt; tab select:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Limited ReSharper IntelliSense &lt;em&gt;and uncheck C#&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8097/8397463717_943221138e_o.png&quot; alt=&quot;ReSharper, Options, Environment, IntelliSense General&quot;/&gt;&lt;/p&gt;


&lt;p&gt;Uncheck everything in the &lt;code&gt;IntelliSense &amp;gt; Completion Behavior&lt;/code&gt; tab.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8331/8397462935_0b0087a910_o.png&quot; alt=&quot;ReSharper, Options, Environment, IntelliSense Completion Behavior&quot;/&gt;&lt;/p&gt;


&lt;p&gt;In the &lt;code&gt;Environment &amp;gt; IntelliSense &amp;gt; Completion Appearance&lt;/code&gt; tab select:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Visual Studio IntelliSense font&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Uncheck everything else&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8077/8398550898_58666c6fba_o.png&quot; alt=&quot;ReSharper, Options, Environment, IntelliSense Completion Appearance&quot;/&gt;&lt;/p&gt;


&lt;p&gt;In the &lt;code&gt;Environment &amp;gt; IntelliSense &amp;gt; Parameter Info&lt;/code&gt; tab select:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Arrow keys&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Uncheck everything else&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8072/8398550136_32dc9b9dbf_o.png&quot; alt=&quot;ReSharper, Options, Environment, IntelliSense Parameter Info&quot;/&gt;&lt;/p&gt;


&lt;h2&gt;Enable Visual Studio IntelliSense&lt;/h2&gt;

&lt;p&gt;Since we customized ReSharper to use Visual Studio IntelliSense, we have to manually enable it from Visual Studio options.&lt;/p&gt;

&lt;p&gt;In Visual Studio, go to Tools menu and click Options&amp;hellip;&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;Text Editor &amp;gt; C#&lt;/code&gt; tab select:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Auto list members&lt;/li&gt;
&lt;li&gt;Parameter information&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8192/8398549650_3df34f8571_o.png&quot; alt=&quot;Visual Studio, Tools, Options, Text Editor, C#&quot;/&gt;&lt;/p&gt;


&lt;h2&gt;Suspending ReSharper&lt;/h2&gt;

&lt;p&gt;There are some projects where I don&amp;rsquo;t even want to have ReSharper&amp;rsquo;s Static code analysis and the quick-fixes.&lt;/p&gt;

&lt;p&gt;In Visual Studio, go to Tools menu and click Options&amp;hellip;&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;ReSharper&lt;/code&gt; tab click &lt;em&gt;Suspend&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8048/8398549044_4bb64e66ec_o.png&quot; alt=&quot;Visual Studio, Tools, Options, ReSharper&quot;/&gt;&lt;/p&gt;



</description>
			<pubDate>Thu, 06 Dec 2012 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Empty ASP.NET Web API Project Template</title>
			<link>http://nikosbaxevanis.com/2012/11/02/empty-asp-net-web-api-project-template</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2012/11/02/empty-asp-net-web-api-project-template</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Usually, every time you create a new Web API project you:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Delete almost all the generated code.&lt;/li&gt;
&lt;li&gt;Uninstall NuGet packages that you don&amp;rsquo;t need (yet, or at all).&lt;/li&gt;
&lt;li&gt;Remove unused assembly references.&lt;/li&gt;
&lt;li&gt;Manually edit the &lt;code&gt;Web.config&lt;/code&gt; file(s) to remove the elements that point to the assemblies which have been removed.&lt;/li&gt;
&lt;/ol&gt;


&lt;h2&gt;Solution&lt;/h2&gt;

&lt;p&gt;Use the &lt;a href=&quot;https://github.com/moodmosaic/EmptyWebApiProjectTemplate&quot;&gt;Empty ASP.NET Web API Project Template&lt;/a&gt;. The Visual Studio extension can be downloaded from &lt;a href=&quot;http://visualstudiogallery.msdn.microsoft.com/a989a149-4bc3-4292-ac8a-5101ee1722d7&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It will add a new project template &lt;code&gt;Empty Web API&lt;/code&gt; which includes the following:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Files&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Properties\AssemblyInfo.cs&lt;/li&gt;
&lt;li&gt;favicon.ico&lt;/li&gt;
&lt;li&gt;Global.asax&lt;/li&gt;
&lt;li&gt;Web.config&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;&lt;strong&gt;Assemblies&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;System&lt;/li&gt;
&lt;li&gt;System.Core&lt;/li&gt;
&lt;li&gt;System.Configuration&lt;/li&gt;
&lt;li&gt;System.Net.Http&lt;/li&gt;
&lt;li&gt;System.Web&lt;/li&gt;
&lt;li&gt;System.Web.Abstractions&lt;/li&gt;
&lt;li&gt;System.Web.ApplicationServices&lt;/li&gt;
&lt;li&gt;System.Web.Mvc&lt;/li&gt;
&lt;li&gt;System.Web.Routing&lt;/li&gt;
&lt;li&gt;System.Xml&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;&lt;strong&gt;NuGet packages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Microsoft.AspNet.WebApi.Client&lt;/li&gt;
&lt;li&gt;Microsoft.AspNet.WebApi.Core&lt;/li&gt;
&lt;li&gt;Microsoft.AspNet.WebApi.WebHost&lt;/li&gt;
&lt;li&gt;&lt;del&gt;Microsoft.AspNet.Providers.Core&lt;/del&gt;&lt;/li&gt;
&lt;li&gt;Microsoft.Net.Http&lt;/li&gt;
&lt;li&gt;Newtonsoft.Json&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;Remarks&lt;/h2&gt;

&lt;p&gt;The Newtonsoft.Json package is included because it is lazy loaded inside the &lt;code&gt;System.Net.Http.Formatting.JsonMediaTypeFormatter&lt;/code&gt; type.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;If you completely remove the Newtonsoft.Json assembly a System.IO.FileNotFoundException exception is thrown with message &amp;ldquo;Could not load file or assembly &amp;lsquo;Newtonsoft.Json, ..&amp;rsquo; or one of its dependencies. The system cannot find the file specified.&amp;rdquo;&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;A &lt;code&gt;favicon.ico&lt;/code&gt; file is included because the browser requests it so &lt;a href=&quot;http://developer.yahoo.com/performance/rules.html#favicon&quot;&gt;it&amp;rsquo;s better not to respond with a 404 Not Found&lt;/a&gt;.&lt;/p&gt;
</description>
			<pubDate>Fri, 02 Nov 2012 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Exercising the SUT asynchronously</title>
			<link>http://nikosbaxevanis.com/2012/10/28/exercising-the-sut-asynchronously</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2012/10/28/exercising-the-sut-asynchronously</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;In unit testing, there are times were the &lt;a href=&quot;http://xunitpatterns.com/SUT.html&quot;&gt;SUT&lt;/a&gt; has to be exercised &lt;strong&gt;asynchronously&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;How can we wait for the exercise to complete execution?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An instance of the SUT can be created on the main thread.&lt;/li&gt;
&lt;li&gt;The main &lt;em&gt;(waiting)&lt;/em&gt; thread &lt;strong&gt;spins in user mode&lt;/strong&gt; while starting the exercise of the SUT asynchronously.&lt;/li&gt;
&lt;li&gt;Once the result has been received, the execution continues on the main thread.&lt;/li&gt;
&lt;li&gt;The assertion takes place.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;The &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.threading.spinwait.aspx&quot;&gt;SpinWait&lt;/a&gt; synchronization type contains a method named &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.threading.spinwait.spinuntil.aspx&quot;&gt;SpinUntil&lt;/a&gt; which works perfect for the described scenario.&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;// Fixture setup
var sut = new ObjectLocalStorage();
sut.Set(@object, expected);
object result = null;

// Exercise system
new Task(() =&amp;gt; result = sut.Get(@object)).Start();
SpinWait.SpinUntil(() =&amp;gt; result != null);

// Verify outcome
Assert.Equal(expected, result);
// Teardown&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Once the &lt;code&gt;Task&lt;/code&gt; has been created it is immediately scheduled for execution by calling the &lt;code&gt;Start&lt;/code&gt; method.&lt;/li&gt;
&lt;li&gt;As long as the unit test runs fast, the waiting thread spins in user mode, which is a &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ee722114.aspx&quot;&gt;good thing&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;There is also a &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/dd449238.aspx&quot;&gt;SpinUntil overload&lt;/a&gt; accepting a TimeSpan timeout.&lt;/p&gt;
</description>
			<pubDate>Sun, 28 Oct 2012 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Truly Constrained Non-Deterministic Numbers in AutoFixture</title>
			<link>http://nikosbaxevanis.com/2012/10/08/truly-constrained-non-deterministic-numbers-in-autofixture</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2012/10/08/truly-constrained-non-deterministic-numbers-in-autofixture</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Numbers in &lt;a href=&quot;https://github.com/autofixture/autofixture&quot;&gt;AutoFixture&lt;/a&gt; are currently created using a &lt;strong&gt;strictly monotonically increasing&lt;/strong&gt; sequence.&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;var fixture = new Fixture();

var i = fixture.CreateAnonymous&amp;lt;int&amp;gt;();
// Prints -&amp;gt; 1
var l = fixture.CreateAnonymous&amp;lt;long&amp;gt;();
// Prints -&amp;gt; 2
var f = fixture.CreateAnonymous&amp;lt;float&amp;gt;();
// Prints -&amp;gt; 3.0&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Starting with version &lt;em&gt;2.13.0&lt;/em&gt;, by applying a specific customization numbers can also be created using a &lt;strong&gt;constrained non-deterministic&lt;/strong&gt; sequence. The new customization is called &lt;code&gt;RandomNumericSequenceCustomization&lt;/code&gt;.&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;var fixture = new Fixture()
    .Customize(new RandomNumericSequenceCustomization());

var i = fixture.CreateAnonymous&amp;lt;int&amp;gt;();
// Prints -&amp;gt; 122
var l = fixture.CreateAnonymous&amp;lt;long&amp;gt;();
// Prints -&amp;gt; 38
var f = fixture.CreateAnonymous&amp;lt;float&amp;gt;();
// Prints -&amp;gt; 147.0&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Once the customization has been applied to a &lt;code&gt;Fixture&lt;/code&gt; instance subsequent requests for numeric types will yield random non-repeatable numbers in the range of [1, 255]. When requesting more than 255 numbers the range is automatically changed to [256, 32767] and so on.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;The default ranges are [1, 255], [256, 32767], and [32768, 2147483647].&lt;/p&gt;&lt;/blockquote&gt;

&lt;h2&gt;Supplying a custom range&lt;/h2&gt;

&lt;p&gt;To supply a custom range, customize an instance of the Fixture class with an instance of the &lt;code&gt;RandomNumericSequenceGenerator&lt;/code&gt; and pass to its constructor a sequence of integer numbers (e.g. &lt;code&gt;-100, 100, 255&lt;/code&gt;).&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;The sequence must be two positive or negative numbers optionally followed by a series of greater numbers.&lt;/p&gt;&lt;/blockquote&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;var fixture = new Fixture();
fixture.Customizations.Add(
    new RandomNumericSequenceGenerator(-100, 100, 255));

var i = fixture.CreateAnonymous&amp;lt;int&amp;gt;();
// Prints -&amp;gt; -95
var l = fixture.CreateAnonymous&amp;lt;long&amp;gt;();
// Prints -&amp;gt; 47
var f = fixture.CreateAnonymous&amp;lt;float&amp;gt;();
// Prints -&amp;gt; -82.0&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;After applying the customization, numbers are now created in the range of [-100, 100]. However, when requesting more numbers than the range size the range is automatically changed to [101, 255].&lt;/p&gt;
</description>
			<pubDate>Mon, 08 Oct 2012 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Statement Completion for Dynamic languages in Sublime Text</title>
			<link>http://nikosbaxevanis.com/2012/10/05/statement-completion-for-dynamic-languages-in-sublime-text</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2012/10/05/statement-completion-for-dynamic-languages-in-sublime-text</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;This post describes how to configure &lt;a href=&quot;http://www.sublimetext.com/&quot;&gt;Sublime Text&lt;/a&gt; in order to get statement completion for JavaScript, Python, &lt;em&gt;(and perhaps PHP, RHTML, Smarty, Mason, Node.js, XBL, Tcl, HTML, HTML5, TemplateToolkit, XUL, Django, Perl, and Ruby)&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;After following the steps, statement completion will also work for Python projects installed in a &lt;a href=&quot;http://www.virtualenv.org/en/latest/index.html#what-it-does&quot;&gt;virtualenv&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Download Sublime Text from &lt;a href=&quot;http://www.sublimetext.com/2&quot;&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Install on Windows or OS X (it doesn&amp;rsquo;t really matter).&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;Install Package Manager&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Run Sublime Text&lt;/li&gt;
&lt;li&gt;Open the Sublime Text Console. This is accessed via the &lt;em&gt;ctrl + `&lt;/em&gt; shortcut.&lt;/li&gt;
&lt;li&gt;Paste the following command into the console (it has to be all in one line):&lt;/li&gt;
&lt;/ul&gt;


&lt;div&gt;
  &lt;pre&gt;&lt;code class='python'&gt;import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print 'Please restart Sublime Text to finish installation'&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Restart Sublime Text&lt;/li&gt;
&lt;/ul&gt;


&lt;blockquote&gt;&lt;p&gt;We have just installed Sublime Package Control &amp;ndash; A full-featured package manager that helps discovering, installing, updating and removing packages for Sublime Text 2. It features an automatic updater and supports GitHub, BitBucket and a full channel/repository system.&lt;/p&gt;&lt;/blockquote&gt;

&lt;h2&gt;Configure Statement Completion&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Press &lt;em&gt;ctrl + shift + p&lt;/em&gt; (Windows, Linux) or &lt;em&gt;cmd + shift + p&lt;/em&gt; (OS X).&lt;/li&gt;
&lt;li&gt;Type &lt;em&gt;Install Package&lt;/em&gt; and select it.&lt;/li&gt;
&lt;/ul&gt;


&lt;blockquote&gt;&lt;p&gt;The &lt;em&gt;Install Package&lt;/em&gt; command shows a list of all available packages that are available for install. This will include all of the packages from the &lt;a href=&quot;http://wbond.net/sublime_packages/community&quot;&gt;default channel&lt;/a&gt;, plus any from repositories you have added.&lt;/p&gt;&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Select &lt;code&gt;SublimeCodeIntel&lt;/code&gt; from the list of packages.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;Configure Statement Completion for Python projects in virtualenv&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;You may skip this if you are not using virtualenv.&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a &lt;code&gt;.codeintel&lt;/code&gt; directory at the root of the project&lt;/li&gt;
&lt;li&gt;Create a &lt;code&gt;config&lt;/code&gt; file (without any extension) inside the newly created directory.&lt;/li&gt;
&lt;/ul&gt;


&lt;div&gt;
  &lt;pre&gt;&lt;code class='json'&gt;{
    &amp;quot;Python&amp;quot;: {
        &amp;quot;python&amp;quot;: '~/Documents/Projects/VirtualEnvName/bin/python',
        &amp;quot;pythonExtraPaths&amp;quot;: ['~/Documents/Projects/VirtualEnvName/lib/python/site-packages',
        ]
    },
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Note that &lt;code&gt;VirtualEnvName&lt;/code&gt; is the name of the virtualenv were the files of the project are located.&lt;/p&gt;

&lt;p&gt;The project itself is in &lt;code&gt;~/Documents/Projects/VirtualEnvName/ProjectName&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;Statement Completion in action!&lt;/h2&gt;

&lt;p&gt;A screenshot for jQuery (note also the &lt;a href=&quot;https://github.com/buymeasoda/soda-theme&quot;&gt;&lt;em&gt;very&lt;/em&gt; cool theme&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8357/8397459957_e121e4b04c_o.png&quot; alt=&quot;A screenshot for jQuery&quot;/&gt;&lt;/p&gt;


&lt;p&gt;Also,&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://farm9.staticflickr.com/8076/8398548370_3a313d63d8_o.png&quot; target=&quot;_blank&quot;&gt;A screenshot for Document Object Model&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://farm9.staticflickr.com/8466/8397459947_18d7176364_o.png&quot; target=&quot;_blank&quot;&gt;A screenshot for Python&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;References:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.sublimetext.com/&quot;&gt;Sublime Text &amp;ndash; The text editor you&amp;rsquo;ll fall in love with&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://wbond.net/sublime_packages/package_control&quot;&gt;Sublime Package Control &amp;ndash; Overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://wbond.net/sublime_packages/package_control/usage&quot;&gt;Sublime Package Control &amp;ndash; Usage&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/Kronuz/SublimeCodeIntel&quot;&gt;Sublime Code Intel &amp;ndash; Overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/Kronuz/SublimeCodeIntel/issues/165&quot;&gt;Sublime Code Intel &amp;ndash; Usage on virtualenv&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
			<pubDate>Fri, 05 Oct 2012 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>AutoFixture, xUnit.net, and Auto Mocking</title>
			<link>http://nikosbaxevanis.com/2012/07/31/autofixture-xunit-net-and-auto-mocking</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2012/07/31/autofixture-xunit-net-and-auto-mocking</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;blockquote&gt;&lt;p&gt;The features discussed in this post are available when using &lt;a href=&quot;https://github.com/AutoFixture/AutoFixture&quot;&gt;AutoFixture&lt;/a&gt; &lt;a href=&quot;http://blog.ploeh.dk/2010/10/08/AutoDataTheoriesWithAutoFixture.aspx&quot;&gt;decleratively&lt;/a&gt; with the xUnit.net &lt;a href=&quot;http://nuget.org/packages/AutoFixture.Xunit/&quot;&gt;extension&lt;/a&gt;. In addition, it is required to have at least one of the extensions for Auto Mocking using &lt;a href=&quot;http://nuget.org/packages/AutoFixture.AutoMoq&quot;&gt;AutoMoq&lt;/a&gt;, &lt;a href=&quot;http://nuget.org/packages/AutoFixture.AutoRhinoMocks&quot;&gt;AutoRhinoMocks&lt;/a&gt;, or &lt;a href=&quot;http://nuget.org/packages/AutoFixture.AutoFakeItEasy&quot;&gt;AutoFakeItEasy&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;To install AutoFixture with xUnit.net data theories, run the following command in the Package Manager Console:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;PM&amp;gt; Install-Package AutoFixture.Xunit&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;In the test method below we would like to use xUnit.net data theories to provide:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Auto-generated data specimens for &lt;code&gt;d&lt;/code&gt;, &lt;code&gt;s&lt;/code&gt;, &lt;code&gt;i&lt;/code&gt;, &lt;code&gt;a&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Auto-generated data specimens for &lt;code&gt;_&lt;/code&gt;, &lt;code&gt;s&lt;/code&gt;, &lt;code&gt;i&lt;/code&gt;, &lt;code&gt;a&lt;/code&gt;, and inline values for &lt;code&gt;d&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Auto-generated data specimens for &lt;code&gt;_&lt;/code&gt;, &lt;code&gt;_&lt;/code&gt;, &lt;code&gt;i&lt;/code&gt;, &lt;code&gt;a&lt;/code&gt;, and inline values for &lt;code&gt;d&lt;/code&gt;, &lt;code&gt;s&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;


&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public void TestMethod(
    double d, string s, IInterface i, AbstractType a)
{
    Assert.True(
        d != 0    &amp;amp;&amp;amp;
        s != null &amp;amp;&amp;amp;
        i != null &amp;amp;&amp;amp;
        a != null
        );
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;blockquote&gt;&lt;p&gt;That fact that argument &lt;code&gt;i&lt;/code&gt; is an interface and argument &lt;code&gt;a&lt;/code&gt; is an abstract class prevents us from using &lt;code&gt;[InlineData]&lt;/code&gt;, &lt;code&gt;[AutoData]&lt;/code&gt;, or &lt;code&gt;[InlineAutoData]&lt;/code&gt; attributes.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;AutoFixture allows us to easily define custom DataAttribute derived types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;By deriving from AutoDataAttribute and passing to the base constructor a customization that enables auto mocking with Moq, Rhino Mocks, or FakeItEasy.&lt;/li&gt;
&lt;li&gt;By deriving from CompositeDataAttribute and passing to the base constructor an array of DataAttribute derived type instances, e.g. an instance of &lt;code&gt;InlineDataAttribute&lt;/code&gt; and an instance of &lt;code&gt;AutoDataAttribute&lt;/code&gt; derived type.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;Auto Mocking using Moq&lt;/h2&gt;

&lt;p&gt;To install AutoFixture with Auto Mocking using Moq, run the following command in the Package Manager Console:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;PM&amp;gt; Install-Package AutoFixture.AutoMoq&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;We decorate the test method with AutoMoqData and InlineAutoMoqData attributes:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Theory]
[AutoMoqData]
[InlineAutoMoqData(2)]
[InlineAutoMoqData(3, &amp;quot;foo&amp;quot;)]
public void WithMoq(
    double d, string s, IInterface i, AbstractType a)
{
    Write(d, s, i, a);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Output:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='xml'&gt;AutoMoqData:
  d = 1
  s = s05080d05-b874-4182-bba5-18678ad9b134
  i = Castle.Proxies.IInterfaceProxy
  a = Castle.Proxies.AbstractTypeProxy
  
InlineAutoMoqData:
  d = 2
  s = sce87888d-8cc8-4f69-927c-c4b1347d3147
  i = Castle.Proxies.IInterfaceProxy
  a = Castle.Proxies.AbstractTypeProxy

InlineAutoMoqData:
  d = 3
  s = foo
  i = Castle.Proxies.IInterfaceProxy
  a = Castle.Proxies.AbstractTypeProxy&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Source code:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;internal class AutoMoqDataAttribute : AutoDataAttribute
{
    internal AutoMoqDataAttribute()
        : base(new Fixture().Customize(new AutoMoqCustomization()))
    {
    }
}

internal class InlineAutoMoqDataAttribute : CompositeDataAttribute
{
    internal InlineAutoMoqDataAttribute(params object[] values)
        : base(new DataAttribute[] { 
            new InlineDataAttribute(values), new AutoMoqDataAttribute() })
    {
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;More information on AutoFixture with Auto Mocking using Moq can be found at &lt;a href=&quot;http://blog.ploeh.dk/2010/08/19/AutoFixtureAsAnAutomockingContainer.aspx&quot;&gt;AutoFixture as an auto-mocking container&lt;/a&gt; blog post.&lt;/p&gt;

&lt;h2&gt;Auto Mocking using Rhino Mocks&lt;/h2&gt;

&lt;p&gt;To install AutoFixture with Auto Mocking using Rhino Mocks, run the following command in the Package Manager Console:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;PM&amp;gt; Install-Package AutoFixture.AutoRhinoMocks&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;We decorate the test method with AutoRhinoMockData and InlineAutoRhinoMockData attributes:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Theory]
[AutoRhinoMockData]
[InlineAutoRhinoMockData(2)]
[InlineAutoRhinoMockData(3, &amp;quot;foo&amp;quot;)]
public void WithRhinoMocks(
    double d, string s, IInterface i, AbstractType a)
{
    Write(d, s, i, a);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Ouput:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='xml'&gt;AutoRhinoMockData:
  d = 1
  s = s01172643-5162-474f-bcfa-319ef40a8272
  i = Castle.Proxies.IInterfaceProxy201f58a5559841bfb41895881489658c
  a = Castle.Proxies.AbstractTypeProxy5a86172bbda14cc098b4c675c5b7e555

InlineAutoRhinoMockData:
  d = 2
  s = sd3b9c112-5181-4daa-9b2f-333c7498044a
  i = Castle.Proxies.IInterfaceProxy201f58a5559841bfb41895881489658c
  a = Castle.Proxies.AbstractTypeProxy5a86172bbda14cc098b4c675c5b7e555
  
InlineAutoRhinoMockData:
  d = 3
  s = foo
  i = Castle.Proxies.IInterfaceProxy201f58a5559841bfb41895881489658c
  a = Castle.Proxies.AbstractTypeProxy5a86172bbda14cc098b4c675c5b7e555&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Source code:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;internal class AutoRhinoMockDataAttribute : AutoDataAttribute
{
    internal AutoRhinoMockDataAttribute()
        : base(new Fixture().Customize(new AutoRhinoMockCustomization()))
    {
    }
}

internal class InlineAutoRhinoMockDataAttribute : CompositeDataAttribute
{
    internal InlineAutoRhinoMockDataAttribute(params object[] values)
        : base(new DataAttribute[] { 
            new InlineDataAttribute(values), new AutoRhinoMockDataAttribute() })
    {
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;More information on AutoFixture with Auto Mocking using Rhino Mocks can be found at &lt;a href=&quot;http://blog.ploeh.dk/2010/11/13/RhinoMocksbasedAutomockingWithAutoFixture.aspx&quot;&gt;Rhino Mocks-based auto-mocking with AutoFixture&lt;/a&gt; blog post.&lt;/p&gt;

&lt;h2&gt;Auto Mocking using FakeItEasy&lt;/h2&gt;

&lt;p&gt;To install AutoFixture with Auto Mocking using FakeItEasy, run the following command in the Package Manager Console:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;PM&amp;gt; Install-Package AutoFixture.AutoFakeItEasy&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;We decorate the test method with AutoFakeItEasyData or InlineAutoFakeItEasyData attributes:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Theory]
[AutoFakeItEasyData]
[InlineAutoFakeItEasyData(2)]
[InlineAutoFakeItEasyData(3, &amp;quot;foo&amp;quot;)]
public void WithFakeItEasy(
    double d, string s, IInterface i, AbstractType a)
{
    Write(d, s, i, a);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Output:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='xml'&gt;AutoFakeItEasyData:
  d = 1
  s = s2b4c118b-d18b-4782-992a-d4138c65fd2a
  i = Faked IInterface
  a = Faked AbstractType

InlineAutoFakeItEasyData:
  d = 2
  s = se8da7e09-ea4f-4d16-86bd-4229802e5f5d
  i = Faked IInterface
  a = Faked AbstractType

InlineAutoFakeItEasyData:
  d = 3
  s = foo
  i = Faked IInterface
  a = Faked AbstractType&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Source code:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;internal class AutoFakeItEasyDataAttribute : AutoDataAttribute
{
    internal AutoFakeItEasyDataAttribute()
        : base(new Fixture().Customize(new AutoFakeItEasyCustomization()))
    {
    }
}

internal class InlineAutoFakeItEasyDataAttribute : CompositeDataAttribute
{
    internal InlineAutoFakeItEasyDataAttribute(params object[] values)
        : base(new DataAttribute[] { 
            new InlineDataAttribute(values), new AutoFakeItEasyDataAttribute() })
    {
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;More information on AutoFixture with Auto Mocking using FakeItEasy can be found at &lt;a href=&quot;http://nikosbaxevanis.com/2011/12/14/auto-mocking-with-fakeiteasy-and-autofixture/&quot;&gt;Auto-Mocking with FakeItEasy and AutoFixture&lt;/a&gt; blog post.&lt;/p&gt;
</description>
			<pubDate>Tue, 31 Jul 2012 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Composite xUnit.net Data Attributes</title>
			<link>http://nikosbaxevanis.com/2012/07/27/composite-xunit-net-data-attributes</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2012/07/27/composite-xunit-net-data-attributes</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;&lt;a href=&quot;http://xunit.codeplex.com/&quot;&gt;xUnit.net&lt;/a&gt; &lt;a href=&quot;http://nuget.org/packages/xunit.extensions&quot;&gt;extensions&lt;/a&gt; support data-driven tests called &lt;a href=&quot;http://xunit.codeplex.com/wikipage?title=Comparisons#note4&quot;&gt;Theories&lt;/a&gt;. Such tests are similar to regular xUnit.net tests but instead of being decorated with &lt;code&gt;[Fact]&lt;/code&gt; they are decorated with &lt;code&gt;[Theory]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Below is a data-driven test with the data coming a Microsoft Excel (.xls) spreadsheet.&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Theory]
[ExcelData(&amp;quot;UnitTestData.xls&amp;quot;, &amp;quot;SELECT x, y FROM Data&amp;quot;)]
public void Foo(object x, object y)
{
    // 'x' and 'y' are values from the .xls spreadsheet.
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Also, a data-driven test with the data coming from a type implementing the IEnumerable&amp;lt;object[]&gt;.&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Theory]
[ClassData(typeof(CollectionOfSpecifiedString))]
public void Bar(object x, object y)
{
    // 'x' and 'y' are values from the IEnumerable&amp;lt;object[]&amp;gt; type.
}

internal class CollectionOfSpecifiedString : IEnumerable&amp;lt;object[]&amp;gt;
{
    public IEnumerator&amp;lt;object[]&amp;gt; GetEnumerator()
    {
        yield return new object[]
        {
            &amp;quot;foo&amp;quot;, &amp;quot;zoo&amp;quot;
        };
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return this.GetEnumerator();
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;In the above samples, &lt;code&gt;[ExcelData]&lt;/code&gt; and &lt;code&gt;[ClassData]&lt;/code&gt; are attributes representing a data source for a data-driven test.&lt;/p&gt;

&lt;h2&gt;Using data from multiple attributes&lt;/h2&gt;

&lt;p&gt;Below is a data-driven test with the data coming from a type implementing the IEnumerable&amp;lt;object[]&gt; combined with the data coming from an .xls spreadsheet.&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Theory]
[ClassExcelData(
    typeof(CollectionOfSpecifiedString),
    &amp;quot;UnitTestData.xls&amp;quot;, &amp;quot;SELECT x, y FROM Data&amp;quot;)]
public void Zoo(object x, object y)
{
    // 'x' is coming from the IEnumerable&amp;lt;object[]&amp;gt; type.
    // 'y' is coming from the .xls spreadsheet.
}

internal class CollectionOfSpecifiedString : IEnumerable&amp;lt;object[]&amp;gt;
{
    public IEnumerator&amp;lt;object[]&amp;gt; GetEnumerator()
    {
        yield return new object[]
        {
            &amp;quot;foo&amp;quot;
        };
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return this.GetEnumerator();
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h2&gt;Creating a composite attribute&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;[ClassExcelData]&lt;/code&gt; from the previous example is a &lt;a href=&quot;http://en.wikipedia.org/wiki/Composite_pattern&quot;&gt;composite&lt;/a&gt; of two xUnit.net&amp;rsquo;s data attributes &lt;code&gt;[ClassData]&lt;/code&gt; and &lt;code&gt;[ExcelData]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;All we have to do is create a type deriving from &lt;code&gt;CompositeDataAttribute&lt;/code&gt;, passing in its base constructor an array of the data attributes we would like to compose.&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
internal class ClassExcelDataAttribute : CompositeDataAttribute
{
    internal ClassExcelDataAttribute(Type type, string filename, string selectStatement)
        : base(new DataAttribute[] { 
                new ClassDataAttribute(type), 
                new ExcelDataAttribute(filename, selectStatement) })
    {
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;The description for the &lt;code&gt;CompositeDataAttribute&lt;/code&gt; algorithm can be found &lt;a href=&quot;http://nikosbaxevanis.com/2011/08/25/combining-data-theories-in-autofixture-xunit-extension/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;When defining a composite data attribute, it is acceptable for the first attribute to provide some (or all) data for the parameters of the test method. However, subsequent data attributes must be able to provide the data for the exact position where the previous attribute stopped.&lt;/p&gt;&lt;/blockquote&gt;

&lt;h2&gt;Obtaining the CompositeDataAttribute class&lt;/h2&gt;

&lt;p&gt;CompositeDataAttribute is currently bundled with &lt;a href=&quot;https://github.com/AutoFixture/AutoFixture&quot;&gt;AutoFixture&lt;/a&gt; &lt;a href=&quot;http://feed.nuget.org/packages/AutoFixture.Xunit&quot;&gt;extension&lt;/a&gt; for xUnit.net. You can use it by installing the &lt;a href=&quot;http://feed.nuget.org/packages/AutoFixture.Xunit&quot;&gt;AutoFixture.Xunit NuGet package&lt;/a&gt;.&lt;/p&gt;
</description>
			<pubDate>Fri, 27 Jul 2012 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Using the Web API Dependency Resolver with Castle Windsor's Scoped Lifetime</title>
			<link>http://nikosbaxevanis.com/2012/07/16/using-the-web-api-dependency-resolver-with-castle-windsor-scoped-lifetime</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2012/07/16/using-the-web-api-dependency-resolver-with-castle-windsor-scoped-lifetime</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: &lt;a href=&quot;http://blog.ploeh.dk/&quot;&gt;Mark Seemann&lt;/a&gt; has provided a &lt;a href=&quot;http://blog.ploeh.dk/2012/10/03/DependencyInjectionInASPNETWebAPIWithCastleWindsor.aspx&quot;&gt;solution&lt;/a&gt; without using the IDependencyResolver interface.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;This post is the result of a very good &lt;a href=&quot;http://nikosbaxevanis.com/2012/06/04/using-the-web-api-dependency-resolver-with-castle-windsor-part-2/#comment-568630441&quot;&gt;suggestion&lt;/a&gt; in the comments section of the &lt;a href=&quot;http://nikosbaxevanis.com/2012/06/04/using-the-web-api-dependency-resolver-with-castle-windsor-part-2&quot;&gt;previous&lt;/a&gt; post.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;The WindsorDependencyScope from the previous post has been modified to use the Scoped lifetime &lt;a href=&quot;http://docs.castleproject.org/Windsor.Whats-New-In-Windsor-3.ashx#Added_two_new_lifestyles:_scoped_and_bound_2&quot;&gt;available&lt;/a&gt; in Castle Windsor 3.&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http.Dependencies;
using Castle.MicroKernel.Lifestyle;
using Castle.Windsor;

internal sealed class WindsorDependencyScope : IDependencyScope
{
    private readonly IWindsorContainer container;
    private readonly IDisposable scope;

    public WindsorDependencyScope(IWindsorContainer container)
    {
        if (container == null)
        {
            throw new ArgumentNullException(&amp;quot;container&amp;quot;);
        }

        this.container = container;
        this.scope = container.BeginScope();
    }

    public object GetService(Type t)
    {
        return this.container.Kernel.HasComponent(t) ? this.container.Resolve(t) : null;
    }

    public IEnumerable&amp;lt;object&amp;gt; GetServices(Type t)
    {
        return this.container.ResolveAll(t).Cast&amp;lt;object&amp;gt;().ToArray();
    }

    public void Dispose()
    {
        this.scope.Dispose();
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;The &lt;code&gt;BeginScope&lt;/code&gt; is an extension method for the &lt;code&gt;IWindsorContainer&lt;/code&gt; type. It returns by default an instance of a &lt;code&gt;CallContextLifetimeScope&lt;/code&gt; type. It uses the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.runtime.remoting.messaging.callcontext.aspx&quot;&gt;Call Context&lt;/a&gt; so it can be associated with thread pool threads and manually created threads within a &lt;em&gt;single&lt;/em&gt; AppDomain (it does not use the &lt;em&gt;Logical&lt;/em&gt; Call Context).&lt;/p&gt;

&lt;p&gt;On each request the Web API calls the &lt;a href=&quot;http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/a1b7c04f7227#src%2fSystem.Web.Http%2fHttpRequestMessageExtensions.cs&quot;&gt;GetDependencyScope&lt;/a&gt; extension method of the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.net.http.httprequestmessage.aspx&quot;&gt;HttpRequestMessage&lt;/a&gt; type, which, in return, calls it&amp;rsquo;s own &lt;a href=&quot;http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/a1b7c04f7227#src%2fSystem.Web.Http%2fDependencies%2fIDependencyResolver.cs&quot;&gt;BeginScope&lt;/a&gt; method to start a new resolution scope. Using our own implementation of the &lt;a href=&quot;http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/a1b7c04f7227#src%2fSystem.Web.Http%2fDependencies%2fIDependencyResolver.cs&quot;&gt;IDependencyResolver&lt;/a&gt; interface we always return a new instance of the WindsorDependencyScope type.&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;internal sealed class WindsorDependencyResolver : IDependencyResolver
{    
    // 'using' Directives and other type members removed for brevity.
    
    public IDependencyScope BeginScope()
    {
        return new WindsorDependencyScope(this.container);
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Since we use the Scoped lifetime we need to define it also in the registration code. Then, we will always have at most one instance of each requested type per resolution scope (that is, a request).&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;internal sealed class WebWindsorInstaller : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container.Register(Classes
            .FromAssemblyContaining&amp;lt;ValuesController&amp;gt;()
            .BasedOn&amp;lt;IHttpController&amp;gt;()
            .LifestyleScoped());
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;The source code can be found &lt;a href=&quot;http://nikosbaxevanis.com/downloads/WebApiScopedLifetimeDependencyResolverSample.zip&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
</description>
			<pubDate>Mon, 16 Jul 2012 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Using the Web API Dependency Resolver with Castle Windsor (Part 2)</title>
			<link>http://nikosbaxevanis.com/2012/06/04/using-the-web-api-dependency-resolver-with-castle-windsor-part-2</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2012/06/04/using-the-web-api-dependency-resolver-with-castle-windsor-part-2</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: &lt;a href=&quot;http://blog.ploeh.dk/&quot;&gt;Mark Seemann&lt;/a&gt; has provided a &lt;a href=&quot;http://blog.ploeh.dk/2012/10/03/DependencyInjectionInASPNETWebAPIWithCastleWindsor.aspx&quot;&gt;solution&lt;/a&gt; without using the IDependencyResolver interface.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;The code in this post requires the ASP.NET MVC 4 RC. If you use the Beta version use the code from &lt;a href=&quot;http://nikosbaxevanis.com/2012/03/16/using-the-web-api-dependency-resolver-with-castle-windsor/&quot;&gt;this&lt;/a&gt; post.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Among the many changes in ASP.NET MVC 4 RC, there is now added support for releasing object graphs, resolved on each request, using dependency scopes.&lt;/p&gt;

&lt;h2&gt;Creating a dependency scope per request&lt;/h2&gt;

&lt;p&gt;Since the IHttpControllerFactory interface has been &lt;a href=&quot;http://aspnetwebstack.codeplex.com/SourceControl/network/forks/jongalloway/aspnetwebstack/changeset/changes/f6a7f35302ba&quot;&gt;removed&lt;/a&gt;, the recommendation (from the &lt;a href=&quot;http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253817&quot;&gt;release notes&lt;/a&gt;) is to use the &lt;a href=&quot;http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/a1b7c04f7227#src%2fSystem.Web.Http%2fDispatcher%2fIHttpControllerSelector.cs&quot;&gt;IHttpControllerSelector&lt;/a&gt; interface to control &lt;a href=&quot;http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/a1b7c04f7227#src%2fSystem.Web.Http%2fControllers%2fIHttpController.cs&quot;&gt;IHttpController&lt;/a&gt; selection and the &lt;a href=&quot;http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/a1b7c04f7227#src%2fSystem.Web.Http%2fDispatcher%2fIHttpControllerActivator.cs&quot;&gt;IHttpControllerActivator&lt;/a&gt; interface to control IHttpController activation.&lt;/p&gt;

&lt;p&gt;Below is the IHttpControllerSelector interface:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public interface IHttpControllerSelector
{
    HttpControllerDescriptor SelectController(HttpRequestMessage request);
}

// Other methods removed for brevity.&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;And the IHttpControllerActivator interface:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public interface IHttpControllerActivator
{
    IHttpController Create(
        HttpRequestMessage request, 
        HttpControllerDescriptor controllerDescriptor, 
        Type controllerType);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Both interfaces contain method(s) accepting, among others, an &lt;a href=&quot;http://goo.gl/jsUg2&quot;&gt;HttpRequestMessage&lt;/a&gt;. The trick here is to use the HttpRequestMessage&amp;rsquo;s extension method &lt;a href=&quot;http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/a1b7c04f7227#src%2fSystem.Web.Http%2fHttpRequestMessageExtensions.cs&quot;&gt;GetDependencyScope&lt;/a&gt; for resolving controllers (instead of using a DI Container directly).&lt;/p&gt;

&lt;p&gt;Internally, the GetDependencyScope method uses the DependencyResolver (registered in the GlobalConfiguration instance) calling it&amp;rsquo;s &lt;a href=&quot;http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/a1b7c04f7227#src%2fSystem.Web.Http%2fDependencies%2fIDependencyResolver.cs&quot;&gt;BeginScope&lt;/a&gt; method which &lt;strong&gt;creates a new resolution scope&lt;/strong&gt;. Objects that are resolved in that scope are tracked internally. Once the scope is disposed, those objects are released (using the container&amp;rsquo;s Release method).&lt;/p&gt;

&lt;p&gt;Below is an implementation of the IDependencyScope interface:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http.Dependencies;

internal class ReleasingDependencyScope : IDependencyScope
{
    private readonly IDependencyScope scope;
    private readonly Action&amp;lt;object&amp;gt; release;
    private readonly List&amp;lt;object&amp;gt; instances;

    public WindsorDependencyScope(IDependencyScope scope, Action&amp;lt;object&amp;gt; release)
    {
        if (scope == null)
        {
            throw new ArgumentNullException(&amp;quot;scope&amp;quot;);
        }

        if (release == null)
        {
            throw new ArgumentNullException(&amp;quot;release&amp;quot;);
        }

        this.scope = scope;
        this.release = release;
        this.instances = new List&amp;lt;object&amp;gt;();
    }

    public object GetService(Type t)
    {
        object service = this.scope.GetService(t);
        this.AddToScope(service);

        return service;
    }

    public IEnumerable&amp;lt;object&amp;gt; GetServices(Type t)
    {
        var services = this.scope.GetServices(t);
        this.AddToScope(services);

        return services;
    }

    public void Dispose()
    {
        foreach (object instance in this.instances)
        {
            this.release(instance);
        }
            
        this.instances.Clear();
    }

    private void AddToScope(params object[] services)
    {
        if (services.Any())
        {
            this.instances.AddRange(services);
        }
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Having a custom implementation of the &lt;a href=&quot;http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/a1b7c04f7227#src%2fSystem.Web.Http%2fDependencies%2fIDependencyScope.cs&quot;&gt;IDependencyScope&lt;/a&gt; interface, we can now move on with the implementation of the &lt;a href=&quot;http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/a1b7c04f7227#src%2fSystem.Web.Http%2fDependencies%2fIDependencyResolver.cs&quot;&gt;IDependencyResolver&lt;/a&gt; interface. The recommendation (from the &lt;a href=&quot;http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/a1b7c04f7227#src%2fSystem.Web.Http%2fDependencies%2fIDependencyResolver.cs&quot;&gt;source code&lt;/a&gt;) is to return a new instance of IDependencyScope every time the BeginScope method is called.&lt;/p&gt;

&lt;p&gt;An implementation of the IDependencyResolver interface for Castle Windsor could be similar to the one below:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http.Dependencies;
using Castle.Windsor;

internal class WindsorDependencyResolver : IDependencyResolver
{
    private readonly IWindsorContainer container;

    public WindsorDependencyResolver(IWindsorContainer container)
    {
        if (container == null)
        {
            throw new ArgumentNullException(&amp;quot;container&amp;quot;);
        }

        this.container = container;
    }

    public object GetService(Type t)
    {
        return this.container.Kernel.HasComponent(t) ? this.container.Resolve(t) : null;
    }

    public IEnumerable&amp;lt;object&amp;gt; GetServices(Type t)
    {
        return this.container.ResolveAll(t).Cast&amp;lt;object&amp;gt;().ToArray();
    }

    public IDependencyScope BeginScope()
    {
        return new ReleasingDependencyScope(this, this.container.Release);
    }

    public void Dispose()
    {
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;As we can see, the BeginScope method returns a new instance of IDependencyScope which can resolve and release objects that belong to that scope.&lt;/p&gt;

&lt;p&gt;Moving next, when upgrading from Beta to RC there &lt;em&gt;might&lt;/em&gt; be another thing to consider. Since the IHttpControllerFactory interface has now been removed, implementations of that interface were using the &lt;em&gt;controllerName&lt;/em&gt; in order to resolve component instances from the DI Containers. As a result, controllers were registered in the DI Containers using names for each registration.&lt;/p&gt;

&lt;p&gt;To keep the &lt;em&gt;named&lt;/em&gt; registrations (and not break compatibility with any JavaScript clients) we can create a &lt;a href=&quot;http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/a1b7c04f7227#src%2fSystem.Web.Http%2fDispatcher%2fDefaultHttpControllerSelector.cs&quot;&gt;DefaultHttpControllerSelector&lt;/a&gt; derived type and override it&amp;rsquo;s SelectController method. We can then use the DefaultHttpControllerSelector&amp;rsquo;s GetControllerName method which returns the requested path name &lt;em&gt;(e.g. &amp;ldquo;Orders&amp;rdquo;)&lt;/em&gt;. At that point we can map that name to an &lt;a href=&quot;http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/a1b7c04f7227#src%2fSystem.Web.Http%2fApiController.cs&quot;&gt;ApiController&lt;/a&gt; derived type &lt;em&gt;(ex.: OrderController)&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;A DefaultHttpControllerSelector derived type could be similar to the one below:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;using System;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Dispatcher;

internal class PluralizedNameHttpControllerSelector : DefaultHttpControllerSelector
{
    private readonly HttpConfiguration configuration;
    private readonly Assembly controllerAssembly;

    public PluralizedNameHttpControllerSelector(
        HttpConfiguration configuration, Assembly controllerAssembly)
        : base(configuration)
    {
        if (configuration == null)
        {
            throw new ArgumentNullException(&amp;quot;configuration&amp;quot;);
        }
            
        if (controllerAssembly == null)
        {
            throw new ArgumentNullException(&amp;quot;controllerAssembly&amp;quot;);
        }

        this.configuration = configuration;
        this.controllerAssembly = controllerAssembly;
    }

    public override HttpControllerDescriptor SelectController(
        HttpRequestMessage request)
    {
        var controllerName = base.GetControllerName(request);
        var controllerType = this.GetControllerType(controllerName);

        return new HttpControllerDescriptor(
            this.configuration, controllerName, controllerType);
    }

    private Type GetControllerType(string name)
    {
        // Look in 'this.controllerAssembly' and find the types that can be
        // assigned from an instance of IHttpController  and return the one
        // whose name matches with the given name.
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;blockquote&gt;&lt;p&gt;Make sure to register the above type in Castle Windsor otherwise the framework will pick it&amp;rsquo;s default implementation.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;All the above information is the result of browsing the source code on CodePlex. If any  articles or blog posts are released (by the ASP.NET team or individuals) I might create a new post with updates, if necessary.&lt;/p&gt;
</description>
			<pubDate>Mon, 04 Jun 2012 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Migrating from a blogging service to Jekyll and GitHub</title>
			<link>http://nikosbaxevanis.com/2012/05/25/migrating-from-a-blogging-service-to-jekyll-and-github</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2012/05/25/migrating-from-a-blogging-service-to-jekyll-and-github</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Since 2010, and until a week ago, I had my site powered up and hosted by a paid &lt;strong&gt;blogging service&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;good&lt;/strong&gt; thing with (paid) blogging services is that they handle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Storage for posts&lt;/li&gt;
&lt;li&gt;Storage for comments&lt;/li&gt;
&lt;li&gt;Atom and/or RSS feeds&lt;/li&gt;
&lt;li&gt;Support for social networking services&lt;/li&gt;
&lt;li&gt;Site analytics&lt;/li&gt;
&lt;li&gt;Themes&lt;/li&gt;
&lt;li&gt;Customisation&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;The &lt;strong&gt;bad&lt;/strong&gt; thing with blogging services is that they own your content and are very limited when it comes to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Access the files via FTP client(s).&lt;/li&gt;
&lt;li&gt;Backup/Export posts&lt;/li&gt;
&lt;li&gt;Backup/Export comments&lt;/li&gt;
&lt;li&gt;Customise the creation of web feeds&lt;/li&gt;
&lt;li&gt;Add new social networking services&lt;/li&gt;
&lt;li&gt;Add new themes&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;I believe that nowadays all the above stuff is trivial so it should be done in very simple way.&lt;/p&gt;

&lt;p&gt;Thus, one &lt;strong&gt;should be able&lt;/strong&gt; to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Compose posts on &lt;a href=&quot;http://dillinger.io/&quot; title=&quot;Dillinger is a cloud-enabled HTML5 Markdown editor.&quot;&gt;Dillinger&lt;/a&gt;, &lt;a href=&quot;http://markdownpad.com/&quot; title=&quot;MarkdownPad is a full-featured Markdown editor for Windows.&quot;&gt;MarkdownPad&lt;/a&gt; or even &lt;a href=&quot;http://www.flos-freeware.ch/notepad2.html&quot; title=&quot;A fast and light-weight Notepad-like text editor with syntax highlighting. This program can be run out of the box without installation, and does not touch your system's registry.&quot;&gt;Notepad2&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Customize and style a site using open source templating systems, markdown engines and syntax highlighting tools.&lt;/li&gt;
&lt;li&gt;Host the generated output on any web server.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Furthermore, I do believe that in the future we will use (&lt;strong&gt;even more&lt;/strong&gt;):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Twitter for social networking and microblogging.&lt;/li&gt;
&lt;li&gt;GitHub for open source and commercial closed source project hosting.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;With all the above and since GitHub allows for publishing web content I decided to move into that direction. The migration was successful.&lt;/p&gt;

&lt;p&gt;This site is now powered by &lt;a href=&quot;https://github.com/mojombo/jekyll&quot; title=&quot;Jekyll is a blog-aware, static site generator in Ruby&quot;&gt;Jekyll&lt;/a&gt;. Using &lt;a href=&quot;http://github.com/tsmango/jekyll_alias_generator&quot;&gt;this&lt;/a&gt; plugin I was able to keep all the old permalinks and redirect to the new ones.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;The only &lt;a href=&quot;https://github.com/mojombo/jekyll/issues/325&quot;&gt;limitation&lt;/a&gt; I came across is that GitHub runs Jekyll with the &amp;mdash;safe switch and it will not load any custom plugins (for security reasons). However, one can run the site locally and copy the output that is being generated by the plugin and include it in the source.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Some key &lt;strong&gt;highlights&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Posts can now be written using &lt;a href=&quot;http://en.wikipedia.org/wiki/Markdown&quot; title=&quot;Markdown is a lightweight markup language, originally created by John Gruber and Aaron Swartz allowing people to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML or HTML.&quot;&gt;Markdown&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The site can be previewed locally by installing the Jekyll  &lt;a href=&quot;http://rubygems.org/gems/jekyll&quot;&gt;Gem&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The creation of web feeds is highly customisable.&lt;/li&gt;
&lt;li&gt;The format of &lt;a href=&quot;https://github.com/mojombo/jekyll/wiki/Permalinks&quot;&gt;permalinks&lt;/a&gt; is very flexible.&lt;/li&gt;
&lt;li&gt;On each push, GitHub transforms the code (using Jekyll) into a static site.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;I like it pretty good, let&amp;rsquo;s see how it goes.&lt;/p&gt;
</description>
			<pubDate>Fri, 25 May 2012 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>xUnit.net and AsyncEnumerator to Async and Await</title>
			<link>http://nikosbaxevanis.com/2012/05/06/xunit-net-and-asyncenumerator-to-async-and-await</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2012/05/06/xunit-net-and-asyncenumerator-to-async-and-await</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Prior to .NET 4,&amp;#0160;one had to implement the &lt;a href=&quot;http://msdn.microsoft.com/en-us/magazine/cc163467.aspx&quot; target=&quot;_blank&quot; title=&quot;Implementing the CLR Asynchronous Programming Model.&quot;&gt;APM&lt;/a&gt; model in order to expose asynchronous methods. After a couple of years, the&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-gb/magazine/cc546608.aspx&quot; target=&quot;_blank&quot; title=&quot;Simplified APM With The AsyncEnumerator.&quot;&gt;AsyncEnumerator&lt;/a&gt;&amp;#0160;class came out to&amp;#0160;simplify the APM by leveraging the use&amp;#0160;of C# iterators for asynchrony. In the meantime,&amp;#0160;Microsoft developed a&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/dd460693.aspx&quot; target=&quot;_blank&quot; title=&quot;Parallel Programming in the .NET Framework.&quot;&gt;new&lt;/a&gt;&amp;#0160;model for asynchronous (and parallel) programming. Since the new model was targeting the&amp;#0160;.NET 4, code written in previous versions have to keep using the AsyncEnumerator class.&lt;/p&gt;


&lt;p&gt;I&amp;#0160;&lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2010/10/an-alternative-net-20-approach-to-the-task-based-asynchronous-pattern.html&quot; target=&quot;_blank&quot; title=&quot;An alternative (.NET 2.0+) approach to the Task-based Asynchronous Pattern.&quot;&gt;have&lt;/a&gt;&amp;#0160;&lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2011/07/async-rest-client-for-scrumy-api.html&quot; target=&quot;_blank&quot; title=&quot;Async REST Client for the Scrumy API.&quot;&gt;been&lt;/a&gt;&amp;#0160;&lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2010/11/going-asynchronous-with-sterling-for-windows-phone-7.html&quot; target=&quot;_blank&quot; title=&quot;Going Asynchronous with Sterling for Windows Phone 7.&quot;&gt;using&lt;/a&gt;&amp;#0160;&lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2010/10/exposing-asynchronous-features-to-client-code-windows-phone-edition.html&quot; target=&quot;_blank&quot; title=&quot;Exposing asynchronous features to client code: Windows Phone 7.&quot;&gt;the&lt;/a&gt;&amp;#0160;AsyncEnumerator class since 2008 and it works great. Today we have the new Async and Await keywords in C# 5.0 (together with the &lt;a href=&quot;http://blogs.microsoft.co.il/blogs/sasha/archive/2011/09/17/improvements-in-the-clr-core-in-net-framework-4-5.aspx&quot; target=&quot;_blank&quot;&gt;many&lt;/a&gt; &lt;a href=&quot;http://blogs.msdn.com/b/dotnet/archive/2011/10/03/large-object-heap-improvements-in-net-4-5.aspx&quot; target=&quot;_blank&quot;&gt;improvements&lt;/a&gt;&amp;#0160;in the CLR) that will ship with .NET 4.5 and the recently added support for&amp;#0160;async unit tests on&amp;#0160;&lt;a href=&quot;http://xunit.codeplex.com/releases/view/77573&quot; target=&quot;_blank&quot;&gt;version 1.9&lt;/a&gt;&amp;#0160;of the&amp;#0160;&lt;a href=&quot;http://xunit.codeplex.com/&quot; target=&quot;_blank&quot; title=&quot;xUnit.net is a unit testing tool for the .NET Framework. Written by the original inventor of NUnit, xUnit.net is the latest technology for unit testing C#, F#, VB.NET and other .NET languages.&quot;&gt;xUnit.net&lt;/a&gt;.&amp;#0160;So, I decided to move some .NET 2.0 code using AsyncEnumerator to .NET 4.5 using Async and Await.&lt;/p&gt;


&lt;p&gt;Below is an interface of the sample type (described in &lt;a href=&quot;http://msdn.microsoft.com/en-us/magazine/cc163467.aspx&quot; target=&quot;_blank&quot; title=&quot;Implementing the CLR Asynchronous Programming Model.&quot;&gt;this&lt;/a&gt; article) exposing both synchronous and asynchronous versions of a time-consuming method:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public interface IMyType
{
    // Synchronous version of time-consuming method.
    DateTime DoSomething();

    // Asynchronous version of time-consuming method (Begin part).
    IAsyncResult BeginDoSomething(AsyncCallback callback, object state = null);

    // Asynchronous version of time-consuming method (End part).
    DateTime EndDoSomething(IAsyncResult asyncResult);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;A unit test with the AsyncEnumerator can be similar to the one shown below:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public IEnumerator&amp;lt;int&amp;gt; D(AsyncEnumerator ae)
{
    var sut = new MyType(5);

    sut.BeginDoSomething(ae.End(), state: null);
    yield return 1;
    var result = sut.EndDoSomething(ae.DequeueAsyncResult());
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;However, since xUnit.net does not support methods of type IEnumerator&amp;lt;int&amp;gt;, we need to tell xUnit.net how to execute them:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Fact]
public void D()
{
    // Drive the D method's iterator asynchronously.
    var ae = new AsyncEnumerator&amp;lt;DateTime&amp;gt;();
    ae.EndExecute(
        ae.BeginExecute(
            this.D(ae), _ =&amp;gt; { }));
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Moving to .NET 4.5 and xUnit.net 1.9 we can create an &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/bb383977.aspx&quot; target=&quot;_blank&quot; title=&quot;Extension methods enable you to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type.&quot;&gt;Extension Method&lt;/a&gt; that returns a &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.threading.tasks.task.aspx&quot; target=&quot;_blank&quot; title=&quot;Represents an asynchronous operation.&quot;&gt;Task&lt;/a&gt; in order to use both the Async and Await keywords in production code and the async unit tests feature of xUnit.net.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;// Task-based asynchronous version of time-consuming method.
public static Task&amp;lt;DateTime&amp;gt; DoSomethingAsync(this IMyType t)
{
    return Task&amp;lt;DateTime&amp;gt;.Factory.FromAsync(
        t.BeginDoSomething,
        t.EndDoSomething,
        state: null
        );
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Now the previous unit test with the AsyncEnumerator can be rewritten as follow:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Fact]
public async Task D()
{
    var sut = new MyType(5);
    var result = await sut.DoSomethingAsync();
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;This looks very nice and clean. As it seems though, if the class contains many async unit tests they will not run in parallel.&amp;#0160;&lt;/p&gt;


&lt;p&gt;As an example, the following 3 tests will take 3 x 5 = 15 seconds to complete:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Fact]
public async Task A()
{
    var sut = new MyType(5);
    var result = await sut.DoSomethingAsync();
}

[Fact]
public async Task B()
{
    var sut = new MyType(5);
    var result = await sut.DoSomethingAsync();
}

[Fact]
public async Task C()
{
    var sut = new MyType(5);
    var result = await sut.DoSomethingAsync();
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;The output from xUnit.net:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;Output from AsyncUnitTesting.xUnit.net.MyTypeTests.C:
  Started  5/5/2012 10:24:45 AM
  Finished 5/5/2012 10:24:50 AM

Output from AsyncUnitTesting.xUnit.net.MyTypeTests.B:
  Started  5/5/2012 10:24:50 AM
  Finished 5/5/2012 10:24:55 AM

Output from AsyncUnitTesting.xUnit.net.MyTypeTests.A:
  Started  5/5/2012 10:24:50 AM
  Finished 5/5/2012 10:25:00 AM

3 passed, 0 failed, 0 skipped, took 15.26 seconds (xUnit.net 1.9.0 build 1566).&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;That was the part of moving the unit tests from an older version of xUnit.net (and the AsyncEnumerator) to version 1.9 of xUnit.net (with Async and Await).&amp;#0160;Apparently, things become more challenging when moving to production code where one needs to deal with stuff such is the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.threading.synchronizationcontext(v=vs.110).aspx&quot; target=&quot;_blank&quot; title=&quot;Provides the basic functionality for propagating a synchronization context in various synchronization models.&quot;&gt;SyncrhonizationContext&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;A gist with all the source code can be found&amp;#0160;&lt;a href=&quot;https://gist.github.com/2604956&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
			<pubDate>Sun, 06 May 2012 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>URI support in AutoFixture</title>
			<link>http://nikosbaxevanis.com/2012/04/19/uri-support-in-autofixture</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2012/04/19/uri-support-in-autofixture</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Starting with version 2.10.0, AutoFixture supports the creation of &lt;a href=&quot;http://en.wikipedia.org/wiki/Uniform_resource_identifier&quot; target=&quot;_blank&quot; title=&quot;In computing, a uniform resource identifier (URI) is a string of characters used to identify a name or a resource. Such identification enables interaction with representations of the resource over a network (typically the World Wide Web) using specific protocols. Schemes specifying a concrete syntax and associated protocols define each URI.&quot;&gt;Uniform Resource Identifiers&lt;/a&gt;&amp;#0160;and the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.uri(v=vs.90).aspx&quot; target=&quot;_blank&quot; title=&quot;Provides an object representation of a uniform resource identifier (URI) and easy access to the parts of the URI.&quot;&gt;Uri&lt;/a&gt;&amp;#0160;type.&lt;/p&gt;


&lt;p&gt;It is now possible to create an anonymous variable for Uri as with any other common type:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;var fixture = new Fixture();
var uri = fixture.CreateAnonymous&amp;lt;Uri&amp;gt;();
// Prints -&amp;gt; scheme://257eb39a-8305-4d13-a7cb-0c481b78809a/&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;By default, both the &lt;strong&gt;scheme name&lt;/strong&gt;&amp;#0160;and the &lt;strong&gt;authority&lt;/strong&gt;&amp;#0160;part are obtained from the context. A custom&amp;#0160;&lt;em&gt;UriScheme&lt;/em&gt; class represents the URI scheme name while the authority&amp;#0160;part is an anonymous variable of type string.&lt;/p&gt;


&lt;p&gt;Example URIs along with their component parts can be found&amp;#0160;&lt;a href=&quot;http://en.wikipedia.org/wiki/URI_scheme#Examples&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&amp;#0160;Since both parts are received from the context, they can be easily customized.&lt;/p&gt;


&lt;h2&gt;Supplying a custom scheme name&lt;/h2&gt;

&lt;p&gt;The UriScheme type provides by default the name &lt;em&gt;&amp;quot;scheme&amp;quot;.&lt;/em&gt;&amp;#0160;However, by injecting a specific instance of this type we can easily override it with something else (e.g. &amp;quot;&lt;em&gt;http&amp;quot;&lt;/em&gt;).&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;var fixture = new Fixture();
fixture.Inject(new UriScheme(&amp;quot;http&amp;quot;));
var uri = fixture.CreateAnonymous&amp;lt;Uri&amp;gt;(); 
// Prints -&amp;gt; http://abc9f406-16f2-4e06-b6f9-0750dc115ac3/&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h2&gt;Supplying a custom authority&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;This is preferred only when each test constructs its own instance of the Fixture type since this change will apply for all the strings received from the context.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;Since the authority part is a string received from the context, it is possible to modify the base of all strings and get the desired name for the authority.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;var fixture = new Fixture();
fixture.Customizations.Add(
    new StringGenerator(() =&amp;gt; &amp;quot;autofixture.codeplex.com&amp;quot;));
var uri = fixture.CreateAnonymous&amp;lt;Uri&amp;gt;(); 
// Prints -&amp;gt; scheme://autofixture.codeplex.com/&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h2&gt;Supplying a custom Uri&lt;/h2&gt;

&lt;p&gt;As with any other generated specimen, it is possible to completely take over it&amp;#39;s creation. Using a custom&amp;#0160;ISpecimenBuilder type, each time a Uri is requested, a predefined Uri will be returned.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public class CustomUriBuilder : ISpecimenBuilder
{
    public object Create(object request, ISpecimenContext context)
    {
        if (request == typeof(Uri))
        {
            return new Uri(&amp;quot;http://autofixture.codeplex.com&amp;quot;);
        }

        return new NoSpecimen(request);
    }
}

var fixture = new Fixture();
fixture.Customizations.Add(new CustomUriBuilder());
var uri = fixture.CreateAnonymous&amp;lt;Uri&amp;gt;(); 
// Prints -&amp;gt; http://autofixture.codeplex.com/&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;An automatically published release created from the latest successful build can be downloaded from&amp;#0160;&lt;a href=&quot;http://autofixture.codeplex.com/releases/view/85801&quot; target=&quot;_blank&quot; title=&quot;AutoFixture - Downloads&quot;&gt;here&lt;/a&gt;.&amp;#0160;The latest version is also live on&amp;#0160;&lt;a href=&quot;http://nuget.org/List/Packages/AutoFixture&quot; target=&quot;_blank&quot; title=&quot;AutoFixture - Package&quot;&gt;NuGet&lt;/a&gt;.&lt;/p&gt;



</description>
			<pubDate>Thu, 19 Apr 2012 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Extending A Legacy System to the Web</title>
			<link>http://nikosbaxevanis.com/2012/04/16/extending-a-legacy-system-to-the-web</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2012/04/16/extending-a-legacy-system-to-the-web</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;An ISV sells ordering and billing systems written in C/C++ and VB6. Each system is consisted of &lt;em&gt;two components&amp;#0160;&lt;/em&gt;and all&amp;#0160;&lt;em&gt;share &lt;/em&gt;a relational database&amp;#0160;containing Tables, Views and Stored Procedures.&lt;/p&gt;


&lt;h2&gt;A Legacy System&lt;/h2&gt;

&lt;p&gt;The &lt;em&gt;server&amp;#0160;&lt;/em&gt;component does the data&amp;#0160;&lt;em&gt;processing&lt;/em&gt;&lt;em&gt;, &lt;/em&gt;accepting &lt;strong&gt;commands&lt;/strong&gt; from the clients.&amp;#0160;The commands are stored inside a&amp;#0160;predefined directory&amp;#0160;in the form of ASCII-encoded text files.&amp;#0160;The legacy*&amp;#0160;command processor repeatedly checks for new text file availability. If a text file is available, it will be processed. This is a continuous process.&amp;#0160;The only way to update the database is to create and send a command which will be picked up and handled sequentially by the command processor.&amp;#0160;When a command is handled successfully, the system updates the shared database.&lt;/p&gt;


&lt;p&gt;The &lt;em&gt;client&amp;#0160;&lt;/em&gt;component connects to the shared &lt;strong&gt;database&lt;/strong&gt; (accessed in a &lt;strong&gt;read-only&lt;/strong&gt; fashion) to display data on screen and to send pre-defined commands. The client is either a VB6 GUI or a handheld radio device similar to &lt;a href=&quot;http://www.orderman.com/en/handhelds/don.html&quot; target=&quot;_blank&quot;&gt;this one&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8465/8398554626_4e1f7962c3_o.png&quot; alt=&quot;A legacy system&quot; /&gt;&lt;/p&gt;




&lt;p&gt;Nowdays, in order to reach the mobile market, it is quite difficult (and expensive) to maintain and expand the above client as-is. However, since each of the components has no knowledge of the other separate component,&amp;#0160;&lt;strong&gt;the client can be easily replaced&lt;/strong&gt;.&lt;/p&gt;


&lt;h2&gt;Moving to HTTP services&lt;/h2&gt;

&lt;p&gt;The new HTML5 client will consume HTTP services. A service here act as the entry point for creating the&amp;#0160;ASCII-encoded text files which will be picked up by the legacy command processor.&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8047/8397465951_247d62192f_o.png&quot; alt=&quot;Moving to HTTP services&quot; /&gt;&lt;/p&gt;




&lt;p&gt;When the application wants to submit data to be processed (by the legacy command processor) it sends a POST request. At this point, the new system creates a message which is send via a&amp;#0160;&lt;a href=&quot;http://www.eaipatterns.com/DatatypeChannel.html&quot; target=&quot;_blank&quot; title=&quot;By using a separate Datatype Channel for each type of data, all of the messages on a given channel will contain the same type of data. The sender, knowing what type the data is, will need to select the appropriate channel to send it on. The receiver, knowing what channel the data was received on, will know what its type is.&quot;&gt;Datatype Channel&lt;/a&gt;&amp;#0160;to its receiver.&lt;/p&gt;


&lt;p&gt;The receiver, of each particular message, forwards the processing of the command. A compatible text file is created, which will be picked up by the legacy command processor in order to update the database.&lt;/p&gt;


&lt;p&gt;When the application wants to&amp;#0160;retrieve data it sends a GET request. At that point, the&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.http.apicontroller(v=vs.108).aspx&quot; target=&quot;_blank&quot;&gt;ApiController&lt;/a&gt;&amp;#0160;uses a&amp;#0160;&lt;a href=&quot;http://martinfowler.com/eaaCatalog/gateway.html&quot; target=&quot;_blank&quot; title=&quot;An object that encapsulates access to an external system or resource.&quot;&gt;Gateway&lt;/a&gt;&amp;#0160;&lt;em&gt;(and internally&amp;#0160;&lt;a href=&quot;http://code.google.com/p/dapper-dot-net/&quot; target=&quot;_blank&quot; title=&quot;Dapper is a single file you can drop in to your project that will extend your IDbConnection interface. It is in production use at Stack Overflow.&quot;&gt;Dapper&lt;/a&gt;)&lt;/em&gt; to access the shared database.&lt;/p&gt;


&lt;p&gt;On refresh, the client sends a new GET request and the ApiController will return the updated data.&lt;/p&gt;


&lt;h2&gt;Moving to Smartphones, Tablets and HTML5&lt;/h2&gt;

&lt;p&gt;Now, the client&amp;#0160;part has to be&amp;#0160;&lt;em&gt;re-&lt;/em&gt;built with HTML5. That way, it will be accessible from the browser, Internet Tablets (similar to&amp;#0160;&lt;a href=&quot;http://www.archos.com/products/ta/archos_43it/index.html?country=us&amp;amp;lang=en&quot; target=&quot;_blank&quot;&gt;this one&lt;/a&gt;), and&amp;#0160;Smartphones.&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8324/8398554562_9909bb1f56_o.png&quot; alt=&quot;Moving to Smartphones, Tablets and HTML5&quot; /&gt;&lt;/p&gt;




&lt;p&gt;Initially,&amp;#0160;&lt;a href=&quot;http://www.sencha.com/products/touch&quot; target=&quot;_blank&quot; title=&quot;Sencha Touch is a user interface (UI) JavaScript library, or framework, specifically built for Mobile Web.&quot;&gt;Sencha Touch&lt;/a&gt;&amp;#0160;was a very good choice. &lt;span style=&quot;text-decoration: line-through;&quot;&gt;It even has a&amp;#0160;&lt;a href=&quot;http://www.sencha.com/blog/sencha-designer-2-beta-announcement&quot; target=&quot;_blank&quot;&gt;designer&lt;/a&gt;.&lt;/span&gt;&amp;#0160;There is even &lt;a href=&quot;http://www.sencha.com/products/architect/&quot; target=&quot;_blank&quot; title=&quot;A WYSIWYG IDE for Building Desktop and Mobile HTML5 Applications.&quot;&gt;Sencha Architect&lt;/a&gt;. Everything is written in JavaScript (which is good) and everything runs fast while testing on iPhone, iPad and other&amp;#0160;similar devices with fast hardware.&lt;/p&gt;


&lt;p&gt;The company however is willing to sell the final product to a price which includes the cost of the devices.&amp;#0160;(That is, a license for 5 users should also include the purchase of 5 mobile devices.) This&amp;#0160;means that the price for the devices can become orders of magnitude higher than the actual price of the application itself.&lt;/p&gt;


&lt;p&gt;The above lead to the fact that the application must ship with a&amp;#0160;&lt;em&gt;not-so-expensive&lt;/em&gt;&amp;#0160;device. After doing some testing and comparison with other devices, a Sencha Touch application did not perform smoothly in slower hardware (like&amp;#0160;&lt;a href=&quot;http://www.archos.com/products/ta/archos_43it/specs.html?country=us&amp;amp;lang=en&quot; target=&quot;_blank&quot;&gt;this one&lt;/a&gt;). (The most annoying part was the scrolling.)&lt;/p&gt;


&lt;p&gt;After trying&amp;#0160;&lt;a href=&quot;http://addyosmani.github.com/todomvc/&quot; target=&quot;_blank&quot; title=&quot;TodoMVC: A common learning application for popular JavaScript MV* frameworks.&quot;&gt;everything&lt;/a&gt;&amp;#0160;it looks like&amp;#0160;&lt;a href=&quot;http://jquerymobile.com/&quot; target=&quot;_blank&quot; title=&quot;jQuery Mobile: Touch-Optimized Web Framework for Smartphones &amp;amp; Tablets.&quot;&gt;jQuery Mobile&lt;/a&gt;&amp;#0160;combined with &lt;a href=&quot;http://mustache.github.com/&quot; target=&quot;_blank&quot; title=&quot;Logic-less templates.  Available in Ruby, JavaScript, Python, Erlang, PHP, Perl, Objective-C, Java, .NET, Android, C++, Go, Lua, ooc, ActionScript, ColdFusion, Scala, Clojure, Fantom, CoffeeScript, D, and for node.js.&quot;&gt;mustache&lt;/a&gt;&amp;#0160;are the best choices in terms of performance. The redistributable file is packed with&amp;#0160;&lt;a href=&quot;http://phonegap.com/&quot; target=&quot;_blank&quot; title=&quot;PhoneGap enables software programmers to build applications for mobile devices using JavaScript, HTML5 and CSS3, instead of lower-level languages.&quot;&gt;PhoneGap&lt;/a&gt;&amp;#0160;and&amp;#0160;the application performs well even on slower hardware giving the flexibility to select among a wide range of mobile devices.&lt;/p&gt;


&lt;p&gt;&lt;span style=&quot;font-size: 8pt;&quot;&gt;*&amp;quot;&lt;em&gt;Legacy&lt;/em&gt;&amp;quot; The definition that&amp;#0160;Michael C. Feathers gives in his excellent&amp;#0160;&lt;a href=&quot;http://www.amazon.com/Working-Effectively-Legacy-Michael-Feathers/dp/0131177052&quot; target=&quot;_blank&quot; title=&quot;Working Effectively with Legacy Code&quot;&gt;book&lt;/a&gt;.&lt;/span&gt;&lt;span style=&quot;font-size: 11px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;

</description>
			<pubDate>Mon, 16 Apr 2012 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Using the Web API Dependency Resolver with Castle Windsor</title>
			<link>http://nikosbaxevanis.com/2012/03/16/using-the-web-api-dependency-resolver-with-castle-windsor</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2012/03/16/using-the-web-api-dependency-resolver-with-castle-windsor</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;blockquote&gt;&lt;p&gt;The code in this post requires the ASP.NET MVC 4 Beta. If you use the RC version use the code from &lt;a href=&quot;http://nikosbaxevanis.com/2012/06/04/using-the-web-api-dependency-resolver-with-castle-windsor-part-2/&quot;&gt;this&lt;/a&gt; post.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: &lt;a href=&quot;http://blog.ploeh.dk&quot;&gt;Mark Seemann&lt;/a&gt; has provided a &lt;a href=&quot;http://blog.ploeh.dk/2012/03/20/RobustDIWithTheASPNETWebAPI.aspx&quot;&gt;great post&lt;/a&gt; on this subject.&lt;/p&gt;

&lt;p&gt;In this post I will discuss a possible solution for having Castle Windsor resolving types for both MVC controllers and Web API controllers. Since the former is well known I will focus mostly on the Web API part.&lt;/p&gt;


&lt;p&gt;A team building a mobile web application uses the&amp;nbsp;ASP.NET&amp;nbsp;MVC stack combined with another web services framework. With the release of the Beta version of&amp;nbsp;ASP.NET&amp;nbsp;MVC 4 they decided to give Web API a try (side by side with MVC controllers) and see if it fits their needs.&lt;/p&gt;


&lt;p&gt;The&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.aspx&quot; target=&quot;_blank&quot;&gt;Controller&lt;/a&gt;-derived types are used only for rendering the views (the code is written in JavaScript) while the&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.http.apicontroller(v=vs.108).aspx&quot; target=&quot;_blank&quot;&gt;ApiController&lt;/a&gt;-derived types are used for returning &amp;nbsp;data to the client.&lt;/p&gt;


&lt;p&gt;The&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.http.services.dependencyresolver(v=vs.108).aspx&quot; target=&quot;_blank&quot;&gt;DependencyResolver&lt;/a&gt;&amp;nbsp;class provides a method called&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/hh834083(v=vs.108).aspx&quot; target=&quot;_blank&quot;&gt;SetResolver&lt;/a&gt;&amp;nbsp;which acts as a registration point for resolving dependencies.&lt;/p&gt;


&lt;blockquote&gt;Be careful as there are more than one DependencyResolver types. One defined in System.Web.Mvc namespace and one defined in System.Web.Http namespace. We need the latter here.&lt;/blockquote&gt;


&lt;p&gt;Once we define the delegates and set a breakpoint we can see what types the framework requests.&lt;/p&gt;


&lt;p&gt;At first an instance of the IHttpControllerFactory type is requested:&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8506/8397459253_439417138a_o.png&quot; alt=&quot;IHttpControllerFactory type is requested&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Followed by a request for an instance of the ILogger type and so on.&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8073/8398547788_242021568e_o.png&quot; alt=&quot;ILogger type is requested&quot; /&gt;&lt;/p&gt;


&lt;p&gt;The first thing we want to do is to create a type implementing the IHttpControllerFactory interface.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Dispatcher;
using Castle.MicroKernel;

internal class WindsorHttpControllerFactory : IHttpControllerFactory
{
    private readonly HttpConfiguration configuration;
    private readonly IKernel kernel;

    public WindsorHttpControllerFactory(
        HttpConfiguration configuration, 
        IKernel kernel)
    {
        this.configuration = configuration;
        this.kernel = kernel;
    }

    public IHttpController CreateController(
        HttpControllerContext controllerContext, 
        string controllerName)
    {
        var controller = this.kernel.Resolve&amp;lt;IHttpController&amp;gt;(controllerName);

        controllerContext.Controller = controller;
        controllerContext.ControllerDescriptor = new HttpControllerDescriptor(
            this.configuration, 
            controllerName, 
            controller.GetType());

        return controllerContext.Controller;
    }

    public void ReleaseController(IHttpController controller)
    {
        this.kernel.ReleaseComponent(controller);
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Note that inside the WindsorHttpControllerFactory class the CreateController method&amp;nbsp;&amp;nbsp;takes a string for the name of the controller. That means we need to use the Windsor's&amp;nbsp;&lt;em&gt;Named&amp;nbsp;&lt;/em&gt;method to set a name for each controller registration. (We can also trim the &quot;Controller&quot; part from the name and also pluralize the remaining part.)&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;foreach (Type controller in typeof(OrderController).Assembly.GetTypes()
    .Where(type =&amp;gt; typeof(IHttpController).IsAssignableFrom(type)))
{
    // https://github.com/srkirkland/Inflector/
    string name = Inflector.Pluralize(
        controller.Name.Replace(&amp;quot;Controller&amp;quot;, &amp;quot;&amp;quot;));

    container.Register(Component
        .For(controller)
        .Named(name)
        .LifestylePerWebRequest());
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Let's also create a NullLogger implementing the ILogger interface.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;using System;
using System.Diagnostics;
using System.Web.Http.Common;

internal class NullLogger : ILogger
{
    public void Log(string category, TraceLevel level, 
        Func&amp;lt;string&amp;gt; messageCallback)
    {
    }

    public void LogException(string category, TraceLevel level, 
        Exception exception)
    {
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;For all the other instances that the framework requests there are default implementations in the System.Web.* assemblies and we can now create a Windsor&amp;nbsp;&lt;a href=&quot;http://stw.castleproject.org/Default.aspx?Page=Installers&amp;amp;NS=Windsor&amp;amp;AspxAutoDetectCookieSupport=1&quot; target=&quot;_blank&quot;&gt;Installer&lt;/a&gt;&amp;nbsp;to encapsulate the registration logic.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;using System;
using System.Linq;
using System.Net.Http.Formatting;
using System.Web.Http;
using System.Web.Http.Common;
using System.Web.Http.Controllers;
using System.Web.Http.Dispatcher;
using System.Web.Http.Metadata;
using System.Web.Http.Metadata.Providers;
using System.Web.Http.ModelBinding;
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;

internal class WebApiInstaller : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container.Register(
            Component.For&amp;lt;IHttpControllerFactory&amp;gt;()
               .ImplementedBy&amp;lt;WindsorHttpControllerFactory&amp;gt;()
               .LifestyleSingleton(),

            Component.For&amp;lt;ILogger&amp;gt;()
               .ImplementedBy&amp;lt;NullLogger&amp;gt;()
               .LifestyleSingleton(),

            Component.For&amp;lt;IFormatterSelector&amp;gt;()
               .ImplementedBy&amp;lt;FormatterSelector&amp;gt;()
               .LifestyleSingleton(),

            Component.For&amp;lt;IHttpControllerActivator&amp;gt;()
               .ImplementedBy&amp;lt;DefaultHttpControllerActivator&amp;gt;()
               .LifestyleTransient(),

            Component.For&amp;lt;IHttpActionSelector&amp;gt;()
               .ImplementedBy&amp;lt;ApiControllerActionSelector&amp;gt;()
               .LifestyleTransient(),

            Component.For&amp;lt;IActionValueBinder&amp;gt;()
               .ImplementedBy&amp;lt;DefaultActionValueBinder&amp;gt;()
               .LifestyleTransient(),

            Component.For&amp;lt;IHttpActionInvoker&amp;gt;()
               .ImplementedBy&amp;lt;ApiControllerActionInvoker&amp;gt;()
               .LifestyleTransient(),

            Component.For&amp;lt;ModelMetadataProvider&amp;gt;()
               .ImplementedBy&amp;lt;CachedDataAnnotationsModelMetadataProvider&amp;gt;()
               .LifestyleTransient(),

            Component.For&amp;lt;HttpConfiguration&amp;gt;()
               .Instance(GlobalConfiguration.Configuration));
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;In the&amp;nbsp;Application_Start method we add the installer and set the delegates for the SetResolver method. That way when the framework requests an IHttpControllerFactory instance, Windsor will supply the one we created earlier.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;this.container = new WindsorContainer()
    .Install(new WebApiInstaller());

GlobalConfiguration.Configuration.ServiceResolver.SetResolver(
    serviceType =&amp;gt; container.Resolve(serviceType),
    serviceType =&amp;gt; container.ResolveAll(serviceType).Cast&amp;lt;object&amp;gt;());&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;In order to have Windsor resolve regular controllers (side by side) we can create and add another installer as well as an implementation of the IControllerFactory interface.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;this.container = new WindsorContainer()
    .Install(new WebMvcInstaller())
    .Install(new WebApiInstaller());

GlobalConfiguration.Configuration.ServiceResolver.SetResolver(
    serviceType =&amp;gt; container.Resolve(serviceType),
    serviceType =&amp;gt; container.ResolveAll(serviceType).Cast&amp;lt;object&amp;gt;());

ControllerBuilder.Current.SetControllerFactory(
    new WindsorControllerFactory(this.container));&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Finally, a&amp;nbsp;gist with all the source code can be found &lt;a href=&quot;https://gist.github.com/2044349&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;References:&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://forums.asp.net/t/1770736.aspx/&quot; target=&quot;_blank&quot;&gt;Web Api / Implementing IHttpControllerFactory.CreateController&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://forums.asp.net/t/1772519.aspx/&quot; target=&quot;_blank&quot;&gt;Web Api /&amp;nbsp;How do I use Windsor?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;ul&gt;
&lt;/ul&gt;

</description>
			<pubDate>Fri, 16 Mar 2012 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Dynamic Proxy overriding Equals in AutoFixture Likeness</title>
			<link>http://nikosbaxevanis.com/2012/02/20/dynamic-proxy-overriding-equals-in-autofixture-likeness</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2012/02/20/dynamic-proxy-overriding-equals-in-autofixture-likeness</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;From version 2.9.0 of AutoFixture, the&amp;nbsp;&lt;a href=&quot;http://blog.ploeh.dk/2010/06/29/IntroducingAutoFixtureLikeness.aspx&quot; target=&quot;_blank&quot;&gt;Likeness&lt;/a&gt;&amp;nbsp;class contains a new feature for&amp;nbsp;creating a dynamic proxy that overrides Equals on the destination type.&lt;/p&gt;


&lt;p&gt;As an example, we want to compare instances of the following types:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public class DoubleParameterType&amp;lt;T1, T2&amp;gt;
{
    public DoubleParameterType(T1 parameter1, T2 parameter2)
    {
        this.Parameter1 = parameter1;
        this.Parameter2 = parameter2;
    }

    public T1 Parameter1 { get; private set; }
    public T2 Parameter2 { get; private set; }
}

public class SingleParameterType&amp;lt;T&amp;gt;
{
    public SingleParameterType(T parameter)
    {
        this.Parameter = parameter;
    }

    public T Parameter { get; private set; }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;We can have the following syntax (prior to version 2.9.0):&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Fact]
public void TestWithLikeness()
{
    // Fixture setup
    var value = new DoubleParameterType&amp;lt;int, double&amp;gt;(1, 2.0);

    Likeness&amp;lt;DoubleParameterType&amp;lt;int, double&amp;gt;, SingleParameterType&amp;lt;int&amp;gt;&amp;gt; sut 
        = value.AsSource()
               .OfLikeness&amp;lt;SingleParameterType&amp;lt;int&amp;gt;&amp;gt;();
            
    // Exercise system
    var result = sut.Equals(value);
    // Verify outcome
    Assert.True(result);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;However, from version 2.9.0 there is also a new CreateProxy method on Likeness which returns a proxy of the destination type overriding Equals with Likeness's instance of IEqualityComparer&amp;nbsp;(the SemanticComparer class):&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Fact]
public void TestWithLikenessProxy()
{
    // Fixture setup
    var value = new DoubleParameterType&amp;lt;int, double&amp;gt;(1, 2.0);
            
    SingleParameterType&amp;lt;int&amp;gt; sut
        = value.AsSource()
               .OfLikeness&amp;lt;SingleParameterType&amp;lt;int&amp;gt;&amp;gt;()
               .CreateProxy();
            
    // Exercise system
    var result = sut.Equals(value);
    // Verify outcome
    Assert.True(result);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Below is also an example, where we need to verify that an expectation was met:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public class Bar
{
    public string Zip { get; set; }
}

public class Foo
{
    public Bar Bar { get; private set; }

    public void DoSomething(ISomeContext ctx)
    {
        this.Bar = new Bar { Zip = &amp;quot;12345&amp;quot; };
        ctx.DoSomething(this.Bar);
    }
}

public interface ISomeContext
{
    void DoSomething(object request);
}

[Fact]
public void Test()
{
    var foo = new Foo();
    var ctx = new Mock&amp;lt;ISomeContext&amp;gt;();
    foo.DoSomething(ctx.Object);

    var bar = new Bar().AsSource().OfLikeness&amp;lt;Bar&amp;gt;().CreateProxy();
    bar.Zip = &amp;quot;12345&amp;quot;;

    ctx.Verify(x =&amp;gt; x.DoSomething(bar));
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Although the new Bar instance is created inside the DoSomething method, we can pass a &lt;em&gt;proxied &lt;/em&gt;Bar instance on the mock's Verify method.&lt;/p&gt;


&lt;p&gt;Internally, a custom Proxy Generator was written which also&amp;nbsp;supports types with non-parameterless constructors.&amp;nbsp;In order to create proxies of such types, the values from the source have to be compatible with the parameters on the destination constructor.&amp;nbsp;(The mapping between the two is made possible by using the same semantic heuristics, as the default semantic comparison.)&lt;/p&gt;



</description>
			<pubDate>Mon, 20 Feb 2012 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Test-After Development Sins (Ignoring cross-cutting concerns)</title>
			<link>http://nikosbaxevanis.com/2012/02/18/test-after-development-sins-ignoring-cross-cutting-concerns</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2012/02/18/test-after-development-sins-ignoring-cross-cutting-concerns</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;A&amp;#0160;&lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2012/01/test-after-development-sins-introduction.html&quot; target=&quot;_blank&quot; title=&quot;&amp;quot;Test-After Development&amp;quot; Sins: Introduction&quot;&gt;series&lt;/a&gt;&amp;#0160;of articles exploring the impact of writing tests&amp;#0160;&lt;em&gt;after&amp;#0160;&lt;/em&gt;the code is written&amp;#0160;on the implementation part of&amp;#0160;&lt;a href=&quot;http://en.wikipedia.org/wiki/Software_development_process&quot; target=&quot;_blank&quot; title=&quot;A software development process, also known as a software development life cycle (SDLC), is a structure imposed on the development of a software product.&quot;&gt;SDLC&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;&lt;span style=&quot;text-decoration: underline;&quot;&gt;Sin No.3&lt;/span&gt;: Ignoring cross-cutting concerns.&lt;/p&gt;


&lt;p&gt;The problem with this approach becomes very clear. It will be hard and tedious work, inside each test, to create stubs and mocks for each and every aspect.&amp;#0160;The intent of the unit tests will also look wrong since, in reality, these aspects should not be treated as&lt;em&gt;&amp;#0160;&lt;/em&gt;dependencies of the&amp;#0160;&lt;a href=&quot;http://xunitpatterns.com/SUT.html&quot; target=&quot;_blank&quot; title=&quot;The &amp;quot;system under test&amp;quot;. It is short for &amp;quot;whatever thing we are testing&amp;quot; and is always defined from the perspective of the test.&quot;&gt;SUT&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Among others, logging and caching are cross-cutting concerns that can easily slip through the services (making us treat them as normal dependencies).&amp;#0160;&lt;/p&gt;


&lt;p&gt;While the preferred way to model these aspects is using decorators and/or dynamic interceptors,&amp;#0160;there are many times that we see classes violating the&amp;#0160;&lt;a href=&quot;http://en.wikipedia.org/wiki/Single_responsibility_principle&quot; target=&quot;_blank&quot; title=&quot;In object-oriented programming, the single responsibility principle states that every object should have a single responsibility, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility.&quot;&gt;SRP&lt;/a&gt;&amp;#0160;containing &lt;em&gt;all-in-one&lt;/em&gt; logging, caching, auditing and other aspects (and even violating the&amp;#0160;&lt;a href=&quot;http://en.wikipedia.org/wiki/Interface_segregation_principle&quot; target=&quot;_blank&quot; title=&quot;The notion that many client specific interfaces are better than one general purpose interface.&quot;&gt;ISP&lt;/a&gt;&amp;#0160;with a coarse-grained&amp;#0160;&lt;a href=&quot;http://martinfowler.com/bliki/HeaderInterface.html&quot; target=&quot;_blank&quot; title=&quot;A header interface is an explicit interface that mimics the implicit public interface of a class. Essentially you take all the public methods of a class and declare them in an interface.&quot;&gt;Header Interface&lt;/a&gt;).&lt;/p&gt;

</description>
			<pubDate>Sat, 18 Feb 2012 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Parameterized Tests for ServiceStack Web Services</title>
			<link>http://nikosbaxevanis.com/2012/02/18/parameterized-tests-for-servicestack-web-services</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2012/02/18/parameterized-tests-for-servicestack-web-services</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;I have been using ServiceStack&amp;#39;s &lt;a href=&quot;https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack.ServiceInterface/RestServiceBase.cs&quot; target=&quot;_blank&quot;&gt;RestServiceBase&lt;/a&gt;&amp;#0160;class with great success.&amp;#0160;Because of that I started looking for ways to automate a &lt;a href=&quot;http://xunitpatterns.com/Layer%20Test.html&quot; target=&quot;_blank&quot; title=&quot;Also known as: Single Layer Test, Testing by Layers, Layered Test.&quot;&gt;Layer Test&lt;/a&gt; for a simple scenario where a&amp;#0160;client requests a representation of a resource using GET and/or submits data to be processed to the identified resource using POST.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public class CategoryService : RestServiceBase&amp;lt;Category&amp;gt;
{
    public override object OnGet(Category request)  { /* ... */ }
    public override object OnPost(Category request) { /* ... */ }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;I found a very nice&amp;#0160;&lt;a href=&quot;https://github.com/ServiceStack/ServiceStack/wiki/HowTo-write-unit-integration-tests&quot; target=&quot;_blank&quot;&gt;entry&lt;/a&gt; on the wiki and after writting a couple of tests I realized that I was repating the following steps over and over:&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;Copy the base URI on each test case.&lt;/li&gt;
&lt;li&gt;Create a new instance of the &lt;a href=&quot;https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack.Common/ServiceClient.Web/JsonServiceClient.cs&quot; target=&quot;_blank&quot;&gt;JsonRestClient&lt;/a&gt; class (and preferably cast to &lt;a href=&quot;https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack.Interfaces/Service/IRestClient.cs&quot; target=&quot;_blank&quot;&gt;IRestClient&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;var restClient = (IRestClient)new JsonServiceClient(&amp;quot;http://localhost:5000&amp;quot;);&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;One solution is to have the base URI (and even the IRestClient) on a private field inside the test class and use it from all tests.&amp;#0160;However, a better approach would be to write&amp;#0160;&lt;a href=&quot;http://xunitpatterns.com/Parameterized%20Test.html&quot; target=&quot;_blank&quot;&gt;Parameterized Tests&lt;/a&gt;&amp;#0160;that accept an instance of the IRestClient type.&lt;/p&gt;


&lt;p&gt;Fortunately, this can be done using xUnit.net data theories. Furthermore, since the IRestClient is an interface, this is a great scenario for using &lt;a href=&quot;http://autofixture.codeplex.com/&quot; target=&quot;_blank&quot; title=&quot;AutoFixture makes it easier for developers to do Test-Driven Development by automating non-relevant Test Fixture Setup, allowing the Test Developer to focus on the essentials of each test case.&quot;&gt;AutoFixture&lt;/a&gt;&amp;#0160;together&amp;#0160;&lt;a href=&quot;http://blog.ploeh.dk/2010/10/08/AutoDataTheoriesWithAutoFixture.aspx&quot; target=&quot;_blank&quot;&gt;with&lt;/a&gt; xUnit.net data theories &lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2011/12/auto-mocking-with-fakeiteasy-and-autofixture.html&quot; target=&quot;_blank&quot;&gt;and&lt;/a&gt;&amp;#0160;auto mocking.&lt;/p&gt;


&lt;p&gt;Below is a parameterized test:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Theory, AutoWebData]
public void HttpGetReturnsnNonEmptyResult(IRestClient sut)
{
    var results = sut.Get&amp;lt;Category[]&amp;gt;(&amp;quot;/categories&amp;quot;);
    Assert.True(results.Any());
}
[Theory, AutoWebData]
public void HttpGetReturnsNonEmptyResultWithId(IRestClient sut)
{
    var expectedId = sut.Get&amp;lt;Category[]&amp;gt;(&amp;quot;/categories&amp;quot;).First().Id;
    var result = sut.Get&amp;lt;Category&amp;gt;(&amp;quot;/categories/&amp;quot; + expectedId);
    Assert.Equal(expectedId, result.Id);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;The &lt;em&gt;AutoWebData &lt;/em&gt;attribute provides auto-generated data specimens generated by AutoFixture as an extention to xUnit.net&amp;#39;s Theory attribute.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public sealed class AutoWebDataAttribute : AutoDataAttribute
{
    public AutoWebDataAttribute()
        : base(new Fixture().Customize(new WebModelCustomization()))
    {
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Inside this attribute class we also pass a new instance of the Fixture class &lt;em&gt;customized &lt;/em&gt;in order to supply an instance of the JsonServiceClient when an IRestClient is requested. (You can read more about AutoFixture Customizations&amp;#0160;&lt;a href=&quot;http://megakemp.wordpress.com/2011/12/15/keep-your-unit-tests-dry-with-autofixture-customizations/&quot; target=&quot;_blank&quot; title=&quot;Keep your unit tests DRY with AutoFixture Customizations.&quot;&gt;here&lt;/a&gt;.)&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public class WebModelCustomization : CompositeCustomization
{
    public WebModelCustomization()
        : base(
            new RestClientCustomization(),
            new AutoMoqCustomization()) { } 

    private sealed class RestClientCustomization : ICustomization
    {
        public void Customize(IFixture fixture)
        {
            fixture.Inject&amp;lt;IRestClient&amp;gt;(
                new JsonServiceClient(&amp;quot;http://localhost:5000&amp;quot;));
        }
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;The advantage of this approach is that we have abstracted the creation of the IRestClient instance from the test itself. The base URI is now hardcoded in only one place (the customization class). Furthermore, we can easily pass other parameters to the test method if necessary.&amp;#0160;&lt;/p&gt;


&lt;p&gt;While this approach is applied to ServiceStack it can be easily generalized and used on other scenarios as well.&lt;/p&gt;



</description>
			<pubDate>Sat, 18 Feb 2012 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Test-After Development Sins (Production Code First)</title>
			<link>http://nikosbaxevanis.com/2012/01/28/test-after-development-sins-production-code-first</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2012/01/28/test-after-development-sins-production-code-first</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;div&gt;
&lt;p&gt;A &lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2012/01/test-after-development-sins-introduction.html&quot; target=&quot;_blank&quot; title=&quot;&amp;quot;Test-After Development&amp;quot; Sins: Introduction&quot;&gt;series&lt;/a&gt;&amp;#0160;of short articles exploring the impact of writing tests&amp;#0160;&lt;em&gt;after&amp;#0160;&lt;/em&gt;the code is written&amp;#0160;on the implementation part of&amp;#0160;&lt;a href=&quot;http://en.wikipedia.org/wiki/Software_development_process&quot; target=&quot;_blank&quot; title=&quot;A software development process, also known as a software development life cycle (SDLC), is a structure imposed on the development of a software product.&quot;&gt;SDLC&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;


&lt;p&gt;&lt;span style=&quot;text-decoration: underline;&quot;&gt;Sin No.1&lt;/span&gt;: Production Code First.&lt;/p&gt;


&lt;p&gt;By not writing tests upfront, the code becomes most of the times a &lt;a href=&quot;http://martinfowler.com/eaaCatalog/transactionScript.html&quot; target=&quot;_blank&quot; title=&quot;Organizes business logic by procedures where each procedure handles a single request from the presentation.&quot;&gt;Transaction Script&lt;/a&gt;. It usually lives at application boundaries. If not, then it usually delegates all method arguments to a method with the same name inside a &lt;a href=&quot;http://martinfowler.com/eaaCatalog/serviceLayer.html&quot; target=&quot;_blank&quot; title=&quot;Defines an application&amp;#39;s boundary with a layer of services that establishes a set of available operations and coordinates the application&amp;#39;s response in each operation.&quot;&gt;Service Layer&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Most of the times, this code is responsible for aspects such is validation and persistence violating the &lt;a href=&quot;http://en.wikipedia.org/wiki/Single_responsibility_principle&quot; target=&quot;_blank&quot; title=&quot;In object-oriented programming, the single responsibility principle states that every object should have a single responsibility, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility.&quot;&gt;SRP&lt;/a&gt;&amp;#0160;and likely most (if not all) of the other&amp;#0160;&lt;a href=&quot;http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)&quot; target=&quot;_blank&quot; title=&quot;In computer programming, SOLID (Single responsibility, Open-closed, Liskov substitution, Interface segregation and Dependency inversion) is a mnemonic acronym introduced by Robert C. Martin in the early 2000s which stands for five basic principles of object-oriented programming and design.&quot;&gt;principles&lt;/a&gt; of class design.&lt;/p&gt;


&lt;p&gt;Even worse, inside those methods, dependencies might be resolved using a&amp;#0160;&lt;a href=&quot;http://martinfowler.com/articles/injection.html#UsingAServiceLocator&quot; target=&quot;_blank&quot;&gt;Service Locator&lt;/a&gt;&amp;#0160;(which is &lt;a href=&quot;http://blog.ploeh.dk/2010/02/03/ServiceLocatorIsAnAntiPattern.aspx&quot; target=&quot;_blank&quot; title=&quot;Service Locator is an Anti-Pattern&quot;&gt;not&lt;/a&gt; good) forcing us to mock the container (if that&amp;#39;s an option at all) in order to successfully write unit tests&amp;#0160;&lt;em&gt;afterwards&lt;/em&gt;.&lt;/p&gt;


&lt;p&gt;At the end, a lot of time is spent to write a few&amp;#0160;&lt;a href=&quot;http://xunitpatterns.com/Fragile%20Test.html&quot; target=&quot;_blank&quot; title=&quot;A test fails to compile or run when the system under test (SUT) is changed in ways that do not affect the part the test is exercising.&quot;&gt;Fragile Tests&lt;/a&gt;, resulting in a system which is (in most other places) not covered by tests at all.&lt;/p&gt;



</description>
			<pubDate>Sat, 28 Jan 2012 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Test-After Development Sins (Header Interfaces)</title>
			<link>http://nikosbaxevanis.com/2012/01/28/test-after-development-sins-header-interfaces</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2012/01/28/test-after-development-sins-header-interfaces</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;A&amp;#0160;&lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2012/01/test-after-development-sins-introduction.html&quot; target=&quot;_blank&quot; title=&quot;&amp;quot;Test-After Development&amp;quot; Sins: Introduction&quot;&gt;series&lt;/a&gt;&amp;#0160;of articles exploring the impact of writing tests&amp;#0160;&lt;em&gt;after&amp;#0160;&lt;/em&gt;the code is written&amp;#0160;on the implementation part of&amp;#0160;&lt;a href=&quot;http://en.wikipedia.org/wiki/Software_development_process&quot; target=&quot;_blank&quot; title=&quot;A software development process, also known as a software development life cycle (SDLC), is a structure imposed on the development of a software product.&quot;&gt;SDLC&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;&lt;span style=&quot;text-decoration: underline;&quot;&gt;Sin No.2&lt;/span&gt;: Header Interfaces.&lt;/p&gt;


&lt;p&gt;A good example is a data access layer combined with the use of an&amp;#0160;Object-relational mapper (ORM).&lt;/p&gt;


&lt;p&gt;While an ORM provides (out of the box) a collection-like interface (&lt;a href=&quot;https://github.com/nhibernate/nhibernate-core/blob/master/src/NHibernate/ISession.cs&quot; target=&quot;_blank&quot; title=&quot;The main runtime interface between a .NET application and NHibernate. This is the central API class abstracting the notion of a persistence service.&quot;&gt;ISession&lt;/a&gt;, &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.data.entity.dbcontext(v=vs.103).aspx&quot; target=&quot;_blank&quot; title=&quot;Provides facilities for querying and working with entity data as objects.&quot;&gt;DbContext&lt;/a&gt;) for accessing domain objects, most of the time a coarse-grained &lt;a href=&quot;http://martinfowler.com/bliki/HeaderInterface.html&quot; target=&quot;_blank&quot; title=&quot;A header interface is an explicit interface that mimics the implicit public interface of a class. Essentially you take all the public methods of a class and declare them in an interface.&quot;&gt;Header Interface&lt;/a&gt; is created on &lt;em&gt;top &lt;/em&gt;of that.&lt;/p&gt;


&lt;p&gt;Those interfaces usually contain high number of members making the overall architecture extremely &lt;em&gt;inflexible.&lt;/em&gt;&lt;/p&gt;


&lt;p&gt;The system is usually forced to live with only &lt;em&gt;one &lt;/em&gt;implementation for each interface. That implementation is most of the times generalized.&lt;/p&gt;


&lt;p&gt;Some examples,&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;It&amp;#39;s nearly impossible, in performance related scenarios, to manually execute SQL or access the IDbConnection.&lt;/li&gt;
&lt;/ul&gt;


&lt;ul&gt;
&lt;li&gt;In order to map data between application boundaries or&amp;#0160;populate an instance of a view model the exact same implementation is used.&lt;/li&gt;
&lt;/ul&gt;


&lt;blockquote&gt;&lt;p&gt;In the second example, the implementation&amp;#0160;&lt;strong&gt;eagerly&amp;#0160;&lt;/strong&gt;loads all the entities of an Aggregate Root which hurts performance.&lt;/p&gt;&lt;/blockquote&gt;

</description>
			<pubDate>Sat, 28 Jan 2012 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Test-After Development Sins</title>
			<link>http://nikosbaxevanis.com/2012/01/28/test-after-development-sins</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2012/01/28/test-after-development-sins</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;A series of short articles exploring the impact of writing tests&amp;#0160;&lt;em&gt;after&amp;#0160;&lt;/em&gt;the code is written&amp;#0160;on the implementation part of &lt;a href=&quot;http://en.wikipedia.org/wiki/Software_development_process&quot; target=&quot;_blank&quot; title=&quot;A software development process, also known as a software development life cycle (SDLC), is a structure imposed on the development of a software product.&quot;&gt;SDLC&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2012/01/test-after-development-sins-production-code-first.html&quot; target=&quot;_blank&quot; title=&quot;&amp;quot;Test-After Development&amp;quot; Sins: Production Code First.&quot;&gt; Sin No.1&lt;/a&gt;:&amp;#0160;Production Code First.&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2012/01/test-after-development-sins-coarse-header-interfaces.html&quot; target=&quot;_blank&quot; title=&quot;&amp;quot;Test-After Development&amp;quot; Sins: Header Interfaces.&quot;&gt;Sin No.2&lt;/a&gt;: Header Interfaces.&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2012/02/test-after-development-sins-ignoring-cross-cutting-concerns.html&quot; target=&quot;_blank&quot; title=&quot;&amp;quot;Test-After Development&amp;quot; Sins: Ignoring cross-cutting concerns.&quot;&gt;Sin No.3&lt;/a&gt;: Ignoring cross-cutting concerns.&lt;/p&gt;


&lt;p&gt;Sin No.4: Increasing costs.&lt;/p&gt;


&lt;p&gt;Sin No.5:&amp;#0160;Decreasing quality.&lt;/p&gt;



</description>
			<pubDate>Sat, 28 Jan 2012 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Auto-Mocking with FakeItEasy and AutoFixture</title>
			<link>http://nikosbaxevanis.com/2011/12/14/auto-mocking-with-fakeiteasy-and-autofixture</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/12/14/auto-mocking-with-fakeiteasy-and-autofixture</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;AutoFixture can become an auto-mocking container using &lt;a title=&quot;The simplest mocking library for .NET 3.5 and Silverlight with deep C# 3.0 integration.&quot; href=&quot;http://code.google.com/p/moq/&quot; target=&quot;_blank&quot;&gt;Moq&lt;/a&gt;&amp;nbsp;(described &lt;a title=&quot;AutoFixture as an auto-mocking container.&quot; href=&quot;http://blog.ploeh.dk/2010/08/19/AutoFixtureAsAnAutomockingContainer.aspx&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;) and &lt;a title=&quot;Rhino Mocks is a dynamic mock object framework for the .Net platform. Its purpose is to ease testing by allowing the developer to create mock implementations of custom objects and verify the interactions using unit testing.&quot; href=&quot;http://hibernatingrhinos.com/open-source/rhino-mocks&quot; target=&quot;_blank&quot;&gt;Rhino Mocks&lt;/a&gt; (described &lt;a title=&quot;Rhino Mocks-based auto-mocking with AutoFixture.&quot; href=&quot;http://blog.ploeh.dk/2010/11/13/RhinoMocksbasedAutomockingWithAutoFixture.aspx&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;).&lt;/p&gt;


&lt;p&gt;In addition to the above auto-mocking features it is now possible to use &lt;a title=&quot;A .Net dynamic fake framework for creating all types of fake objects, mocks, stubs etc. Easier semantics, all fake objects are just that - fakes - the use of the fakes determines whether they're mocks or stubs.&quot; href=&quot;http://code.google.com/p/fakeiteasy/&quot; target=&quot;_blank&quot;&gt;FakeItEasy&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;To install AutoFixture with Auto Mocking using FakeItEasy, run the following command in the Package Manager Console:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;PM&amp;gt; Install-Package AutoFixture.AutoFakeItEasy&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;To use it, add an AutoFakeItEasyCustomization to the Fixture instance:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;var fixture = new Fixture()
    .Customize(new AutoFakeItEasyCustomization());&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Here is a typical usage inside a test method which will automatically create mocked instances using FakeItEasy:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;var fixture = new Fixture()
    .Customize(new AutoFakeItEasyCustomization());
var result = fixture.CreateAnonymous&amp;lt;IInterface&amp;gt;();&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;To &lt;em&gt;explicitly &lt;/em&gt;use FakeItEasy inside a test you need to &lt;a title=&quot;AutoFixture Freeze.&quot; href=&quot;http://blog.ploeh.dk/2010/03/17/AutoFixtureFreeze.aspx&quot; target=&quot;_blank&quot;&gt;Freeze&lt;/a&gt; it first:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Fact]
public void FixtureCanFreezeFake()
{
    // Fixture setup
    var fixture = new Fixture()
        .Customize(new AutoFakeItEasyCustomization());
    var dummy = new object();
    var fake = fixture.Freeze&amp;lt;Fake&amp;lt;IInterface&amp;gt;&amp;gt;();
    fake.CallsTo(x =&amp;gt; x.MakeIt(dummy))
        .Returns(null);
    // Exercise system
    var result = fixture.CreateAnonymous&amp;lt;IInterface&amp;gt;();
    result.MakeIt(dummy);
    // Verify outcome
    A.CallTo(() =&amp;gt; result.MakeIt(dummy)).MustHaveHappened();
    // Teardown
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;The above example can be made even more elegant by using &lt;a title=&quot;AutoData Theories with AutoFixture.&quot; href=&quot;http://blog.ploeh.dk/2010/10/08/AutoDataTheoriesWithAutoFixture.aspx&quot; target=&quot;_blank&quot;&gt;AutoData&lt;/a&gt; theories:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Theory, AutoFakeData]
public void FixtureCanFreezeFake([Frozen]Fake&amp;lt;IInterface&amp;gt; fake, IInterface sut)
{
    var dummy = new object();
    sut.MakeIt(dummy);
    A.CallTo(() =&amp;gt; sut.MakeIt(dummy)).MustHaveHappened();
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Below is the code for the AutoFakeDataAttribute class:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public class AutoFakeDataAttribute : AutoDataAttribute
{
    public AutoFakeDataAttribute()
        : base(new Fixture().Customize(new AutoFakeItEasyCustomization()))
    {
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;An automatically published release created from the latest successful build can also be downloaded from&amp;nbsp;&lt;a title=&quot;AutoFixture - Downloads&quot; href=&quot;http://autofixture.codeplex.com/releases/view/78605&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
			<pubDate>Wed, 14 Dec 2011 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>RegularExpressionAttribute support in AutoFixture</title>
			<link>http://nikosbaxevanis.com/2011/12/11/regularexpressionattribute-support-in-autofixture</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/12/11/regularexpressionattribute-support-in-autofixture</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Continuing the support of DataAnnotations as described&amp;nbsp;&lt;a title=&quot;StringLengthAttribute support in AutoFixture&quot; href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2011/09/stringlengthattribute-support-in-autofixture.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;&amp;nbsp;and &lt;a title=&quot;RangeAttribute support in AutoFixture&quot; href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2011/09/rangeattribute-support-in-autofixture.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;, there is now added support for the&amp;nbsp;&lt;a title=&quot;Specifies that a data field value must match the specified regular expression.&quot; href=&quot;http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.regularexpressionattribute.aspx&quot; target=&quot;_blank&quot;&gt;RegularExpressionAttribute&lt;/a&gt;&amp;nbsp;class.&lt;/p&gt;


&lt;p&gt;Starting with version 2.6.0, when this attribute is applied on a data field AutoFixture will &lt;em&gt;try &lt;/em&gt;to&amp;nbsp;generate a value that&amp;nbsp;matches the specified regular expression.&lt;/p&gt;


&lt;p&gt;Let's take as an example the following type:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public class RegularExpressionValidatedType
{
    // Allow up to 40 uppercase and lowercase.
    [RegularExpression(&amp;quot;^[a-zA-Z''-'\s]{1,40}$&amp;quot;)]
    public string Name { get; set; }
    
    [RegularExpression(&amp;quot;^http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$&amp;quot;)]
    public string Url { get; set; }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Prior to version 2.6.0 if&amp;nbsp;we request an anonymous instance from AutoFixture, by&amp;nbsp;&lt;em&gt;default&lt;/em&gt;&amp;nbsp;we would get back an instance of the above type with it's properties containing values similar to those below.&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8510/8398554280_b996887d56_o.png&quot; title=&quot;Prior verion 2.6.0&quot; alt=&quot;Prior verion 2.6.0&quot; /&gt;&lt;/p&gt;




&lt;p&gt;However, from version 2.6.0 AutoFixture can handle requests with&amp;nbsp;regular expressions, through the RegularExpressionAttribute class, by issuing a new request for the specified regular expression pattern.&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8501/8398554186_edc6990289_o.png&quot; title=&quot;After verion 2.6.0&quot; alt=&quot;After verion 2.6.0&quot; /&gt;&lt;/p&gt;




&lt;p&gt;The idea behind this new feature is that members of a &lt;a title=&quot;In computing, a regular expression provides a concise and flexible means for &amp;quot;matching&amp;quot; (specifying and recognizing) strings of text, such as particular characters, words, or patterns of characters.&quot; href=&quot;http://en.wikipedia.org/wiki/Regular_expression&quot; target=&quot;_blank&quot;&gt;Regular Expression&lt;/a&gt;&amp;nbsp;(Regex) can be generated by first transforming the Regex into a &lt;a title=&quot;A finite-state machine (FSM) or finite-state automaton (plural: automata), or simply a state machine, is a mathematical model used to design computer programs and digital logic circuits.&quot; href=&quot;http://en.wikipedia.org/wiki/Finite_state_machine&quot; target=&quot;_blank&quot;&gt;Finite-state machine&lt;/a&gt;, particularly a&amp;nbsp;&lt;a title=&quot;In the theory of computation and automata theory, a deterministic finite automaton (DFA)—also known as deterministic finite state machine—is a finite state machine accepting finite strings of symbols.&quot; href=&quot;http://en.wikipedia.org/wiki/Deterministic_finite_automata&quot; target=&quot;_blank&quot;&gt;Deterministic finite automaton&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;


&lt;p&gt;You may also watch a short,&amp;nbsp;introductory,&amp;nbsp;video on the subject &lt;a title=&quot;Symbolic Regular Expression Exploration&quot; href=&quot;http://channel9.msdn.com/posts/Peli/Margus-Veanes-Rex-Symbolic-Regular-Expression-Exploration/&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. (Although it is for &lt;a title=&quot;Rex is a tool that explores .NET regexes and generates members efficiently.&quot; href=&quot;http://research.microsoft.com/en-us/projects/rex/&quot; target=&quot;_blank&quot;&gt;Rex&lt;/a&gt;, I find it very descriptive.)&lt;/p&gt;


&lt;p&gt;The current implementation uses internally the algorithms provided by the&amp;nbsp;&lt;a title=&quot;A DFA/NFA (finite-state automata) implementation with Unicode alphabet (UTF16) and support for the standard regular expression operations (concatenation, union, Kleene star) and a number of non-standard ones (intersection, complement, etc.)&quot; href=&quot;http://www.brics.dk/automaton/&quot; target=&quot;_blank&quot;&gt;dk.brics.automaton&lt;/a&gt;&amp;nbsp;and &lt;a title=&quot;A library for generating random text from regular expressions.&quot; href=&quot;http://code.google.com/p/xeger/&quot; target=&quot;_blank&quot;&gt;Xeger&lt;/a&gt;&amp;nbsp;packages.&lt;/p&gt;


&lt;p&gt;An automatically published release created from the latest successful build can be downloaded from&amp;nbsp;&lt;a title=&quot;AutoFixture - Downloads&quot; href=&quot;http://autofixture.codeplex.com/releases/view/78338&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&amp;nbsp;The latest version is also live on&amp;nbsp;&lt;a title=&quot;AutoFixture - Package&quot; href=&quot;http://nuget.org/List/Packages/AutoFixture&quot; target=&quot;_blank&quot;&gt;NuGet&lt;/a&gt;.&lt;/p&gt;



</description>
			<pubDate>Sun, 11 Dec 2011 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Fare - Finite Automata/Regex in .NET</title>
			<link>http://nikosbaxevanis.com/2011/11/24/fare-finite-automata-regex-in-net</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/11/24/fare-finite-automata-regex-in-net</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Project &lt;a href=&quot;https://github.com/moodmosaic/Fare&quot; target=&quot;_blank&quot; title=&quot;Fare - [F]inite [A]utomata and [R]egular [E]xpressions&quot;&gt;Fare&lt;/a&gt; is an effort to bring a &lt;a href=&quot;http://en.wikipedia.org/wiki/Deterministic_finite-state_machine&quot; target=&quot;_blank&quot; title=&quot;Deterministic finite-state machine&quot;&gt;DFA&lt;/a&gt;/&lt;a href=&quot;http://en.wikipedia.org/wiki/Nondeterministic_finite-state_machine&quot; target=&quot;_blank&quot; title=&quot;Nondeterministic finite-state machine&quot;&gt;NFA&lt;/a&gt; (finite-state automata) implementation from Java to .NET.&amp;#0160;There are quite a few implementations available in other languages today. This project aims to fill the gap in .NET.&lt;/p&gt;


&lt;p&gt;Fare is a .NET port of the well established Java library &lt;a href=&quot;http://www.brics.dk/automaton/&quot; target=&quot;_blank&quot; title=&quot;dk.brics.automaton&quot;&gt;dk.brics.automaton&lt;/a&gt; with API as close as possible to the corresponding dk.brics.automaton classes. It also includes a port of &lt;a href=&quot;http://code.google.com/p/xeger/&quot; target=&quot;_blank&quot; title=&quot;A Java library for generating random text from regular expressions.&quot;&gt;Xeger&lt;/a&gt;&amp;#0160;which is a&amp;#0160;Java library for generating random text from regular expressions. The latter is possible in .NET using the &lt;a href=&quot;http://research.microsoft.com/en-us/projects/rex/&quot; target=&quot;_blank&quot; title=&quot;Rex is a tool that explores .NET regexes and generates members efficiently.&quot;&gt;Rex&lt;/a&gt; tool.&lt;/p&gt;


&lt;p&gt;There are currently integration tests utilizing xUnit.net data &lt;a href=&quot;http://xunit.codeplex.com/wikipage?title=Comparisons#note4&quot; target=&quot;_blank&quot; title=&quot;The extensions library (xunit.extensions.dll) ships with support for data-driven tests call Theories.&quot;&gt;theories&lt;/a&gt; using the [ClassData] attribute. This way, the same test cases can be used across the ported code, the Java code and even compared to the output of Rex.&lt;/p&gt;


&lt;p&gt;The source code is&amp;#0160;&lt;a href=&quot;https://github.com/moodmosaic/Fare&quot; target=&quot;_blank&quot; title=&quot;Fare - [F]inite [A]utomata and [R]egular [E]xpressions&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;



</description>
			<pubDate>Thu, 24 Nov 2011 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Notes from porting Java code to .NET</title>
			<link>http://nikosbaxevanis.com/2011/11/19/notes-from-porting-java-code-to-net</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/11/19/notes-from-porting-java-code-to-net</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Recently I needed to use a&amp;#0160;DFA/NFA (finite-state automata) implementation from a Java package in .NET. I could not find a port of this particular&amp;#0160;&lt;a href=&quot;http://www.brics.dk/automaton/&quot; target=&quot;_blank&quot; title=&quot;dk.brics.automaton&quot;&gt;package&lt;/a&gt;&amp;#0160;and&amp;#0160;&lt;a href=&quot;http://www.ikvm.net/userguide/ikvmc.html&quot; target=&quot;_blank&quot; title=&quot;IKVM.NET Bytecode Compiler (ikvmc.exe)&quot;&gt;IKVMC&lt;/a&gt;&amp;#0160;was not an option since I preferred to depend only on the standard library (BCL). So,&amp;#0160;I decided to port the code myself.&lt;/p&gt;


&lt;p&gt;In my case, the Java package didn&amp;#39;t have unit tests (at least not publicly available on the website). &lt;strong&gt;How could I know that the results of the ported code are the same with the original code?&lt;/strong&gt;&lt;/p&gt;


&lt;p&gt;The solution I came up with was the following:&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;Write integration tests, one for the ported code and one for the Java code.     
&lt;ul&gt;
&lt;li&gt;Both tests should have the same, deterministic, input.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Keep porting enough code from the Java source in order to make the test pass.     
&lt;ul&gt;
&lt;li&gt;Verify that results are the same with the test in Java.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Recursively repeat this process until all tests pass and yield correct results.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;An example can be found here with integration tests for &lt;a href=&quot;https://github.com/moodmosaic/Fare/tree/master/Src/Fare.Tests.Integration&quot; target=&quot;_blank&quot;&gt;ported&lt;/a&gt; code and &lt;a href=&quot;https://github.com/moodmosaic/Fare/tree/master/Src/Fare.Tests.Integration/Java&quot; target=&quot;_blank&quot;&gt;Java&lt;/a&gt; (through IKVMC).&lt;/p&gt;


&lt;ul&gt;
&lt;/ul&gt;


&lt;p&gt;During the process of porting I came across a few&amp;#0160;&lt;strong&gt;differences&lt;/strong&gt; between Java and .NET and particularly:&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;Multi-dimensional arrays syntax is slightly different.&lt;/li&gt;
&lt;li&gt;Substring method parameteres have different meaning.    
&lt;ul&gt;
&lt;li&gt;In C# we pass StartIndex, Length.&lt;/li&gt;
&lt;li&gt;In Java we pass StartIndex, EndIndex.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;In Java, the list and set implementations override equals, etc. The equivalent doesn&amp;#39;t happen in .NET.&lt;/li&gt;
&lt;li&gt;Java LinkedList Add method appends the specified element to the end of the list. The equivalent in .NET is the AddLast method.&lt;/li&gt;
&lt;li&gt;Java LinkedList Remove(int) method removes the element at the specified position in the list and returns the element that was removed from the list. The equivalent in .NET exists only with the use of an extension method.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;The following links helped me a lot:&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;Stack Overflow    
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/295224/what-are-major-differences-between-c-sharp-and-java&quot; target=&quot;_blank&quot;&gt;What are major differences between C# and Java?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/285793/why-should-i-bother-about-serialversionuid&quot; target=&quot;_blank&quot;&gt;Why should I bother about serialVersionUID?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/3581741/c-sharp-equivalent-to-javas-charat&quot; target=&quot;_blank&quot;&gt;C# equivalent to Java&amp;#39;s charAt()?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/8129943/working-with-multidimensional-arrays-in-c-sharp-similar-to-java/8129952#8129952&quot; target=&quot;_blank&quot;&gt;Working with multidimensional arrays in C# similar to Java&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/8103643/net-port-with-javas-map-set-hashmap&quot; target=&quot;_blank&quot;&gt;.NET port with Java&amp;#39;s Map, Set, HashMap&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/496928/what-is-the-difference-between-instanceof-and-class-isassignablefrom&quot; target=&quot;_blank&quot;&gt;What is the difference between instanceof and Class.isAssignableFrom&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/699210/why-should-i-implement-icloneable-in-c&quot; target=&quot;_blank&quot;&gt;Why you should not implement ICloneable in C#?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Java SE 6 Documentation&lt;br /&gt; 
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://download.oracle.com/javase/6/docs/api/java/util/Comparator.html&quot; target=&quot;_blank&quot;&gt;Interface Comparator&amp;lt;T&amp;gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://download.oracle.com/javase/6/docs/api/java/lang/Comparable.html&quot; target=&quot;_blank&quot;&gt;Comparable&amp;lt;T&amp;gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://download.oracle.com/javase/6/docs/api/java/util/Set.html&quot; target=&quot;_blank&quot;&gt;Interface Set&amp;lt;E&amp;gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;



</description>
			<pubDate>Sat, 19 Nov 2011 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Estimation Quiz</title>
			<link>http://nikosbaxevanis.com/2011/10/16/estimation-quiz</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/10/16/estimation-quiz</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;&lt;em&gt;Given some instructions, provide an estimate for the process of assembling a shelf (see picture below).&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;Academic approach&lt;/h2&gt;




&lt;p&gt;After &lt;span&gt;spending&lt;/span&gt; several minutes thinking, you estimate it to 30 minutes and &amp;#0160;then start assembling the parts in order to build the shelf.&lt;em&gt;&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8492/8398554832_23607b3fea_o.png&quot; alt=&quot;Academic approach&quot; /&gt;&lt;/p&gt;




&lt;h2&gt;Pragmatic approach&lt;/h2&gt;




&lt;p&gt;Depending on the complexity of the assembling and the quality of the given instructions the whole process can fall out of any estimation.&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8515/8397466279_8c02b3985f_o.png&quot; alt=&quot;Pragmatic approach&quot; /&gt;&lt;/p&gt;




&lt;p&gt;..and from the initial estimate of 30 minutes you can end up in a 10 hours of actual work.&lt;/p&gt;



</description>
			<pubDate>Sun, 16 Oct 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Using class libraries from different platforms</title>
			<link>http://nikosbaxevanis.com/2011/10/11/using-class-libraries-from-different-platforms</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/10/11/using-class-libraries-from-different-platforms</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;There are times where we need to use a library written in a different platform than the one we are currently on.&amp;#0160;Most of the times a port already exists and we can choose to go with that.&amp;#0160;Before using a port there are some good considerations:&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;The size of the original codebase.&lt;/li&gt;
&lt;li&gt;The kind of project (is it a logger, an&amp;#0160;ORM, etc).&lt;/li&gt;
&lt;li&gt;The current version of the original compared with the ported one. It depends on the activity of the original but if the ported is left 1+ year behind this is not a good sign.&lt;/li&gt;
&lt;li&gt;The quality of the ported codebase,&amp;#0160;framework usage, coding conventions. Does it use recommeded guidelines for the target framework?&lt;/li&gt;
&lt;li&gt;The activity of the ported project. If it&amp;#39;s low that&amp;#39;s a sign that future versions might now show up. However, consider contributing.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Besides ported code, there are cases where we can use a tool that allows us to use the original library from a different platform. For example, when working in .NET we can use Java class libraries through IKVM.NET which has a bytecode compiler called&amp;#0160;&lt;a href=&quot;http://www.ikvm.net/userguide/ikvmc.html&quot; target=&quot;_blank&quot; title=&quot;IKVM.NET Bytecode Compiler (ikvmc.exe)&quot;&gt;IKVMC&lt;/a&gt;.&lt;/p&gt;



</description>
			<pubDate>Tue, 11 Oct 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>IKVMC in Action with Hamcrest</title>
			<link>http://nikosbaxevanis.com/2011/10/11/ikvmc-in-action-with-hamcrest</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/10/11/ikvmc-in-action-with-hamcrest</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;In &lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2011/10/using-class-libraries-from-different-platforms.html&quot; target=&quot;_blank&quot; title=&quot;Using class libraries from different platforms.&quot;&gt;this&lt;/a&gt; post, we saw two possible ways for using code written on a different platform than the one we are working on.&amp;#0160;Now we will see a scenario where we need to use a Java class library&amp;#0160;from .NET using the &lt;a href=&quot;http://www.ikvm.net/userguide/ikvmc.html&quot; target=&quot;_blank&quot; title=&quot;The ikvmc tool converts Java bytecode to .NET dll&amp;#39;s and exe&amp;#39;s.&quot;&gt;IKVMC&lt;/a&gt;&amp;#0160;tool.&amp;#0160;We are going to use &lt;a href=&quot;http://code.google.com/p/hamcrest/&quot; target=&quot;_blank&quot; title=&quot;Hamcrest is a framework for creating matchers, allowing match rules to be defined declaratively.&quot;&gt;Hamcrest&lt;/a&gt;, a library of matchers for building test expressions.&lt;/p&gt;


&lt;p&gt;Before we pass any command line argument to IKVMC we need to&amp;#0160;detect the dependencies between the jar files.&amp;#0160;&lt;a href=&quot;http://www.kirkk.com/main/Main/JarAnalyzer&quot; target=&quot;_blank&quot; title=&quot;JarAnalyzer is a dependency management utility for jar files.&quot;&gt;JarAnalyser&lt;/a&gt;&amp;#0160;is a good choice and fortunately there is a tool&amp;#0160;&lt;a href=&quot;http://code.google.com/p/jar2ikvmc/&quot; target=&quot;_blank&quot; title=&quot;Helps to convert a big collection of Java jar files into .net dlls by analyzing dependencies between jar files.&quot;&gt;Jar2ikvmc&lt;/a&gt; which&amp;#0160;uses JarAnalyser to detect dependencies between jar files and then generates command-line script for ikvmc.exe.&lt;/p&gt;


&lt;p&gt;The version of Hamcrest that we use is&amp;#0160;1.3RC2 and we are going to convert&amp;#0160;hamcrest-core.jar and hamcrest-library.jar.&lt;/p&gt;


&lt;p&gt;Here is the generated script from Jar2ikvmc:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;rest-core-1.3.0RC2.jar -target:library
ikvmc hamcrest-library-1.3RC2.jar -target:library -r:hamcrest-core-1.3RC2.dll&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Now we can run the generated script on the ikvmc.exe tool. It will generate two .NET assemblies. We can now compare the difference in the syntax with the excellent port &lt;a href=&quot;https://github.com/grahamrhay/NHamcrest&quot; target=&quot;_blank&quot;&gt;NHamcrest&lt;/a&gt; by &lt;a href=&quot;http://grahamrhay.wordpress.com/&quot; target=&quot;_blank&quot;&gt;Graham Rhay&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;We are going to use the Graham Rhay&amp;#39;s&amp;#0160;&lt;a href=&quot;https://github.com/grahamrhay/NHamcrest/blob/master/NHamcrest.XUnit/AssertEx.cs&quot; target=&quot;_blank&quot;&gt;Assert&lt;/a&gt; class that let us use NHamcrest from xUnit.net.&lt;/p&gt;


&lt;p&gt;Here is the code that uses NHamcrest:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public class Assert : Xunit.Assert
{
    public static void That&amp;lt;T&amp;gt;(T actual, IMatcher&amp;lt;T&amp;gt; matcher)
    {
        if (matcher.Matches(actual))
            return;

        var description = new StringDescription();
        matcher.DescribeTo(description);

        var mismatchDescription = new StringDescription();
        matcher.DescribeMismatch(actual, mismatchDescription);

        throw new MatchException(
            description.ToString(),
            mismatchDescription.ToString(),
            null);
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Here is the code that uses Hamcrest that we coverted using IKVMC:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;using org.hamcrest;

public class Assert : Xunit.Assert
{
    public static void That&amp;lt;T&amp;gt;(T actual, Matcher matcher)
    {
        if (matcher.matches(actual))
            return;

        var description = new StringDescription();
        matcher.describeTo(description);

        var mismatchDescription = new StringDescription();
        matcher.describeMismatch(actual, mismatchDescription);

        throw new MatchException(
            description.ToString(),
            mismatchDescription.ToString(),
            null);
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Here is a unit-test that uses NHamcrest:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;using NHamcrest.Xunit
using Xunit;

[Test]
public void Pass()
{
    Assert.That(1, Is.EqualTo(1));
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Here is a unit-test that uses Hamcrest that we coverted using IKVMC:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;using org.hamcrest.core;
using Xunit;

[Fact]
public void EqualTo()
{
    Assert.That(1, IsEqual.equalTo(1));
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;A notable difference is on the different naming conventions (Java methods start with lowercase). However, we can create &lt;a href=&quot;http://martinfowler.com/bliki/HeaderInterface.html&quot; target=&quot;_blank&quot; title=&quot;A header interface is an explicit interface that mimics the implicit public interface of a class.&quot;&gt;header interfaces&lt;/a&gt;&amp;#0160;declaring those methods inside.&lt;/p&gt;


&lt;p&gt;To sum up, if there is a good quality port we can use the port. In this case, I personally choose to go with NHamcrest. However, we already demoed the alternative approach which also works.&lt;/p&gt;

</description>
			<pubDate>Tue, 11 Oct 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>What goes first? (Theory or Tooling)</title>
			<link>http://nikosbaxevanis.com/2011/09/26/what-goes-first-theory-or-tooling</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/09/26/what-goes-first-theory-or-tooling</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;blockquote&gt;
&lt;p&gt;A very good friend of mine went to an interview where the interviewer kept asking about the X, Y or Z tool without paying attention to knowledge on the theory behind those tools.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;In my opinion it is always better to have a discussion, rather than a cliché&amp;#0160;interview.&amp;#0160;During the discussion it would be good to let the developer talk and express opinions on theory, design patterns and principles rather than make questions on specific tools and frameworks. The reason I strongly support that is because languages and tools tend to continuously&amp;#0160;evolve (and sometimes change directions) while the patterns and principles hardly change.&lt;/p&gt;


&lt;p&gt;Tools are implementations of patterns and principles in a specific language. Thus a developer should give priority on the theory behind them rather on the API of a specific tool.&lt;/p&gt;


&lt;p&gt;Let&amp;#39;s take as an example a Dependency Injection (DI) container. It gives no real value when a developer knows &lt;em&gt;only&lt;/em&gt; how to use Spring, Windsor or Unity if lacks fundamental knowledge of DI theory. On the other hand one, that knows how to apply proper&amp;#0160;&lt;a href=&quot;http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod&quot; target=&quot;_blank&quot; title=&quot;The Principles of OOD&quot;&gt;OOD&lt;/a&gt;&amp;#0160;design and follows SOLID&amp;#0160;principles, will use a DI container to compose object graphs in the &lt;a href=&quot;http://blog.ploeh.dk/2011/07/28/CompositionRoot.aspx&quot; target=&quot;_blank&quot; title=&quot;Composition Root&quot;&gt;Composition Root&lt;/a&gt; and it&amp;#39;s API to effectively apply lifetime management on them.&lt;/p&gt;


&lt;p&gt;The same applies when making questions on a specific ORM solution.&lt;/p&gt;

</description>
			<pubDate>Mon, 26 Sep 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>StringLengthAttribute support in AutoFixture</title>
			<link>http://nikosbaxevanis.com/2011/09/18/stringlengthattribute-support-in-autofixture</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/09/18/stringlengthattribute-support-in-autofixture</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Continuing the support of DataAnnotations as described &lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2011/09/rangeattribute-support-in-autofixture.html&quot; target=&quot;_blank&quot; title=&quot;RangeAttribute support in AutoFixture&quot;&gt;here&lt;/a&gt;, there is now added support for the&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.stringlengthattribute(v=VS.90).aspx&quot; target=&quot;_blank&quot; title=&quot;Specifies the maximum length of characters that are allowed in a data field.&quot;&gt;StringLengthAttribute&lt;/a&gt; class. Starting with version 2.4.0, when this attribute is applied on a data field it can specify the maximum length of characters that are allowed.&lt;/p&gt;


&lt;p&gt;Let&amp;#39;s take as an example the following type:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public class StringLengthValidatedType
{
    [StringLength(3)]
    public string Property { get; set; }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Prior to version 2.4.0 if&amp;#0160;we request an anonymous instance from AutoFixture, by &lt;em&gt;default&lt;/em&gt; we would get back an instance of the above type with it&amp;#39;s Property containing a value similar to the one below.&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8476/8398548352_20a167088e_o.png&quot; title=&quot;Prior verion 2.4.0&quot; alt=&quot;Prior verion 2.4.0&quot; /&gt;&lt;/p&gt;




&lt;p&gt;However, after version 2.4.0 AutoFixture can handle requests with&amp;#0160;string length constraints through the StringLengthAttribute&amp;#0160;class&amp;#0160;by issuing a new request for a constrained string.&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8084/8398548324_cfb75590cd_o.png&quot; title=&quot;After verion 2.4.0&quot; alt=&quot;After verion 2.4.0&quot; /&gt;&lt;/p&gt;




&lt;p&gt;An automatically published release created from the latest successful build can be downloaded from&amp;#0160;&lt;a href=&quot;http://autofixture.codeplex.com/releases/view/73545&quot; target=&quot;_blank&quot; title=&quot;AutoFixture - Downloads&quot;&gt;here&lt;/a&gt;.&amp;#0160;The latest version is also live on&amp;#0160;&lt;a href=&quot;http://nuget.org/List/Packages/AutoFixture&quot; target=&quot;_blank&quot; title=&quot;AutoFixture - Package&quot;&gt;NuGet&lt;/a&gt;.&lt;/p&gt;

</description>
			<pubDate>Sun, 18 Sep 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>RangeAttribute support in AutoFixture</title>
			<link>http://nikosbaxevanis.com/2011/09/13/rangeattribute-support-in-autofixture</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/09/13/rangeattribute-support-in-autofixture</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Support for types from the System.ComponentModel.&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations(v=VS.90).aspx&quot; target=&quot;_blank&quot; title=&quot;The System.ComponentModel.DataAnnotations namespace provides attribute classes that are used to define metadata for ASP.NET Dynamic Data controls.&quot;&gt;DataAnnotations&lt;/a&gt; namespace is one of the most voted features for AutoFixture. Starting with version 2.3.1 AutoFixture supports the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.rangeattribute(v=VS.90).aspx&quot; target=&quot;_blank&quot; title=&quot;Specifies the numeric range constraints for the value of a data field.&quot;&gt;RangeAttribute&lt;/a&gt; class.&amp;#0160;When this attribute is applied on a data field it can specify the numeric range constraints for it&amp;#39;s value.&lt;/p&gt;


&lt;p&gt;Let&amp;#39;s take as an example the following type:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public class RangeValidatedType
{
    [Range(10, 20)]
    public int Property { get; set; }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Prior to version 2.3.1 if&amp;#0160;we request an anonymous instance from AutoFixture (or better,&amp;#0160;a specimen from AutoFixture&amp;#39;s kernel) we would get back an instance of the above type with it&amp;#39;s Property containing a value probably out of the specified numeric range.&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8352/8398554262_e0f7efe6ef_o.png&quot; title=&quot;Prior verion 2.3.1&quot; alt=&quot;Prior verion 2.3.1&quot; /&gt;&lt;/p&gt;




&lt;p&gt;However, after version 2.3.1 AutoFixture can handle requests with&amp;#0160;numeric range constraints through the RangeAttribute class&amp;#0160;by issuing a new request for a value inside the specified range.&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8045/8397465809_4ba5a4b147_o.png&quot; title=&quot;After verion 2.3.1&quot; alt=&quot;After verion 2.3.1&quot; /&gt;&lt;/p&gt;




&lt;p&gt;An automatically published release created from the latest successful build can be downloaded from &lt;a href=&quot;http://autofixture.codeplex.com/releases/view/73230&quot; target=&quot;_blank&quot; title=&quot;AutoFixture - Downloads&quot;&gt;here&lt;/a&gt;.&amp;#0160;The latest version is also live on&amp;#0160;&lt;a href=&quot;http://nuget.org/List/Packages/AutoFixture&quot; target=&quot;_blank&quot; title=&quot;AutoFixture - Package&quot;&gt;NuGet&lt;/a&gt;.&lt;/p&gt;



</description>
			<pubDate>Tue, 13 Sep 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Heuristics for Static Factory Methods in AutoFixture</title>
			<link>http://nikosbaxevanis.com/2011/08/25/heuristics-for-static-factory-methods-in-autofixture</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/08/25/heuristics-for-static-factory-methods-in-autofixture</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Here is a type with a private constructor:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public class TypeWithFactoryMethod
{
    private TypeWithFactoryMethod() 
    {
    }

    public static TypeWithFactoryMethod Create()
    {
        return new TypeWithFactoryMethod();
    }

    public static TypeWithFactoryMethod Create(object argument)
    {
        return new TypeWithFactoryMethod();
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;In order to create an instance of that type we have to call one of it&amp;#39;s static factory methods, for example:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;var instance = TypeWithFactoryMethod.Create();&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;If we try to create an &lt;a href=&quot;http://blogs.msdn.com/b/ploeh/archive/2008/11/17/anonymous-variables.aspx&quot; target=&quot;_blank&quot; title=&quot;Anonymous Variables&quot;&gt;Anonymous Variable&lt;/a&gt; with &lt;a href=&quot;http://autofixture.codeplex.com&quot; target=&quot;_blank&quot; title=&quot;AutoFixture makes it easier for developers to do Test-Driven Development by automating non-relevant Test Fixture Setup, allowing the Test Developer to focus on the essentials of each test case.&quot;&gt;AutoFixture&lt;/a&gt; right now (version 2.1) it will throw an exception since there are no public constructors:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;var fixture = new Fixture();
var result = fixture.CreateAnonymous&amp;lt;TypeWithFactoryMethod&amp;gt;();&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Using the latest version from&amp;#0160;&lt;a href=&quot;http://autofixture.codeplex.com/SourceControl/list/changesets&quot; target=&quot;_blank&quot; title=&quot;AutoFixture (changesets)&quot;&gt;trunk&lt;/a&gt;&amp;#0160;(and on the next public release) the above code will work.&amp;#0160;It will successfully return an instance of the type by using&amp;#0160;a set of heuristics that enable AutoFixture to search for static factory methods.&lt;/p&gt;


&lt;p&gt;The latest build (including strong names) can be downloaded from &lt;a href=&quot;http://teamcity.codebetter.com/project.html?projectId=project129&amp;amp;tab=projectOverview. &quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;



</description>
			<pubDate>Thu, 25 Aug 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Combining Data Theories in AutoFixture.Xunit extension</title>
			<link>http://nikosbaxevanis.com/2011/08/25/combining-data-theories-in-autofixture-xunit-extension</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/08/25/combining-data-theories-in-autofixture-xunit-extension</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;&lt;a href=&quot;http://xunit.codeplex.com/&quot; target=&quot;_blank&quot; title=&quot;xUnit.net is a unit testing tool for the .NET Framework. Written by the original inventor of NUnit.&quot;&gt;xUnit.net&lt;/a&gt; supports parameterized tests via data theories which are types deriving from the Xunit.Extensions.DataAttribute type.&amp;#0160;Some popular attributes include:&lt;/p&gt;


&lt;p&gt;InlineDataAttribute,&amp;#0160;PropertyDataAttribute and ClassDataAttribute.&lt;/p&gt;


&lt;p&gt;AutoFixture.Xunit extension includes a very useful type, for providing auto-data theories, called&amp;#0160;&lt;a href=&quot;http://blog.ploeh.dk/2010/10/08/AutoDataTheoriesWithAutoFixture.aspx&quot; target=&quot;_blank&quot; title=&quot;AutoData Theories with AutoFixture&quot;&gt;AutoMoqDataAttribute&lt;/a&gt;.&amp;#0160;&lt;/p&gt;


&lt;p&gt;Imagine a Scenario where we have a unit test method with 3 parameters.&amp;#0160;We want the first parameters to be supplied by InlineData and the rest by AutoFixture using AutoMoqData.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Theory]
[InlineAutoData(&amp;quot;foo&amp;quot;)]
[InlineAutoData(&amp;quot;foo&amp;quot;, &amp;quot;bar&amp;quot;)]
public void Test(string s1, string s2, MyClass myClass)
{
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;This is now possible using the &lt;strong&gt;InlineAutoDataAttribute&lt;/strong&gt; type which is now on the trunk and will be available on next public release (after version 2.1).&amp;#0160;It provides a data source for a data theory, with the data coming from inline values combined with auto-generated data specimens generated by AutoFixture.&lt;/p&gt;


&lt;p&gt;InlineAutoDataAttribute derives from &lt;strong&gt;CompositeDataAttribute&lt;/strong&gt;,&amp;#0160;an implementation of DataAttribute that composes other DataAttribute instances.&lt;/p&gt;


&lt;p&gt;Here is how it works:&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;Delegate the GetData method call to the&amp;#0160;&lt;em&gt;first&lt;/em&gt;&amp;#0160;attribute.&lt;/li&gt;
&lt;li&gt;Loop through the results from the first attribute and check if the length of each object array matches the number of arguments required by the method.     
&lt;ul&gt;
&lt;li&gt;If so, yield the object array.&lt;/li&gt;
&lt;li&gt;If not, invoke GetData on the&amp;#0160;&lt;em&gt;next&lt;/em&gt;&amp;#0160;attribute.     
&lt;ul&gt;
&lt;li&gt;Throw away the first objects from the result in order to continue from where it ran out of objects from the first result set and concatenate the rest to the previous array.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;ul&gt;
&lt;li&gt;Recursively repeat this process until all object arrays have the required length.&lt;/li&gt;
&lt;/ul&gt;


&lt;blockquote&gt;
&lt;p&gt;While this feature comes with AutoFixture.Xunit extension, the CompositeDataAttribute class depends only on the xunit.extensions assembly.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;You may compile the code from the latest&amp;#0160;&lt;a href=&quot;http://autofixture.codeplex.com/SourceControl/list/changesets&quot; target=&quot;_blank&quot; title=&quot;AutoFixture (changesets)&quot;&gt;trunk&lt;/a&gt;&amp;#0160;version, alternatively&amp;#0160;the latest build (including strong names) can be downloaded from&amp;#0160;&lt;a href=&quot;http://teamcity.codebetter.com/project.html?projectId=project129&amp;amp;tab=projectOverview. &quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;



</description>
			<pubDate>Thu, 25 Aug 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>S(ports) is for (Open) Source</title>
			<link>http://nikosbaxevanis.com/2011/08/23/s-ports-is-for-open-source</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/08/23/s-ports-is-for-open-source</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p style=&quot;text-align: center;&quot;&gt;&lt;em&gt;The &amp;quot;Loose Laces&amp;quot; Story&lt;/em&gt;&lt;/p&gt;


&lt;p style=&quot;text-align: center;&quot;&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8183/8398548564_325c904f66_o.png&quot; title=&quot;Country, Northeastern Corinthia&quot; alt=&quot;Country, Northeastern Corinthia&quot;/&gt;&lt;/p&gt;


&lt;p&gt;On the weekends, I usually try not to stay in Glyfada. Sometimes I go to country. There, I may invite friends and go out or stay at home.&lt;/p&gt;


&lt;p&gt;Usually, in the afternoon I go for a run.&amp;#0160;Τhere is a 10 km route from my house to the next village. Because of the uphill road on the way back, it takes me 51-53 minutes to run.&lt;/p&gt;


&lt;p&gt;I always try to run the route in less than 51 minutes. Nevertheless most of the time I can not do it - either&amp;#0160;I start too fast (doing first 5KM below 26 minutes) and then get tired or I begin slowly and on the way back it&amp;#39;s impossible to go that fast.&lt;/p&gt;


&lt;p&gt;However, the last time I run there&amp;#0160;I started fast, faster than any other time. Reached the 5KM point (the next village) on ~20 minutes and on my way back it took me other ~27 minutes. This is a total of ~47 minutes (!).&lt;/p&gt;


&lt;p&gt;Obviously, that was a personal record.&lt;/p&gt;


&lt;p&gt;The reason I write all these, is because that one (and only) time that I&amp;#39;ve made it below 50 minutes,&amp;#0160;I was running with loosed laces on the right shoe, plus the shoes were not running shoes at all. I noticed the loose lace when I had already started, but I could not do anything since I didn&amp;#39;t want to stop the timer.&lt;/p&gt;


&lt;p&gt;What I&amp;#39;ve learned is that, the equiment (non-running shoes) and the conditions (loosed laces) doesn&amp;#39;t really matter.&lt;/p&gt;


&lt;p&gt;What it does matter&amp;#0160;is how one truly wants to do something.&lt;/p&gt;


&lt;p&gt;Τhe same applies for software.&lt;/p&gt;



</description>
			<pubDate>Tue, 23 Aug 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Enabling Add-In functionality in ASP.NET MVC 3 (Part 2)</title>
			<link>http://nikosbaxevanis.com/2011/08/22/enabling-add-in-functionality-in-asp-net-mvc-3-part-2</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/08/22/enabling-add-in-functionality-in-asp-net-mvc-3-part-2</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;In this &lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2011/08/enabling-add-in-functionality-in-aspnet-mvc3.html&quot; target=&quot;_blank&quot; title=&quot;Enabling Add-In functionality in ASP.NET MVC 3&quot;&gt;post&lt;/a&gt; I discussed the implementation of a&amp;#0160;Unity-specific controller factory &amp;#0160;that could take&amp;#0160;a delegate as a parameter in the constructor acting as the fallback factory when the DI container can not supply a controller.&lt;/p&gt;


&lt;p&gt;However, I did not really like the initial design. There are cases when the UnityControllerFactory can be used standalone without third party extensiblity in mind.&lt;/p&gt;


&lt;p&gt;One possible improvement in the design is to introduce a &lt;a href=&quot;http://en.wikipedia.org/wiki/Composite_pattern&quot; target=&quot;_blank&quot; title=&quot;Composite Pattern&quot;&gt;composite&lt;/a&gt; implementation for an IControllerFactory. That way, we still have the chance to supply a MEF-specific controller factory.&lt;/p&gt;


&lt;p&gt;A possible implementation of the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.mvc.icontrollerfactory.createcontroller.aspx&quot; target=&quot;_blank&quot; title=&quot;Creates the specified controller by using the specified request context.&quot;&gt;CreateController&lt;/a&gt; method is the one below:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public override IController CreateController(
   RequestContext requestContext, 
   string controllerName)
{
    return (from factory in this.Factories
            let controller = factory.CreateController(
                requestContext, controllerName)
            where controller != null
            select controller).FirstOrDefault();
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;It will iterate through all controller factories calling their CreateController method. The first IController instance provided by the controller factories is returned.&lt;/p&gt;


&lt;p&gt;With this implementation, if the Unity-specific controller factory can not provide an IController instance we will ask the next controller factory (MEF-specific controller factory in this example) to provide the IController instance, and so on.&lt;/p&gt;


&lt;p&gt;The&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/dd460275.aspx&quot; target=&quot;_blank&quot; title=&quot;Sets the specified controller factory.&quot;&gt;SetControllerFactory&lt;/a&gt;&amp;#0160;method can accept an instance of a CompositeControllerFactory type as shown below:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;private static void BootstrapContainer()
{
    // No direct reference on the container outside this method.
    var unityControllerFactory = new UnityControllerFactory(
        new UnityContainer()
            .Install(Registrator.ForControllers,
                     Registrator.ForServices,
                     Registrator.ForEnterpriseLibrary));


    string extensionsPath = Path.Combine(
        AppDomain.CurrentDomain.BaseDirectory, &amp;quot;Extensions&amp;quot;);

    var discoverableControllerFactory = new DiscoverableControllerFactory(
        new CompositionContainer(
            new DirectoryCatalog(extensionsPath))
            );

    ControllerBuilder.Current.SetControllerFactory(
        new CompositeControllerFactory(
            unityControllerFactory, 
            discoverableControllerFactory)
            );
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;&lt;a href=&quot;https://github.com/moodmosaic/System.Web.Mvc.Composition/blob/master/Src/System.Web.Mvc.Composition/CompositeControllerFactory.cs&quot; target=&quot;_blank&quot; title=&quot;CompositeControllerFactory.cs&quot;&gt;Implementation&lt;/a&gt;,&amp;#0160;&lt;a href=&quot;https://github.com/moodmosaic/System.Web.Mvc.Composition/blob/master/Src/System.Web.Mvc.CompositionUnitTest/CompositeControllerFactoryFacts.cs&quot; target=&quot;_blank&quot; title=&quot;CompositeControllerFactoryFacts.cs&quot;&gt;Unit tests&lt;/a&gt;&amp;#0160;and &lt;a href=&quot;http://nuget.org/List/Packages/System.Web.Mvc.Composition&quot; target=&quot;_blank&quot; title=&quot;System.Web.Mvc.Composition&quot;&gt;NuGet Package&lt;/a&gt;.&amp;#0160;Sample application available &lt;a href=&quot;http://goo.gl/bcye3&quot; target=&quot;_blank&quot; title=&quot;ExtensibleMvcApplicationDemo-Part2.zip&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;



</description>
			<pubDate>Mon, 22 Aug 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Enabling Add-In functionality in ASP.NET MVC 3</title>
			<link>http://nikosbaxevanis.com/2011/08/08/enabling-add-in-functionality-in-asp-net-mvc-3</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/08/08/enabling-add-in-functionality-in-asp-net-mvc-3</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;&lt;strong&gt;Update:&amp;#0160;&lt;/strong&gt;&amp;#0160;&lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2011/08/enabling-add-in-functionality-in-aspnet-mvc3-part2.html&quot; target=&quot;_blank&quot; title=&quot;Enabling Add-In functionality in ASP.NET MVC 3 (Part 2)&quot;&gt;Part 2&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;I remember, back in 2006 when I wrote my first managed add-in for AutoCAD. The fact that we could extend the functionality of a very big product, using .NET was huge. Till that time, if we wanted to use .NET for add-in functionality we had to rely on &lt;a href=&quot;http://en.wikipedia.org/wiki/Runtime_Callable_Wrapper&quot; target=&quot;_blank&quot; title=&quot;Runtime Callable Wrapper&quot;&gt;RCW&lt;/a&gt;&amp;#0160;or else we had to&amp;#0160;write messy and error-prone VBA code.&amp;#0160;&lt;/p&gt;


&lt;p&gt;Today, anyone who builds applications in managed code (using .NET 4 and above) has built-in&amp;#0160;functionality for extensibility provided by the framework itself. In this post, we will be extending an ASP.NET MVC 3 application. We are going to use Unity as the Dependency Injection (DI) container and the types from the&amp;#0160;System.ComponentModel.Composition namespace (or else, &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.componentmodel.composition.aspx&quot; target=&quot;_blank&quot; title=&quot;Managed Extensibility Framework, or MEF&quot;&gt;MEF&lt;/a&gt;) for managing the composition of parts.&lt;/p&gt;


&lt;p&gt;The host application, is the one shown below. I have selected the interesting types that I will be discussing.&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8071/8397466245_72d78ba23d_o.png&quot; alt=&quot;The types that I will be discussing&quot; /&gt;&lt;/p&gt;




&lt;h2&gt;DiscoverableControllerFactory&lt;/h2&gt;


&lt;p&gt;A MEF-specific &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.mvc.defaultcontrollerfactory.aspx&quot; target=&quot;_blank&quot; title=&quot;Represents the controller factory that is registered by default.&quot;&gt;DefaultControllerFactory&lt;/a&gt;&amp;#0160;derived type. It&amp;#0160;gets the exported types with the contract name, derived from an IController type. After the controller is supplied, the MVC framework will resolve the Views.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;internal sealed class DiscoverableControllerFactory : DefaultControllerFactory
{
    private readonly CompositionContainer compositionContainer;

    public DiscoverableControllerFactory(
        CompositionContainer compositionContainer)
    {
        this.compositionContainer = compositionContainer;
    }

    public override IController CreateController(
        RequestContext requestContext, 
        string controllerName)
    {
        Lazy&amp;lt;IController&amp;gt; controller = this.compositionContainer
          .GetExports&amp;lt;IController, IDictionary&amp;lt;string, object&amp;gt;&amp;gt;()
          .Where(c =&amp;gt; c.Metadata.ContainsKey(&amp;quot;controllerName&amp;quot;)
                   &amp;amp;&amp;amp; c.Metadata[&amp;quot;controllerName&amp;quot;].ToString() == controllerName)
          .First();

        return controller.Value;
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;h2&gt;UnityControllerFactory&lt;/h2&gt;


&lt;p&gt;A Unity-specific DefaultControllerFactory&amp;#0160;&amp;#0160;derived type. There are many implementations around. The difference from other implementations is that this one takes a delegate as a parameter in the constructor that acts as the fallback factory when the DI container can not supply a controller. This is a very important part of our architecture because here we have the chance to supply the target controller (as an add-in)&amp;#0160;using&amp;#0160;MEF.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;internal sealed class UnityControllerFactory : DefaultControllerFactory
{
    private readonly UnityContainer container;
    private Func&amp;lt;RequestContext, string, IController&amp;gt; alternativeFactoryMethod;

    public UnityControllerFactory(
        UnityContainer container,
        Func&amp;lt;RequestContext, string, IController&amp;gt; alternativeFactoryMethod)
    {
        this.container = container;
        this.alternativeFactoryMethod = alternativeFactoryMethod;
    }

    protected override IController GetControllerInstance(
        RequestContext requestContext, 
        Type controllerType)
    {
        IController controller;

        if (controllerType == null)
        {
            try
            {
                string controllerName = requestContext.HttpContext
                    .Request.Path.Replace(&amp;quot;/&amp;quot;, &amp;quot;&amp;quot;);
                return this.alternativeFactoryMethod(
                    requestContext, 
                    controllerName);
            }
            catch
            {
                throw new HttpException(404, string.Format(
                    &amp;quot;The controller for path '{0}' could not be found or it 
                        does not implement IController.&amp;quot;,
                    requestContext.HttpContext.Request.Path));
            }
        }

        if (!typeof(IController).IsAssignableFrom(controllerType))
        {
            throw new ArgumentException(string.Format(
                &amp;quot;Type requested is not a controller: {0}&amp;quot;, controllerType.Name),
                 &amp;quot;controllerType&amp;quot;);
        }

        try
        {
            controller = container.Resolve(controllerType) as IController;
        }
        catch (Exception e)
        {
            throw new InvalidOperationException(string.Format(
                &amp;quot;Error resolving controller {0}&amp;quot;, controllerType.Name), e);
        }

        return controller;
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;h2&gt;Global.asax&lt;/h2&gt;


&lt;p&gt;Here we specify the default path for the extensions. We create a new instance of the DiscoverableControllerFactory class passing a CompositionContainer and a DirectoryCatalog. Keep in mind that the DirectoryCatalog is one of the many choices that MEF provides for discovering parts. Besides the creation of the&amp;#0160;DiscoverableControllerFactory we also create a new instance of the UnityControllerFactory class acting as the default controller factory. Any controllers that this factory can not supply will fallback to the DiscoverableControllerFactory using it&amp;#39;s CreateController method. One last thing to note, this is the application&amp;#39;s&amp;#0160;&lt;a href=&quot;http://blog.ploeh.dk/2011/07/28/CompositionRoot.aspx&quot; target=&quot;_blank&quot; title=&quot;Composition Root&quot;&gt;Composition Root&lt;/a&gt;. The DI container is referenced here, where the composition happens, and&amp;#0160;&lt;span style=&quot;text-decoration: underline;&quot;&gt;nowhere else&lt;/span&gt;&amp;#0160;in the entire application.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;private static void BootstrapContainer()
{
    string extensionsPath = Path.Combine(
        AppDomain.CurrentDomain.BaseDirectory, &amp;quot;Extensions&amp;quot;);

    var discoverableControllerFactory = new DiscoverableControllerFactory(
        new CompositionContainer(
            new DirectoryCatalog(extensionsPath)));

    // No direct reference on the container outside this method.
    var unityControllerFactory = new UnityControllerFactory(
        new UnityContainer()
            .Install(Registrator.ForControllers,
                     Registrator.ForServices,
                     Registrator.ForEnterpriseLibrary),
        fallbackFactoryMethod: discoverableControllerFactory.CreateController);

    ControllerBuilder.Current.SetControllerFactory(unityControllerFactory);
}

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();

    RegisterGlobalFilters(GlobalFilters.Filters);
    RegisterRoutes(RouteTable.Routes);

    BootstrapContainer();
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;The add-in application is a regular class library and it&amp;#39;s structure is shown below. I have selected the interesting types that I will be discussing.&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8077/8397466255_c4bcf9152a_o.png&quot; alt=&quot;The types that I will be discussing&quot; /&gt;&lt;/p&gt;




&lt;h2&gt;ConceptController&lt;/h2&gt;


&lt;p&gt;This is a proof of concept&amp;#0160;Controller for this demo. It is decorated with the&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.componentmodel.composition.exportattribute.aspx&quot; target=&quot;_blank&quot; title=&quot;Specifies that a type, property, field, or method provides a particular export.&quot;&gt;ExportAttribute&lt;/a&gt;&amp;#0160;and&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.componentmodel.composition.exportmetadataattribute.aspx&quot; target=&quot;_blank&quot; title=&quot;Specifies metadata for a type, property, field, or method marked with the ExportAttribute.&quot;&gt;ExportMetadataAttribute&lt;/a&gt;. The later is needed in order to help the DiscoverableControllerFactory to choose the right controller among all the controllers supplied by this and other add-ins. The&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.componentmodel.composition.partcreationpolicyattribute.aspx&quot; target=&quot;_blank&quot; title=&quot;Specifies the CreationPolicy for a part.&quot;&gt;PartCreationPolicyAttribute&lt;/a&gt;&amp;#0160;is needed in order to specify that a new non-shared (transient) instance will be created for each request.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Export(typeof(IController)), ExportMetadata(&amp;quot;controllerName&amp;quot;, &amp;quot;Concept&amp;quot;)]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class ConceptController : Controller
{
    public ActionResult Index()
    {
        ViewBag.Name = this.GetType().Assembly.FullName;

        return View(&amp;quot;~/Extensions/Views/Concept/Index.cshtml&amp;quot;);
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;h2&gt;Index.cshtml, Web.config&lt;/h2&gt;


&lt;p&gt;Nothing special to say here. The razor view is just any other (razor) view. The Web.config is needed as a hint for the MVC framework to compile the razor views at runtime.&lt;/p&gt;


&lt;blockquote&gt;
&lt;p&gt;Make sure to select all the views and set the property &amp;quot;Copy to Output directory&amp;quot; to &amp;quot;&lt;em&gt;Copy if newer&amp;quot;. &lt;/em&gt;This is important because each time we compile the add-in library besides the .dll with the models and the controllers we also want the views to be copied there (they are also part of the add-in).&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;You can download the demo application &lt;a href=&quot;http://goo.gl/kX4ZP&quot; target=&quot;_blank&quot; title=&quot;ExtensibleMvcApplicationDemo-Part1.zip&quot;&gt;here&lt;/a&gt;. Upon build the Concepts.dll along with it&amp;#39;s Views will be copied in the Web project&amp;#39;s &amp;quot;Extensions&amp;quot; directory. When run, the application will automatically load the assembly the first time the &amp;quot;Concepts&amp;quot; tab is pressed.&lt;/p&gt;


&lt;ul&gt;
&lt;/ul&gt;



</description>
			<pubDate>Mon, 08 Aug 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>The Small Shelf</title>
			<link>http://nikosbaxevanis.com/2011/08/07/the-small-shelf</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/08/07/the-small-shelf</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8329/8398548102_8136765cd3_o.png&quot; alt=&quot;The shelf in my library where I store my favorite books&quot; /&gt;&lt;/p&gt;




&lt;p&gt;The &amp;quot;small shelf&amp;quot; is a shelf in my library where I store my favorite books on Software Development. I like to write code and I am not looking forward to stop, so there are no books there about management (at least, yet).&lt;/p&gt;


&lt;p&gt;At the moment, the titles are (from right to left):&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.co.uk/Code-Complete-Practical-Handbook-Construction/dp/0735619670/ref=wl_it_dp_o?ie=UTF8&amp;amp;coliid=IE2595W60WCL4&amp;amp;colid=19397BGFN5DJH&quot; target=&quot;_blank&quot; title=&quot;Code Complete: A Practical Handbook of Software Construction by Steve McConnell&quot;&gt;Code Complete: A Practical Handbook of Software Construction&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.co.uk/CLR-via-3rd-Jeffrey-Richter/dp/0735627045/ref=wl_it_dp_o?ie=UTF8&amp;amp;coliid=I2QDLQQLXWKJSW&amp;amp;colid=19397BGFN5DJH&quot; target=&quot;_blank&quot; title=&quot;CLR via C# 3rd Edition by Jeffrey Richter&quot;&gt;CLR via C# 3rd Edition&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.co.uk/Framework-Design-Guidelines-Conventions-Development/dp/0321545613/ref=wl_it_dp_o?ie=UTF8&amp;amp;coliid=I3NMZD949VN2M8&amp;amp;colid=19397BGFN5DJH&quot; target=&quot;_blank&quot; title=&quot;Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries by Krzysztof Cwalina&quot;&gt;Framework Design Guidelines 2nd Edition&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.co.uk/Enterprise-Application-Architecture-Addison-Wesley-Signature/dp/0321127420/ref=wl_it_dp_o?ie=UTF8&amp;amp;coliid=I1S8PWZ4KAALG5&amp;amp;colid=19397BGFN5DJH&quot; target=&quot;_blank&quot; title=&quot;Patterns of Enterprise Application Architecture by Martin Fowler&quot;&gt;Patterns of Enterprise Application Architecture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.co.uk/Domain-driven-Design-Tackling-Complexity-Software/dp/0321125215/&quot; target=&quot;_blank&quot; title=&quot;Domain-driven Design: Tackling Complexity in the Heart of Software by Eric Evans&quot;&gt;Domain-driven Design: Tackling Complexity in the Heart of Software&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.co.uk/Release-Production-Ready-Software-Pragmatic-Programmers/dp/0978739213/ref=wl_it_dp_o?ie=UTF8&amp;amp;coliid=I32DDNTOT2LPKC&amp;amp;colid=19397BGFN5DJH&quot; target=&quot;_blank&quot; title=&quot;Release It!: Design and Deploy Production-Read​y Software by Michael T. Nygard&quot;&gt;Release It!: Design and Deploy Production-Read​y Software&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.co.uk/Dependency-Injection-NET-Mark-Seemann/dp/1935182501&quot; target=&quot;_blank&quot; title=&quot;Dependency Injection in .NET by Mark Seemann&quot;&gt;Dependency Injection in .NET&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.co.uk/xUnit-Test-Patterns-Refactoring-Signature/dp/0131495054/ref=wl_it_dp_o?ie=UTF8&amp;amp;coliid=IQQRNYGEWLPM7&amp;amp;colid=19397BGFN5DJH&quot; target=&quot;_blank&quot; title=&quot;xUnit Test Patterns: Refactoring Test Code by Gerard Meszaros&quot;&gt;xUnit Test Patterns: Refactoring Test Code&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.co.uk/Growing-Object-Oriented-Software-Guided-Tests/dp/0321503627&quot; target=&quot;_blank&quot; title=&quot;Growing Object-Oriented Software, Guided by Tests by Steve Freeman, and Nat Pryce&quot;&gt;Growing Object-Oriented Software, Guided by Tests&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.co.uk/Real-World-Functional-Programming-Examples/dp/1933988924&quot; target=&quot;_blank&quot; title=&quot;Real-World Functional Programming: With Examples in F# and C# by Tomas Petricek, and Jon Skeet&quot;&gt;Real-World Functional Programming: With Examples in F# and C#&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;ul&gt;
&lt;/ul&gt;


&lt;p&gt;Due to the small dimensions of the shelf, when I want to store a new book I have to remove one so I need to carefully consider which one I should remove. Pretty neat process isn&amp;#39;t it?&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8226/8398547870_0b62dd015c_o.png&quot; alt=&quot;Some books not in the shelf&quot; /&gt;&lt;/p&gt;




&lt;p&gt;Here are some books not in the shelf, the three from the bottom where recently removed. That doesn&amp;#39;t mean they are not good, or I don&amp;#39;t like them, or I haven&amp;#39;t read them (in any way).&lt;/p&gt;


&lt;p&gt;By they way, these are (from bottom to top):&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.co.uk/NHibernate-3-0-Cookbook-Jason-Dentler/dp/184951304X/ref=wl_it_dp_o?ie=UTF8&amp;amp;coliid=I1P3Y3RARP8QAT&amp;amp;colid=19397BGFN5DJH&quot; target=&quot;_blank&quot; title=&quot;NHibernate 3.0 Cookbook by Jason Dentler&quot;&gt;NHibernate 3.0 Cookbook&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.co.uk/Old-New-Thing-Development-Throughout/dp/0321440307/ref=wl_it_dp_o?ie=UTF8&amp;amp;coliid=I39Q726IL6JVVU&amp;amp;colid=19397BGFN5DJH&quot; target=&quot;_blank&quot; title=&quot;The Old New Thing: Practical Development Throughout the Evolution of Windows by Raymond Chen&quot;&gt;The Old New Thing: Practical Development Throughout the Evolution of Windows&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.co.uk/Kanban-David-J-Anderson/dp/0984521402/ref=wl_it_dp_o?ie=UTF8&amp;amp;coliid=I15H19AQJB5RIQ&amp;amp;colid=19397BGFN5DJH&quot; target=&quot;_blank&quot; title=&quot;Kanban by David J. Anderson&quot;&gt;Kanban&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.co.uk/HTML5-CSS3-Tomorrows-Standards-Programmers/dp/1934356689/ref=wl_it_dp_o?ie=UTF8&amp;amp;coliid=I29VATAH0LV7SD&amp;amp;colid=19397BGFN5DJH&quot; target=&quot;_blank&quot; title=&quot;HTML5 and CSS3: Develop with Tomorrow&amp;#39;s Standards Today by Brian P. Hogan&quot;&gt;HTML5 and CSS3: Develop with Tomorrow&amp;#39;s Standards Today&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.co.uk/Lean-Architecture-Agile-Software-Development/dp/0470684208/ref=wl_it_dp_o?ie=UTF8&amp;amp;coliid=I19CZ5Q1SNFX21&amp;amp;colid=19397BGFN5DJH&quot; target=&quot;_blank&quot; title=&quot;Lean Architecture: for Agile Software Development by James O. Coplien&quot;&gt;Lean Architecture: for Agile Software Development&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;The last two are new, I received the past weeks.&lt;/p&gt;


&lt;p&gt;I am curious with HTML5, I think in the following years there is going to be a switch to a unified presentation model using the combination of HTML5, CSS3 and JavaScript. I also believe that using this model, any access to external systems/services/etc is going to happen in a RESTfull way. For that reason, on my Kindle&amp;#0160;device among other is&amp;#0160;&lt;a href=&quot;http://www.amazon.co.uk/REST-Practice-Hypermedia-Systems-Architecture/dp/0596805829/ref=sr_1_1?ie=UTF8&amp;amp;qid=1312710691&amp;amp;sr=8-1&quot; target=&quot;_blank&quot; title=&quot;REST in Practice: Hypermedia and Systems Architecture by Jim Webber, Savas Parastatidis and Ian Robinson&quot;&gt;REST in Practice: Hypermedia and Systems Architecture&lt;/a&gt;. I use Kindle a lot, specially &lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2011/06/embrace-the-web.html&quot; target=&quot;_blank&quot;&gt;when&lt;/a&gt; I&amp;#39;m on the plane.&lt;/p&gt;


&lt;p&gt;Finally, I currently maintain three Amazon.co.uk wish lists, which I have publicly available:&lt;/p&gt;


&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.co.uk/registry/wishlist/19397BGFN5DJH/ref=cm_wl_rlist_go&quot; target=&quot;_blank&quot;&gt;Books&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.co.uk/registry/wishlist/R8UIH1AFSR4G/ref=cm_wl_rlist_go&quot; target=&quot;_blank&quot;&gt;E-books&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.co.uk/registry/wishlist/DEFDF6UV9QS9/ref=cm_wl_rlist_go&quot; target=&quot;_self&quot;&gt;Recently Viewed&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;The last one helps me a lot, since I can save there the book titles I come across and later I can decide what I will buy.&lt;/p&gt;



</description>
			<pubDate>Sun, 07 Aug 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Following the Composition Root pattern with Enterprise Library</title>
			<link>http://nikosbaxevanis.com/2011/08/04/following-the-composition-root-pattern-with-enterprise-library</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/08/04/following-the-composition-root-pattern-with-enterprise-library</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;A question that frequently rises when building enterprise applications is: &lt;em&gt;&amp;quot;Where should we compose object graphs?&amp;quot; &lt;/em&gt;and the answer is given by the Composition Root pattern:&amp;#0160;&lt;em&gt;&amp;quot;As close as possible to the applications entry point.&amp;quot;&lt;/em&gt;&lt;/p&gt;


&lt;p&gt;The Composition Root pattern is&amp;#0160;described in the excellent&amp;#0160;&lt;a href=&quot;http://manning.com/seemann/&quot; target=&quot;_blank&quot; title=&quot;Dependency Injection in .NET (Mark Seemann)&quot;&gt;book&lt;/a&gt;, Dependency Injection in .NET by Mark Seemann.&lt;/p&gt;


&lt;p&gt;Here is the definition from the book:&lt;em&gt;&lt;br /&gt;&lt;/em&gt;&lt;/p&gt;


&lt;blockquote&gt;
&lt;p&gt;A Composition Root is a (preferably) unique location in an application where modules are composed&amp;#0160;together.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;When working with the Enterprise Library, it is very common to hide the complexities of initial context creation by&amp;#0160;using the built-in IServiceLocator implementation provided by the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/microsoft.practices.enterpriselibrary.common.configuration.enterpriselibrarycontainer(v=pandp.50).aspx&quot; target=&quot;_blank&quot; title=&quot;Entry point for the container infrastructure for Enterprise Library.&quot;&gt;EnterpriseLibraryContainer&lt;/a&gt;&amp;#0160;class.&lt;/p&gt;


&lt;p&gt;Since I completely agree with the statement &amp;quot;&lt;a href=&quot;http://blog.ploeh.dk/2010/02/03/ServiceLocatorIsAnAntiPattern.aspx&quot; target=&quot;_blank&quot;&gt;Service Locator is an Anti-Pattern&lt;/a&gt;&amp;quot; I would like to compose all Enterprise Library modules in the Composition Root. Then, I can use well-known DI patterns (such as Constructor Injection) to supply the Dependencies.&lt;/p&gt;


&lt;p&gt;Fortunately, the EnterpriseLibraryContainer class contains a method named &amp;quot;ConfigureContainer&amp;quot; that reads the current configuration and supplies the corresponding type information to configure a dependency injection container (by default Unity).&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;var configurator = new UnityContainerConfigurator(container);
var configSource = ConfigurationSourceFactory.Create();

EnterpriseLibraryContainer.ConfigureContainer(configurator, configSource);&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;After configuring the container in the Composition Root we can resolve any instance of a type from Enterprise Library as with any other object.&lt;/p&gt;



</description>
			<pubDate>Thu, 04 Aug 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Creating JSON-enabled ViewModels</title>
			<link>http://nikosbaxevanis.com/2011/07/17/creating-json-enabled-viewmodels</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/07/17/creating-json-enabled-viewmodels</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Recently, Ian Randall&amp;nbsp;contributed something really cool to the DynamicViewModel codebase:&amp;nbsp;Support for binding to a JSON object.&amp;nbsp;I find this exciting!&amp;nbsp;&lt;/p&gt;


&lt;p&gt;In the trunk of DynamicViewModel you can find an example that uses the Stack Exchange API. It is a WPF application for searching the Stack Overflow Users.&amp;nbsp;&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8045/8398555224_d4ecaec7ae_o.png&quot; alt=&quot;Screenshot of the demo application&quot; /&gt;&lt;/p&gt;




&lt;p&gt;All API responses are JSON in Stack Exchange API. Ian took advantage of that and wrote a DynamicViewModelFactory that contains the factory method below:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public static DynamicViewModel Create(string json)
{
    DynamicViewModel result;
    if (!json.TryCreateDynamic(out result))
    {
        throw new ArgumentException(&amp;quot;parameter was not a valid JSON string&amp;quot;);
    }

    return result;
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;This factory method creates an instance of a DynamicViewModel from a JSON formatted string. In order to use it you need to write code similar to the one below:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;var uriString = &amp;quot;http://api.stackoverflow.com/1.1/users?filter=&amp;quot; + e.Argument;
var request   = CreateHttpWebRequest(uriString);
var response  = request.GetResponse();

using (var streamReader = new StreamReader(response.GetResponseStream()))
{
    var json = streamReader.ReadToEnd();
    dynamic viewModel = DynamicViewModelFactory.Create(json);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;And some XAML action:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;&amp;lt;TextBlock
    Grid.Column=&amp;quot;0&amp;quot;
    VerticalAlignment=&amp;quot;Center&amp;quot;
    Margin=&amp;quot;4,0,0,0&amp;quot;
    Text=&amp;quot;{Binding display_name}&amp;quot; /&amp;gt;
&amp;lt;TextBlock
    Grid.Column=&amp;quot;1&amp;quot;
    VerticalAlignment=&amp;quot;Center&amp;quot;
    Text=&amp;quot;{Binding reputation}&amp;quot; /&amp;gt;

&amp;lt;local:BadgesUserControl
    Grid.Column=&amp;quot;2&amp;quot;
    DataContext=&amp;quot;{Binding badge_counts}&amp;quot; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;The source code is &lt;a href=&quot;http://dynamicviewmodel.codeplex.com/SourceControl/list/changesets&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. Thanks to&amp;nbsp;&lt;a href=&quot;http://xaml.geek.nz/contact&quot; target=&quot;_self&quot;&gt;Ian Randall&lt;/a&gt;!&lt;/p&gt;

</description>
			<pubDate>Sun, 17 Jul 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Async REST Client for the Scrumy API</title>
			<link>http://nikosbaxevanis.com/2011/07/17/async-rest-client-for-the-scrumy-api</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/07/17/async-rest-client-for-the-scrumy-api</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;I am a big fan of &lt;a title=&quot;Scrumy is a simple and intuitive virtual task board based on some concepts of Scrum that helps organize and manage your projects.&quot; href=&quot;http://scrumy.com/&quot; target=&quot;_blank&quot;&gt;Scrumy&lt;/a&gt;, I must admit that! Scrumy is &lt;em&gt;a simple and intuitive virtual task board based on some concepts of Scrum that helps organize and manage your projects (scrumy.com)&lt;/em&gt;.&amp;nbsp;&lt;/p&gt;


&lt;p&gt;The last weeks I have been thinking of a Visual Studio Extension for viewing (and interacting with) an entire Scrum (Sprints, Stories, Tasks, etc) from inside the IDE.&amp;nbsp;I started building a client library around the Scrumy REST API. I wanted it to be fully asynchronous because I would like to make the Extension UI responsive.&lt;/p&gt;


&lt;p&gt;Back a few months ago, I was watching a 5hr webcast on Windows Azure called &lt;a title=&quot;Windows Azure Deep Dive with Jeffrey Richter: Explore the Benefits of Windows Azure Data Storage and Compute Services&quot; href=&quot;http://www.wintellect.com/CS/blogs/jeffreyr/archive/2011/04/05/windows-azure-deep-dive-with-jeffrey-richter-explore-the-benefits-of-windows-azure-data-storage-and-compute-services.aspx&quot; target=&quot;_blank&quot;&gt;Windows Azure Deep Dive with Jeffrey Richter&lt;/a&gt; were Jeffrey Richter&amp;nbsp;shared among the (fantastic code samples) a fully asynchronous HttpRestClient class. This class is making heavy use of the&amp;nbsp;&lt;a title=&quot;AsyncEnumerator uses C# language features to simplify asynchronous programming.&quot; href=&quot;http://msdn.microsoft.com/en-us/magazine/cc721613.aspx&quot; target=&quot;_blank&quot;&gt;AsyncEnumerator&lt;/a&gt; class (which I am big fan of, till C# 5.0 with async is out) so I though I should build my client around the HttpRestClient class and make also use of the AsyncEnumerator class.&lt;/p&gt;


&lt;p&gt;I started by looking at the GET response:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='xml'&gt;&amp;lt;scrumy&amp;gt;
    &amp;lt;created-at&amp;gt;2011-06-24T21:49:57Z&amp;lt;/created-at&amp;gt;
    &amp;lt;time-zone&amp;gt;Central Time (US &amp;amp; Canada)&amp;lt;/time-zone&amp;gt;
    &amp;lt;updated-at&amp;gt;2011-06-24T23:38:50Z&amp;lt;/updated-at&amp;gt;
    &amp;lt;url&amp;gt;nikos&amp;lt;/url&amp;gt;
&amp;lt;/scrumy&amp;gt;

&amp;lt;sprints type=&amp;quot;array&amp;quot;&amp;gt;
    &amp;lt;sprint&amp;gt;
        &amp;lt;created-at&amp;gt;2011-06-24T21:50:53Z&amp;lt;/created-at&amp;gt;
        &amp;lt;id&amp;gt;186884&amp;lt;/id&amp;gt;
        &amp;lt;start-date&amp;gt;2011-06-24&amp;lt;/start-date&amp;gt;
        &amp;lt;updated-at&amp;gt;2011-06-24T21:50:53Z&amp;lt;/updated-at&amp;gt;
        &amp;lt;scrumy-url&amp;gt;nikos&amp;lt;/scrumy-url&amp;gt;
    &amp;lt;/sprint&amp;gt;
&amp;lt;/sprints&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Then I created the corresponding&amp;nbsp;classes:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;/// &amp;lt;example&amp;gt;
///     &amp;lt;scrumy&amp;gt;
///         &amp;lt;created-at&amp;gt;2011-06-24T21:49:57Z&amp;lt;/created-at&amp;gt;
///         &amp;lt;time-zone&amp;gt;Central Time (US &amp;amp; Canada)&amp;lt;/time-zone&amp;gt;
///         &amp;lt;updated-at&amp;gt;2011-06-24T21:57:08Z&amp;lt;/updated-at&amp;gt;
///         &amp;lt;url&amp;gt;nikos&amp;lt;/url&amp;gt;
///     &amp;lt;/scrumy&amp;gt;
/// Editable fields: url, time_zone
/// &amp;lt;/example&amp;gt;
public sealed class Scrumy
{
    public DateTimeOffset CreatedAt { get; set; }

    public string TimeZone { get; set; }

    public DateTimeOffset UpdatedAt { get; set; }

    public string Url { get; set; }
}

/// &amp;lt;example&amp;gt;
///     &amp;lt;sprints type=&amp;quot;array&amp;quot;&amp;gt;
///        &amp;lt;sprint&amp;gt;
///            &amp;lt;created-at&amp;gt;2011-06-24T21:50:53Z&amp;lt;/created-at&amp;gt;
///            &amp;lt;id&amp;gt;186884&amp;lt;/id&amp;gt;
///            &amp;lt;start-date&amp;gt;2011-06-24&amp;lt;/start-date&amp;gt;
///            &amp;lt;updated-at&amp;gt;2011-06-24T21:50:53Z&amp;lt;/updated-at&amp;gt;
///            &amp;lt;scrumy-url&amp;gt;nikos&amp;lt;/scrumy-url&amp;gt;
///        &amp;lt;/sprint&amp;gt;
///    &amp;lt;/sprints&amp;gt;
/// Editable fields: url, time_zone
/// &amp;lt;/example&amp;gt;
public sealed class Sprint
{
    public DateTimeOffset CreatedAt { get; set; }

    public int Id { get; set; }

    public DateTimeOffset StartDate { get; set; }

    public DateTimeOffset UpdatedAt { get; set; }

    public string ScrumyUrl { get; set; }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Next I included generic Begin/End methods for supporting the APM inside my class:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;private IAsyncResult BeginRequest(
     ScrumyRequest request, 
     Func&amp;lt;XElement, ScrumyResponse&amp;gt; processor, 
     AsyncCallback callback = null,
     object state = null)
{
    var ae = new AsyncEnumerator&amp;lt;ScrumyResponse&amp;gt;(
         string.Format(&amp;quot;Method={0}, Uri={1}&amp;quot;, request.Method, request.Uri));
    ae.SyncContext = null;
    return apmWrap.Return(ae,
        ae.BeginExecute(MakeRequest(ae, request, processor),
            apmWrap.Callback(ae, callback), state));
}

private new TResponse EndRequest&amp;lt;TResponse&amp;gt;(IAsyncResult result) 
     where TResponse : ScrumyResponse
{
    return (TResponse)apmWrap.Unwrap(ref result).EndExecute(result);
}

private IEnumerator&amp;lt;int&amp;gt; MakeRequest(
     AsyncEnumerator&amp;lt;ScrumyResponse&amp;gt; ae, 
     ScrumyRequest request, 
     Func&amp;lt;XElement, ScrumyResponse&amp;gt; processor)
{
    base.BeginRequest(request.Method, request.Uri, ae.End());
    yield return 1;

    XElement element = base.EndRequestXElement(ae.DequeueAsyncResult());

    ae.Result = processor.Invoke(element);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;With these helper methods, dealing with the APM was trivial when implementing methods for the Scrumy client. Here are the methods I had to write for getting the Sprints:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public IAsyncResult BeginGetScrumy(
     GetScrumyRequest request, 
     AsyncCallback callback = null, 
     object state = null)
{
    Func&amp;lt;XElement, GetScrumyResponse&amp;gt; processor = element =&amp;gt;
    {
        DateTimeOffset createdAt;
        DateTimeOffset.TryParse(
             element.Element(&amp;quot;created-at&amp;quot;).Value, out createdAt);

        DateTimeOffset updatedAt;
        DateTimeOffset.TryParse(
             element.Element(&amp;quot;updated-at&amp;quot;).Value, out updatedAt);

        var scrumy = new Scrumy
        {
            CreatedAt = createdAt,
            TimeZone = element.Element(&amp;quot;time-zone&amp;quot;).Value,
            UpdatedAt = updatedAt,
            Url = element.Element(&amp;quot;url&amp;quot;).Value
        };

        return new GetScrumyResponse { Scrumy = scrumy };
    };

    return BeginRequest(request, processor, callback, state);
}

public GetScrumyResponse EndGetScrumy(IAsyncResult ar)
{
    return EndRequest&amp;lt;GetScrumyResponse&amp;gt;(ar);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;As you notice, only the logic that creates a Sprint object from an XElement is inside the Begin part. Everything else is handled by the helper classes.&lt;/p&gt;


&lt;p&gt;Finally, here is how to use it:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;AsyncEnumerator ae = new AsyncEnumerator();            
ae.BeginExecute(GetSprint(ae), ae.EndExecute);

private IEnumerator&amp;lt;int&amp;gt; GetSprint(AsyncEnumerator ae)
{
    var request = new GetSprintRequest(client.ProjectName);
            
    client.BeginGetSprint(request, ae.End());
    yield return 1;
            
    var response = client.EndGetSprint(ae.DequeueAsyncResult());
    Assert.NotEmpty(response.Sprints);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;I am looking forward building as much as I can and then to continue with the Visual Studio Extension.&lt;/p&gt;


&lt;p&gt;A gist with all the source code can be found &lt;a title=&quot;Asynchronous .NET Client Implementation around the Scrumy REST API.&quot; href=&quot;https://gist.github.com/2850410&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;



</description>
			<pubDate>Sun, 17 Jul 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>The Mood Mosaic Vol. 13</title>
			<link>http://nikosbaxevanis.com/2011/07/03/the-mood-mosaic-vol-13</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/07/03/the-mood-mosaic-vol-13</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;The Mood Mosaic series is a famous Vinyl compilation with Funk, Rare Groove and Disco tracks (&amp;#39;60s-&amp;#39;80s).&lt;/p&gt;


&lt;p&gt;I recently got the&amp;#0160;&lt;a href=&quot;http://www.discogs.com/Various-The-Mood-Mosaic-13-Soul-Seduction/release/1787861&quot; target=&quot;_blank&quot; title=&quot;The Mood Mosaic 13: Soul Seduction&quot;&gt;Vol. 13&lt;/a&gt;&amp;#0160;and I really enjoyed the tracks Closer Closer (Celi Bee &amp;amp; The Fuzzy Bunch)&amp;#0160;and Midnight Groove (Love Unlimited)&amp;#0160;among others.&amp;#0160;For the latter, there is a less known re-edit back from 2005. It can be found on &lt;a href=&quot;http://www.juno.co.uk/products/re-edits-volume-1-ep/180402-01/?ref=NikosBaxevanis&quot; target=&quot;_blank&quot; title=&quot;Love Unlimited Orchestra - Midnight Groove (Edit)&quot;&gt;Juno&lt;/a&gt; and also on &lt;a href=&quot;http://www.discogs.com/sell/list?release_id=501875&amp;amp;ev=rb&quot; target=&quot;_blank&quot; title=&quot;Love Unlimited Orchestra - Midnight Groove (Edit)&quot;&gt;Discogs&lt;/a&gt; marketplace.&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://farm9.staticflickr.com/8194/8398548430_5e3c8ef15c_o.png&quot; target=&quot;_blank&quot; title=&quot;My Technics turntable.&quot;&gt;That&lt;/a&gt;&amp;#0160;is the turntable I have (Technics 1210 M5G).&lt;/p&gt;


&lt;p&gt;Enjoy.&lt;/p&gt;



</description>
			<pubDate>Sun, 03 Jul 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Mono for Android (Threads Window)</title>
			<link>http://nikosbaxevanis.com/2011/06/25/mono-for-android-threads-window</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/06/25/mono-for-android-threads-window</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;(Couldn&amp;#39;t resist..!)&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8215/8398554432_8590d1d44c_o.png&quot; title=&quot;Visual Studio Threads Window&quot; alt=&quot;Visual Studio Threads Window&quot;/&gt;&lt;/p&gt;



</description>
			<pubDate>Sat, 25 Jun 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Don't Rely on SQL Membership Provider database schema</title>
			<link>http://nikosbaxevanis.com/2011/06/23/dont-rely-on-sql-membership-provider-database-schema</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/06/23/dont-rely-on-sql-membership-provider-database-schema</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;You take the blue pill and the story &lt;a href=&quot;http://blogs.teamb.com/craigstuntz/2010/03/05/38558/&quot;&gt;ends&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;However, due to the role-centric nature of many applications, entities rely on the user and it&amp;#39;s role(s).&amp;#0160;On registration, the user choose one or more roles. Each role is associated with behaviors. For each behavior one or more restriction policies apply, etc.&amp;#0160;&lt;/p&gt;


&lt;p&gt;In somes cases, we could decide to take a dependency on the ASP.NET Membership tables and just map on the UserName column of Users table, and the RoleName column of Roles table (also on the UsersInRole table too).&lt;/p&gt;


&lt;p&gt;Fabio has a &lt;a href=&quot;http://fabiomaulo.blogspot.com/2010/03/conform-mapping-aspnet-membership.html&quot; target=&quot;_blank&quot; title=&quot;ConfORM: &amp;quot;Mapping&amp;quot; ASP.NET Membership&quot;&gt;post&lt;/a&gt; on how you can do this using ConfORM. In this post I will map only the User and Role tables. In addition, I will demonstrate an elegant approach of assigning different behaviors on the Role entity and mapping them with the RoleName column on the database.&lt;/p&gt;


&lt;h2&gt;Entities&lt;/h2&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

public class User : Entity&amp;lt;Guid&amp;gt;
{
    public virtual string UserName { get; set; }

    public virtual ICollection&amp;lt;Role&amp;gt; Roles { get; set; }

    public User()
    {
        Roles = new Collection&amp;lt;Role&amp;gt;();
    }
}

public class Role : Entity&amp;lt;Guid&amp;gt;
{
    public virtual string RoleName { get; set; }

    public virtual RoleType RoleType { get; set; }

    public virtual ICollection&amp;lt;User&amp;gt; Users { get; set; }

    public Role()
    {
        Users = new Collection&amp;lt;User&amp;gt;();
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h2&gt;Mappings&lt;/h2&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;using FluentNHibernate.Mapping;

public sealed class UserMap : ClassMap&amp;lt;User&amp;gt;
{
    public UserMap()
    {
        Table(&amp;quot;aspnet_Users&amp;quot;);
        LazyLoad();

        Id(x =&amp;gt; x.Id).GeneratedBy
            .Assigned().Column(&amp;quot;UserId&amp;quot;);

        Map(x =&amp;gt; x.UserName);

        HasManyToMany(x =&amp;gt; x.Roles)
            .Table(&amp;quot;aspnet_UsersInRoles&amp;quot;);
    }
}

public sealed class RoleMap : ClassMap&amp;lt;Role&amp;gt;
{
    public RoleMap()
    {
        Table(&amp;quot;aspnet_Roles&amp;quot;);
        LazyLoad();

        Id(x =&amp;gt; x.Id).GeneratedBy
            .Assigned().Column(&amp;quot;RoleId&amp;quot;);

        Map(x =&amp;gt; x.RoleName);

        HasManyToMany(x =&amp;gt; x.Users)
            .Cascade.All()
            .Inverse()
            .Table(&amp;quot;aspnet_UsersInRoles&amp;quot;);
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;The RoleName property on our domain model is a string, in order to get mapped with the RoleName column of the table in the database schema.&lt;/p&gt;


&lt;p&gt;In order to assign different behaviors on the Role entity we can follow the solution of Jimmy Bogard with the Enumeration class described &lt;a href=&quot;http://lostechies.com/jimmybogard/2008/08/12/enumeration-classes/&quot; target=&quot;_blank&quot; title=&quot;Enumeration classes&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;


&lt;h2&gt;RoleType class&lt;/h2&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public class RoleType : Enumeration
{
    public static readonly RoleType Consumer = new ConsumerType();
    public static readonly RoleType Provider = new ProviderType();
    public static readonly RoleType Referrer = new ReferrerType();

    public static readonly RoleType Administrator = new AdministratorType();

    private RoleType() { }
    private RoleType(int value, string displayName)
        : base(value, displayName) { }

    private sealed class ConsumerType : RoleType
    {
        public ConsumerType()
            : base(0, &amp;quot;Consumer&amp;quot;) { }

        // TODO: Add behavior for Consumer.
    }

    private sealed class ProviderType : RoleType
    {
        public ProviderType()
            : base(1, &amp;quot;Provider&amp;quot;) { }

        // TODO: Add behavior for Provider.
    }

    private sealed class ReferrerType : RoleType
    {
        public ReferrerType()
            : base(2, &amp;quot;Referrer&amp;quot;) { }

        // TODO: Add behavior for Referrer.
    }

    private sealed class AdministratorType : RoleType
    {
        public AdministratorType()
            : base(3, &amp;quot;Administrator&amp;quot;) { }

        // TODO: Add behavior for Administrator.
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Adding an IPostLoadEventListener on NHibernate configuration we can easily add logic to set a specific RoleType to each Role entity.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;private sealed class RoleToRoleTypeEventListener : IPostLoadEventListener
{
    public void OnPostLoad(PostLoadEvent @event)
    {
        User user = @event.Entity as User;
        if (user != null)
        {
            foreach (Role role in user.Roles)
            {
                AssignRoleTypeToRole(role);
            }
        }
        else
        {
            Role role = @event.Entity as Role;
            if (role != null)
            {
                AssignRoleTypeToRole(role);
            }
        }
    }

    private static void AssignRoleTypeToRole(Role role)
    {
        switch (role.RoleName)
        {
            case &amp;quot;Consumer&amp;quot;:
                role.RoleType = RoleType.Consumer;
                break;

            case &amp;quot;Provider&amp;quot;:
                role.RoleType = RoleType.Provider;
                break;

            case &amp;quot;Referrer&amp;quot;:
                role.RoleType = RoleType.Referrer;
                break;

            case &amp;quot;Administrator&amp;quot;:
                role.RoleType = RoleType.Administrator;
                break;
        }
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;The complete Configuration for the ISessionFactory is (or, could be) below:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public static ISessionFactory BuildSessionFactory(IKernel kernel)
{
    var configuration = CreateConfiguration(ForMsSql2008);
    return configuration.BuildSessionFactory();
}

public static FluentConfiguration CreateConfiguration(
     Action&amp;lt;IDbIntegrationConfigurationProperties&amp;gt; db)
{
    var cfg = new NHibernate.Cfg.Configuration();
    cfg.DataBaseIntegration(db)
        .Proxy(p =&amp;gt; p.ProxyFactoryFactory&amp;lt;ProxyFactoryFactory&amp;gt;())
        .SessionFactory()
            .GenerateStatistics();

    cfg.EventListeners.PostLoadEventListeners = 
        new IPostLoadEventListener[] { 
            new RoleToRoleTypeEventListener() };

        return Fluently.Configure(cfg)
            .Mappings(AddMappingTypes);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;..However we already took the red pill and staying in wonderland!&lt;/p&gt;



</description>
			<pubDate>Thu, 23 Jun 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Embrace The Web!</title>
			<link>http://nikosbaxevanis.com/2011/06/04/embrace-the-web</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/06/04/embrace-the-web</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;When I&amp;#39;m on the plane, I usually read (on paper or Kindle). The last time was a couple of weeks ago and I was reading the excellent&amp;#0160;&lt;a href=&quot;http://www.amazon.com/REST-Practice-Hypermedia-Systems-Architecture/dp/0596805829&quot; target=&quot;_blank&quot; title=&quot;REST in Practice: Hypermedia and Systems Architecture (Jim Webber, Savas Parastatidis, and Ian Robinson)&quot;&gt;REST in Practise&lt;/a&gt;&amp;#0160;book.&lt;/p&gt;


&lt;p&gt;On the first page,&amp;#0160;&lt;em&gt;Advance Praise for REST in Practice &lt;/em&gt;I read this:&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8352/8398554956_7b7c171993_o.png&quot; alt=&quot;Excerpt from the first page of REST in Practise (Advance Praise for REST in Practise)&quot; /&gt;&lt;/p&gt;




&lt;p&gt;Here is the description from the&amp;#0160;&lt;a href=&quot;http://www.caelumobjects.com/opensource/&quot; target=&quot;_blank&quot;&gt;Caelum Objects&lt;/a&gt;&amp;#0160;website:&lt;/p&gt;


&lt;blockquote&gt;&lt;p&gt;A restful framework based on the four constraints defined by Roy Fielding. It uses &lt;a href=&quot;http://en.wikipedia.org/wiki/HATEOAS&quot; target=&quot;_blank&quot; title=&quot;HATEOAS, an acronym for Hypermedia as the Engine of Application State, is a constraint of the REST application architecture that distinguishes it from most other network application architectures.&quot;&gt;HATEOAS&lt;/a&gt; within its core in order to be able to create loosely coupled distributed systems.&lt;/p&gt;&lt;/blockquote&gt;


&lt;p&gt;I am looking forward trying &lt;a href=&quot;http://restfulie.caelum.com.br/&quot; target=&quot;_blank&quot; title=&quot;Restfulie - Restful made easy&quot;&gt;Restfulie&lt;/a&gt;!&lt;em&gt;&amp;#0160;&lt;/em&gt;For those interested, I found the .NET version of the server&amp;#0160;&lt;a href=&quot;https://github.com/mauricioaniche/restfulie.net&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;&amp;#0160;and the client implementation &lt;a href=&quot;https://github.com/caelum/restfulie-net&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;



</description>
			<pubDate>Sat, 04 Jun 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Enterprise Library IContainerConfigurator implementation for Windsor</title>
			<link>http://nikosbaxevanis.com/2011/05/15/enterprise-library-icontainerconfigurator-implementation-for-windsor</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/05/15/enterprise-library-icontainerconfigurator-implementation-for-windsor</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;blockquote&gt;
&lt;p&gt;Alternative title: &quot;&lt;a title=&quot;Error Management Is Sometimes Exceptionally Difficult&quot; href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2011/05/error-management-is-sometimes-exceptionally-difficult.html&quot; target=&quot;_blank&quot;&gt;Error Management Is Sometimes Exceptionally Difficult&lt;/a&gt;, Part 2&quot;&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;I &lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2011/05/error-management-is-sometimes-exceptionally-difficult.html&quot; target=&quot;_blank&quot;&gt;previously&lt;/a&gt;&amp;nbsp;tried to write an implementation of the &lt;a title=&quot;Implement this interface to create an object that can read a set of TypeRegistration objects representing the current Enterprise Library configuration and configure a dependency injection container with that information.&quot; href=&quot;http://msdn.microsoft.com/en-us/library/microsoft.practices.enterpriselibrary.common.configuration.containermodel.icontainerconfigurator(v=pandp.50).aspx&quot; target=&quot;_blank&quot;&gt;IContainerConfigurator&lt;/a&gt; interface. The most tricky part was extracting the container registration entry for constructing a specific type. The entry is provided in the &lt;a title=&quot;Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel TypeRegistration(Of T) Class&quot; href=&quot;http://msdn.microsoft.com/en-us/library/ff669651(v=pandp.50).aspx&quot; target=&quot;_blank&quot;&gt;TypeRegistration&lt;/a&gt; class as a LambdaExpression and additional metadata.&lt;/p&gt;


&lt;p&gt;The fact that &lt;a title=&quot;Entry point for the container infrastructure for Enterprise Library.&quot; href=&quot;http://msdn.microsoft.com/en-us/library/microsoft.practices.enterpriselibrary.common.configuration.enterpriselibrarycontainer(v=pandp.50).aspx&quot; target=&quot;_blank&quot;&gt;EnterpriseLibraryContainer&lt;/a&gt;&amp;nbsp;class is completely decoupled from a specific container implementation made me keep trying to figure out a way to get the entries from the LamdaExpressions.&lt;/p&gt;


&lt;p&gt;I posted two questions on StackOverflow, and I got all the necessary info:&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;http://blogs.msdn.com/b/agile/archive/2009/06/25/enterprise-library-5-0-architectural-refactoring-complete.aspx&quot;&gt;Architectural Refactoring overview&lt;/a&gt;&amp;nbsp;(from &lt;a title=&quot;Exception Handling Block - Manually registering the ExceptionManager class&quot; href=&quot;http://stackoverflow.com/questions/5968725/exception-handling-block-manually-registering-the-exceptionmanager-class&quot; target=&quot;_blank&quot;&gt;this&lt;/a&gt;&amp;nbsp;question).&lt;/li&gt;
&lt;li&gt;Use of the&amp;nbsp;ParameterValue subclasses combined with the Visitor pattern over ParameterValues to make the code cleaner (from &lt;a href=&quot;http://stackoverflow.com/questions/5955813/enterprise-library-get-value-from-parametervalue-expression&quot; title=&quot;Enterprise Library - Get value from ParameterValue Expression&quot; target=&quot;_blank&quot;&gt;this&lt;/a&gt;&amp;nbsp;question).&lt;/li&gt;
&lt;/ul&gt;


&lt;blockquote&gt;
&lt;p&gt;The support I had from the project team members &amp;nbsp;was accurate and detailed. That was great.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;The &lt;a title=&quot;WindsorContainerConfigurator.cs&quot; href=&quot;http://entlibcontrib.codeplex.com/SourceControl/changeset/63545&quot; target=&quot;_blank&quot;&gt;current&lt;/a&gt; implementation relies heavily on Windsor's Property classes and it is based on the UnityContainerConfigurator.&lt;/p&gt;


&lt;p&gt;Below is the WindsorParameterVisitor,&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;private sealed class WindsorParameterVisitor : ParameterValueVisitor
{
    public Property[] InjectionParameters { get; private set; }

    protected override void VisitConstantParameterValue(
         ConstantParameterValue parameterValue)
    {
        string key = ((MemberExpression)parameterValue.Expression).Member.Name;
        InjectionParameters = new Property[] 
        {
             Property.ForKey(key).Eq(parameterValue.Value) 
        };
    }

    protected override void VisitResolvedParameterValue(
         ContainerResolvedParameter parameterValue)
    {
        InjectionParameters = new Property[] 
        {
             Property.ForKey(parameterValue.Type).Is(parameterValue.Name) 
        };
    }

    protected override void VisitEnumerableParameterValue(
         ContainerResolvedEnumerableParameter parameterValue)
    {
        InjectionParameters = parameterValue.Names
           .Select(name =&amp;gt; Property.ForKey(parameterValue.ElementType).Is(name))
           .ToArray();
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;The ParameterValueVisitor class is needed because most TypeRegistrations are quite complex coming with both ConstructorParameters and InjectedProperties and all this stuff must be routed on the .DependsOn() method of Windsor (actually Castle.MicroKernel).&lt;/p&gt;


&lt;p&gt;Below is some basic setup for configuring the Enterprise Library to use Windsor,&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;var container = new WindsorContainer();

// Add a SubResolver for components with IEnumerable&amp;lt;T&amp;gt; dependencies on .ctors.
container.Kernel.Resolver.AddSubResolver(
     new CollectionResolver(container.Kernel));

// This is the Windsor specific impl. of IContainerConfigurator interface.
var configurator = new WindsorContainerConfigurator(container);

// Configure the Enterprise Library Container to use Windsor internally.
EnterpriseLibraryContainer.ConfigureContainer(configurator, 
    ConfigurationSourceFactory.Create());

// Set Current property to a new instance of the WindsorServiceLocator adapter.
EnterpriseLibraryContainer.Current = new WindsorServiceLocator(container);&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;The source can be found &lt;a href=&quot;http://entlibcontrib.codeplex.com/SourceControl/changeset/63545&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;This is tested with Exception Handling application block and I was able to resolve the ExceptionManager class.&lt;/p&gt;



</description>
			<pubDate>Sun, 15 May 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Updates on Blog's Source Code Location</title>
			<link>http://nikosbaxevanis.com/2011/05/14/updates-on-blog-s-source-code-location</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/05/14/updates-on-blog-s-source-code-location</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Today I moved all the code samples to a single project named BonusBits.CodeSamples which can be found &lt;a href=&quot;https://github.com/moodmosaic/BonusBits.CodeSamples&quot; target=&quot;_blank&quot; title=&quot;BonusBits Blog source-code.&quot;&gt;here&lt;/a&gt;. &amp;#0160;I updated (almost) all the articles and blog posts to reference the new location.&lt;/p&gt;


&lt;p&gt;I think it&amp;#39;s easier to have everything under a single solution and get updates for everything with a single git-pull cmd ;)&lt;/p&gt;



</description>
			<pubDate>Sat, 14 May 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Error Management Is Sometimes Exceptionally Difficult</title>
			<link>http://nikosbaxevanis.com/2011/05/11/error-management-is-sometimes-exceptionally-difficult</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/05/11/error-management-is-sometimes-exceptionally-difficult</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;&lt;strong&gt;Update:&amp;nbsp;&lt;/strong&gt;&amp;nbsp;Please also read &lt;a title=&quot;Enterprise Library IContainerConfigurator implementation for Windsor&quot; href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2011/05/enterpriselibrary-and-windsorcontainerconfigurator.html&quot; target=&quot;_blank&quot;&gt;Part 2&lt;/a&gt;. The source &lt;del&gt;is on github&lt;/del&gt; has been &lt;a href=&quot;http://entlibcontrib.codeplex.com/SourceControl/changeset/63545&quot;&gt;merged&lt;/a&gt; in Enterprise Library Contrib.&lt;/p&gt;


&lt;p&gt;I tend to simplify exception handling at layer boundaries, when&amp;nbsp;designing a distributed application. Most of the time if an exception is propagated there I try to apply some kind of policy in order to log the exception and then re-throw&amp;nbsp;&amp;nbsp;a different exception.&lt;/p&gt;


&lt;p&gt;When I started using the&lt;span&gt;&amp;nbsp;Exception Handling Application Block from Enterprise Library I found out that I had to also deploy the Unity assemblies. &lt;/span&gt;&lt;/p&gt;


&lt;p&gt;&lt;span&gt;The call below resolves the registered component for the ExceptionManager class:&lt;/span&gt;&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;EnterpriseLibraryContainer.Current.GetInstance&amp;lt;ExceptionManager&amp;gt;();&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;The IServiceLocator.Current property of EnterpriseLibraryContainer class sets by default the Unity container (via UnityServiceLocator adapter class).&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8508/8398554996_e06fa74d80_b.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;


&lt;p&gt;In fact, if I remove the Unity assemblies a FileNotFoundException is thrown, indicating that&amp;nbsp;Microsoft.Practices.Unity assembly or one of its dependencies could not be found.&lt;/p&gt;


&lt;p&gt;Since I use Windsor in that application I didn't like the fact that I had to deploy it with two different IoC containers (!) so I started figuring out how I can call tell the EnterpriseLibraryContainer to resolve the ExceptionManager component using Windsor.&lt;/p&gt;


&lt;p&gt;The first thing I did was to compile the&amp;nbsp;&lt;a title=&quot;Castle Windsor Adapter - CommonServiceLocator&quot; href=&quot;http://commonservicelocator.codeplex.com/wikipage?title=Castle%20Windsor%20Adapter&amp;amp;referringTitle=Home&quot; target=&quot;_blank&quot;&gt;Windsor adapter&lt;/a&gt; of the CommonServiceLocator against the current version of Windsor that I use (and also run the unit-tests and see if they pass).&lt;/p&gt;


&lt;p&gt;Next, I set the IServiceLocator.Current property of the EnterpriseLibraryContainer class:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;EntLibraryContainer.Current = new WindsorServiceLocator(container);&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;The last thing I did was to call the ConfigureContainer method on the EnterpriseLibraryContainer class. This method takes an&amp;nbsp;IContainerConfigurator and an IConfigurationSource as parameters.&lt;/p&gt;


&lt;p&gt;Great, so I had to provide a class implementing the IContainerConfigurator interface for the Windsor container.&lt;/p&gt;


&lt;p&gt;The IContainerConfigurator interface contains a single method:&amp;nbsp;&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;void RegisterAll(
     IConfigurationSource configurationSource,        
     ITypeRegistrationsProvider rootProvider
     );&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Below is the (currently incomplete) implementation:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel;

internal sealed class WindsorContainerConfigurator
    : IContainerConfigurator
{
    private readonly IWindsorContainer container;

    public WindsorContainerConfigurator(IWindsorContainer container)
    {
        this.container = container;
    }

    public void RegisterAll(
        IConfigurationSource configurationSource,
        ITypeRegistrationsProvider rootProvider)
    {
        foreach (TypeRegistration registration 
            in rootProvider.GetRegistrations(configurationSource))
        {
            Register(registration);
        }
    }

    private void Register(TypeRegistration registration)
    {
        Type implementation = registration.ImplementationType;

        if (!this.container.Kernel.HasComponent(implementation))
        {
            var componentRegistration =
                Component.For(registration.ServiceType)
                            .ImplementedBy(implementation);

            if (registration.ConstructorParameters.Any())
            {
                var dependencies = GetRegistrationDependencies(
                    componentRegistration, 
                    registration.ConstructorParameters);

                componentRegistration = 
                    componentRegistration.DependsOn(dependencies);
            }

            this.container.Register(AddLifeStyleToRegistration(
                componentRegistration, registration.Lifetime));
        }
    }

    private IDictionary GetRegistrationDependencies&amp;lt;TInterface&amp;gt;(
        ComponentRegistration&amp;lt;TInterface&amp;gt; registration,
        IEnumerable&amp;lt;ParameterValue&amp;gt; constructorParameters)
    {
        var dependencies = new Hashtable();

        foreach (ParameterValue pv in constructorParameters)
        {
            MemberExpression exp = pv.Expression
                as MemberExpression;

            if (exp != null)
            {
                string key = exp.Member.Name;
                object val = GetValue(exp);

                dependencies.Add(key, val);
            }
            else
            {
                // TODO: pv.Expression is a MethodCallExpression.
            }
        }

        return dependencies;
    }

    private static ComponentRegistration&amp;lt;TInterface&amp;gt; AddLifeStyleToRegistration&amp;lt;TInterface&amp;gt;(
        ComponentRegistration&amp;lt;TInterface&amp;gt; registration, 
        TypeRegistrationLifetime typeRegistrationLifetime)
    {
        if (typeRegistrationLifetime == 
            TypeRegistrationLifetime.Singleton)
        {
            registration = registration.LifeStyle.Singleton;
        }
        else if (typeRegistrationLifetime == 
            TypeRegistrationLifetime.Transient)
        {
            registration = registration.LifeStyle.Transient;
        }
        else
        {
            throw new ArgumentOutOfRangeException(
                &amp;quot;typeRegistrationLifetime&amp;quot;, 
                &amp;quot;Only Transient and Singleton are supported.&amp;quot;);
        }

        return registration;
    }

    private static object GetValue(Expression member)
    {
        var objectMember = Expression.Convert(member, typeof(object));
        var getterLambda = Expression.Lambda&amp;lt;Func&amp;lt;object&amp;gt;&amp;gt;(objectMember);

        return getterLambda.Compile().Invoke();
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;I really don't know what to do in the case of a MethodCallExpression as you can see inside the &lt;em&gt;else&lt;/em&gt; block. However, after I can finish with the code inside that block I will be able to do this:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;var container = new WindsorContainer();

// Add a SubResolver for components with IEnumerable&amp;lt;T&amp;gt; dependencies on .ctors.
container.Kernel.Resolver.AddSubResolver(
     new CollectionResolver(container.Kernel));

// This is the Windsor specific impl. of IContainerConfigurator interface.
var configurator = new WindsorContainerConfigurator(container);

// Configure the Enterprise Library Container to use Windsor internally.
EnterpriseLibraryContainer.ConfigureContainer(configurator, 
    ConfigurationSourceFactory.Create());

// Set Current property to a new instance of the WindsorServiceLocator adapter.
EnterpriseLibraryContainer.Current = new WindsorServiceLocator(container);&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;I will try to update the code as soon as I have done any changes.&lt;/p&gt;



</description>
			<pubDate>Wed, 11 May 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>NHibernate SessionPerRequest with WcfOperationSessionContext (Part 2)</title>
			<link>http://nikosbaxevanis.com/2011/04/15/nhibernate-session-per-request-with-wcfoperationsessioncontext-part-2</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/04/15/nhibernate-session-per-request-with-wcfoperationsessioncontext-part-2</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;In the &lt;a title=&quot;NHibernate Session Per Request with WcfOperationSessionContext.&quot; href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2011/03/nhibernate-session-per-request-with-wcfoperationsessioncontext.html&quot; target=&quot;_blank&quot;&gt;previous&lt;/a&gt; post I gave a brief description on how&amp;nbsp;WcfOperationSessionContext can be configured to work.&amp;nbsp;In this post I am going through all the basic steps required to set up a &lt;em&gt;test project&lt;/em&gt; that uses WCF for out of process communication and NHibernate for persistence.&lt;/p&gt;


&lt;h2&gt;Hosting the WCF Service in a Managed Application&lt;/h2&gt;


&lt;p&gt;To host the service inside a managed application, define an endpoint for the service either imperatively in code, declaratively through configuration, or using default endpoints, and then create an instance of ServiceHost.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;internal sealed class Program
{
    public static void Main()
    {
        var svh = new ServiceHost(
            typeof(WcfOperationSessionContextTestService));
        svh.AddServiceEndpoint(typeof(ICurrentSessionContextTestService),
            new NetTcpBinding(), &amp;quot;net.tcp://localhost:56789&amp;quot;);

        Bootstrapper.Initialize();
        svh.Open();

        Console.WriteLine(&amp;quot;Server ready. Press any key to exit..&amp;quot;);
        Console.ReadKey(false);
        svh.Close();
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Before putting the service to start receiving messages, initialize NHibernate by calling Boostrapper's Initialize method. This creates the ISessionFactory instance that will be used through the entire application. Then call Open on ServiceHost. This creates and opens the listener for the service.&lt;/p&gt;


&lt;h2&gt;Building the default SessionFactory&lt;/h2&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;internal static class Bootstrapper
{
    public static void Initialize()
    {
        if (SessionFactoryHolder.DefaultSessionFactory != null)
        {
            return;
        }

        var cfg = new Configuration();
        cfg.CurrentSessionContext&amp;lt;WcfOperationSessionContext&amp;gt;()
           .DataBaseIntegration(ForSQLiteInMemory)
           .Proxy(p =&amp;gt; p.ProxyFactoryFactory&amp;lt;ProxyFactoryFactory&amp;gt;())
           .SessionFactory()
               .GenerateStatistics();

        SessionFactoryHolder.DefaultSessionFactory = cfg.BuildSessionFactory();
    }

    private static void ForSQLiteInMemory(
        IDbIntegrationConfigurationProperties db)
    {
        db.ConnectionString = &amp;quot;data source=:memory:&amp;quot;;
        db.ConnectionReleaseMode = ConnectionReleaseMode.OnClose;
        db.Dialect&amp;lt;SQLiteDialect&amp;gt;();
        db.ConnectionProvider&amp;lt;DriverConnectionProvider&amp;gt;();
        db.Driver&amp;lt;SQLite20Driver&amp;gt;();
        db.BatchSize = 100;
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;The above steps to build the SessionFactory are straightforward. The new&amp;nbsp;Loquacious extension methods are used for the configuration.&lt;/p&gt;


&lt;h2&gt;Creating a WCF Service for testing the&amp;nbsp;WcfOperationSessionContext&lt;/h2&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[NHibernateWcfContext]
[ServiceBehavior(
    InstanceContextMode = InstanceContextMode.PerSession)]
internal sealed class WcfOperationSessionContextTestService
    : ICurrentSessionContextTestService
{
    private static readonly ISessionFactory sessionFactory
        = SessionFactoryHolder.DefaultSessionFactory;

    public void RunTests()
    {
        // Show the current session Id for each request.
        Console.WriteLine(&amp;quot;SessionId={0}&amp;quot;, 
            sessionFactory.GetCurrentSession()
                .GetSessionImplementation().SessionId);

        // Calling GetCurrentSession 2 times returns the SAME instance.
        Debug.Assert(object.ReferenceEquals(
            sessionFactory.GetCurrentSession(), 
            sessionFactory.GetCurrentSession()) == true);
        Console.WriteLine(&amp;quot;Passed..&amp;quot;);

        // Since session is NOT thread-safe GetCurrentSession does
        // not work from other thread than the one it was created.
        var done = new ManualResetEventSlim(false);
        ThreadPool.QueueUserWorkItem((state) =&amp;gt; {
            try
            {
                ((ISessionFactory)state).GetCurrentSession();
            }
            catch (NullReferenceException)
            { 
                Console.WriteLine(&amp;quot;Passed..&amp;quot;);
            }
            done.Set();
        }, sessionFactory);
        done.Wait();
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;blockquote&gt;
&lt;p&gt;You may find more information about the&amp;nbsp;NHibernateWcfContext attribute in&amp;nbsp;the&amp;nbsp;&lt;a title=&quot;NHibernate Session Per Request with WcfOperationSessionContext.&quot; href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2011/03/nhibernate-session-per-request-with-wcfoperationsessioncontext.html&quot; target=&quot;_blank&quot;&gt;previous&lt;/a&gt;&amp;nbsp;post.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;The above tests shows the current session Id for each request. This is useful when debugging in order to ensure that each session is different for each separate call.&lt;/p&gt;


&lt;p&gt;Then it checks that calling ISessionFactory's GetCurrentSession method many times it will returns the same instance.&lt;/p&gt;


&lt;p&gt;Since the session is not thread-safe ISessionFactory's GetCurrentSession will throw when called from a thread pool thread. (On a thread pool thread one may call ISessionFactory's OpenSession method and work with the session).&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8475/8397465779_4d8f2fa782_o.png&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;

&lt;h2&gt;WCF Client Configuration&lt;/h2&gt;

&lt;p&gt;Here is how the client connects to the service in order to run the test method.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;internal sealed class Program
{
    private static void Main()
    {
        Console.WriteLine(&amp;quot;Press any key when server is ready..&amp;quot;);
        Console.ReadKey(false);

        var proxy = new ChannelFactory&amp;lt;ICurrentSessionContextTestSer&amp;gt;(
            new NetTcpBinding(), &amp;quot;net.tcp://localhost:56789&amp;quot;);
        ICurrentSessionContextTestService svc = proxy.CreateChannel();

        // Start our loop.
        char operation = (char)0;
        while (operation != 'Q')
        {
            Console.WriteLine(&amp;quot;R=Run Tests, Q=Quit?&amp;quot;);
            operation = char.ToUpper(Console.ReadKey(true).KeyChar);
            if (operation == 'R') { svc.RunTests(); }
        } 

        proxy.Close();
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;The code can be found &lt;a title=&quot;BonusBits Blog source-code.&quot; href=&quot;https://github.com/moodmosaic/BonusBits.CodeSamples&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;



</description>
			<pubDate>Fri, 15 Apr 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>NHibernate SessionPerRequest with WcfOperationSessionContext</title>
			<link>http://nikosbaxevanis.com/2011/03/30/nhibernate-session-per-request-with-wcfoperationsessioncontext</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/03/30/nhibernate-session-per-request-with-wcfoperationsessioncontext</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;&lt;strong&gt;Update:&amp;#0160;&lt;/strong&gt;You may download a &lt;a href=&quot;https://github.com/moodmosaic/BonusBits.CodeSamples/tree/master/BonusBits.CodeSamples.NHibernate&quot; target=&quot;_blank&quot; title=&quot;WcfOperationSessionContext (Sample Application with Tests)&quot;&gt;working example&lt;/a&gt; using NHibernate, WCF and SQLite in-memory. The example is described also &lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2011/04/nhibernate-session-per-request-with-wcfoperationsessioncontext-part2.html&quot; target=&quot;_blank&quot; title=&quot;NHibernate Session Per Request with WcfOperationSessionContext (Part 2).&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;NHibernate 3 comes with out of the box support for the scenario where we want to have a single Session for the lifetime of a WCF request.&lt;/p&gt;


&lt;p&gt;Using the &lt;a href=&quot;http://jameskovacs.com/2011/01/21/loquacious-configuration-in-nhibernate-3/&quot; target=&quot;_blank&quot; title=&quot;Loquacious Configuration in NHibernate 3.&quot;&gt;Loquacious&lt;/a&gt;&amp;#0160;configuration we can easily set the WcfOperationSessionContext to be the default&amp;#0160;current session context.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;var cfg = NHibernate.Cfg.Configuration();
cfg.DataBaseIntegration(ForMySQL5)
   .CurrentSessionContext&amp;lt;WcfOperationSessionContext&amp;gt;()
   .Proxy(p =&amp;gt; p.ProxyFactoryFactory&amp;lt;ProxyFactoryFactory&amp;gt;())
   .SessionFactory()
        .GenerateStatistics();&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;We also need to inspect inbound and outbound application messages prior to dispatching a request message to an operation (for binding the Session) and before returning a reply (for unbinding the Session).&lt;/p&gt;


&lt;p&gt;Here is a specific&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.idispatchmessageinspector.aspx&quot; target=&quot;_blank&quot; title=&quot;Defines the methods that enable custom inspection or modification of inbound and outbound application messages in service applications.&quot;&gt;IDispatchMessageInspector&lt;/a&gt; implementation for that:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public sealed class NHibernateWcfContextInitializer
      : IDispatchMessageInspector
  {
      private static readonly ISessionFactory sessionFactory
          = Container.Resolve&amp;lt;ISessionFactory&amp;gt;();

      public object AfterReceiveRequest(
          ref Message request,
          IClientChannel channel,
          InstanceContext instanceContext)
      {
          CurrentSessionContext.Bind(
              sessionFactory.OpenSession());
          return null;
      }

      public void BeforeSendReply(
          ref Message reply,
          object correlationState)
      {
          var session = CurrentSessionContext.Unbind(
               sessionFactory);

          session.Dispose();
      }
  }&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Next, we need to define a custom Service Behavior that applies to every single endpoint of a service. To do that we need to define a class that implements the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iservicebehavior.aspx&quot; target=&quot;_blank&quot; title=&quot;Provides a mechanism to modify or insert custom extensions across an entire service, including the ServiceHostBase.&quot;&gt;IServiceBehavior&lt;/a&gt; interface.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[AttributeUsage(AttributeTargets.Class)]
public sealed class NHibernateWcfContextAttribute
    : Attribute, IServiceBehavior
{
    public void AddBindingParameters(
        ServiceDescription serviceDescription, 
        ServiceHostBase serviceHostBase, 
        Collection&amp;lt;ServiceEndpoint&amp;gt; endpoints, 
        BindingParameterCollection bindingParameters) { }

    public void ApplyDispatchBehavior(
        ServiceDescription serviceDescription, 
        ServiceHostBase serviceHostBase)
    {
        foreach (ChannelDispatcher channelDispatcher 
            in serviceHostBase.ChannelDispatchers)
        {
            foreach (var endpoint in channelDispatcher.Endpoints)
            {
                endpoint.DispatchRuntime.MessageInspectors.Add(
                    new NHibernateWcfContextInitializer());
            }
        }
    }

    public void Validate(
        ServiceDescription serviceDescription, 
        ServiceHostBase serviceHostBase) { }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;We can now decorate any WCF service implementation with [NHibernateWcfContext] attribute and we can access the Session using the ISessionFactory&amp;#39;s GetCurrentSession method.&lt;/p&gt;


&lt;blockquote&gt;&lt;p&gt;When using the&amp;#0160;&lt;a href=&quot;http://code.google.com/p/agatha-rrsl/&quot; target=&quot;_blank&quot; title=&quot;Implementation of the Request/Response Service Layer for .NET&quot;&gt;agatha-rrsl&lt;/a&gt;&amp;#0160;project instead of providing a WcfRequestProcessor define a custom RequestProcessor (deriving from the&amp;#0160;WcfRequestProcessor) and decorating it with the [NHibernateWcfContext] attribute.&lt;/p&gt;&lt;/blockquote&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[NHibernateWcfContext]
public sealed class NHibernateWcfRequestProcessor
    : Agatha.ServiceLayer.WCF.WcfRequestProcessor { }&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;I would generally recommend to try all of the NHibernate&amp;#39;s CurrentSessionContext-derived class in order to use the one that suits better for the given context. In some projects I use the WcfOperationSessionContext for the service layer and the ThreadLocalSessionContext when running&amp;#0160;Job Schedulers.&lt;/p&gt;



</description>
			<pubDate>Wed, 30 Mar 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Data-driven NHibernate with .NET 4.0 and the DynamicEntity Class</title>
			<link>http://nikosbaxevanis.com/2011/03/28/data-driven-nhibernate-with-net-4-0-and-the-dynamicentity-class</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/03/28/data-driven-nhibernate-with-net-4-0-and-the-dynamicentity-class</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;The idea for this post came by a very good friend who wanted to modify his data access layer (DAL) in order to use NHibernate.&lt;/p&gt;


&lt;p&gt;The DAL contains a base class that generates SQL queries and the application were it&amp;#39;s used is completely data-driven. There is no domain, no classes, and the behaviour&amp;#0160;is bound in various event handler methods. Changes to the database (columns, row data, etc) dictate how the application behaves.&lt;/p&gt;


&lt;p&gt;The problem that comes when trying to port this kind of DAL to use NHibernate is that we have to create POCOs in order to persist everything to the database. Since the application is data-driven we would end up using an &lt;a href=&quot;http://www.martinfowler.com/bliki/AnemicDomainModel.html&quot; target=&quot;_blank&quot; title=&quot;The Anemic Domain Model is a term used to describe the use of a software domain model where the business logic is implemented outside the domain objects.&quot;&gt;anemic&lt;/a&gt; domain model holding just the data to persist to the database and no behaviour&amp;#0160;at all.&lt;/p&gt;


&lt;p&gt;The solution for the problem is to use&amp;#0160;dictionaries as entities, a&amp;#0160;little-known feature of NHibernate which&amp;#0160;allows us to define our entities as dictionaries instead of statically typed&amp;#0160;objects.&lt;/p&gt;


&lt;p&gt;Here is how to define a mapping, (notice the&amp;#0160;entity-name instead of a class name):&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8506/8397466511_abfc4b24be_o.png&quot; alt=&quot;The entity-name in mapping&quot; /&gt;&lt;/p&gt;


&lt;p&gt;The only thing we have is the mapping, no classes. In order to create a Currency object we create the following dictionary:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;var currency = new Dictionary&amp;lt;string, object&amp;gt;()
{
    { &amp;quot;ISOCode&amp;quot;,&amp;quot;GBP&amp;quot; },
    { &amp;quot;EnglishName&amp;quot;,&amp;quot;United Kingdom Pound&amp;quot; },
    { &amp;quot;ExchangeRateEURtoCurrency&amp;quot;,0.87780 },
    { &amp;quot;ExchangeRateUpdatedOn&amp;quot;,DateTime.UtcNow },
    { &amp;quot;IsEnabled&amp;quot;,true },
    { &amp;quot;Symbol&amp;quot;,null }
};&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;As you can see, the above code is cumbersome. But we can do something about it.&lt;/p&gt;


&lt;p&gt;Taking advantage of the .NET 4.0 and the&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.dynamic.dynamicobject.aspx&quot; target=&quot;_blank&quot; title=&quot;Provides a base class for specifying dynamic behavior at run time. This class must be inherited from; you cannot instantiate it directly.&quot;&gt;DynamicObject&lt;/a&gt;&amp;#0160;Class, we can create a type deriving from the DynamicObject Class and&amp;#0160;specify dynamic behaviour&amp;#0160;at run time.&amp;#0160;&lt;/p&gt;


&lt;p&gt;Let&amp;#39;s name our class, DynamicEntity. It must be able to:&lt;/p&gt;


&lt;ol&gt;
&lt;li&gt;Accept a string in the .ctor specifying the entity name.&lt;/li&gt;
&lt;li&gt;Set properties (PropertyName = key, PropertyValue = value) on the internal dictionary.&lt;/li&gt;
&lt;li&gt;Get properties (similar to above)&amp;#0160;from the internal dictionary.&lt;/li&gt;
&lt;li&gt;Being able to expose the internal dictionary as property for NHibernate usage.&lt;/li&gt;
&lt;li&gt;Being able to expose it&amp;#39;s name as property for NHibernate usage.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;Here is the DynamicEntity class:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;using System;
using System.Collections.Generic;
using System.Dynamic;

public sealed class DynamicEntity : DynamicObject
{
    private readonly IDictionary&amp;lt;string, object&amp;gt; dictionary
        = new Dictionary&amp;lt;string, object&amp;gt;();

    private readonly string entityName;

    public DynamicEntity(string entityName)
    {
        this.entityName = entityName;
    }

    public string Name
    {
        get
        {
            return this.entityName;
        }
    }

    public IDictionary&amp;lt;string, object&amp;gt; Map
    {
        get
        {
            return this.dictionary;
        }
    }

    public override bool TryGetMember(
        GetMemberBinder binder, out object result)
    {
        if (!this.dictionary.TryGetValue(binder.Name, out result))
        {
            return false;
        }

        return true;
    }

    public override bool TrySetMember(
        SetMemberBinder binder, object value)
    {
        string key = binder.Name;

        if (this.dictionary.ContainsKey(key))
        {
            this.dictionary.Remove(key);
        }

        this.dictionary.Add(key, value);

        return true;
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Finally, here is an integration test in action:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Fact]
public void NHibernateShouldBeAbleToPersistCurrency()
{
    dynamic currency = new DynamicEntity(&amp;quot;Currency&amp;quot;);

    currency.ISOCode                   = &amp;quot;GBP&amp;quot;;
    currency.EnglishName               = &amp;quot;United Kingdom Pound&amp;quot;;
    currency.ExchangeRateEURtoCurrency = 0.87780;
    currency.ExchangeRateUpdatedOn     = DateTime.UtcNow;
    currency.IsEnabled                 = true;
    currency.Symbol                    = null;

    object id;

    using (var tx = Session.BeginTransaction())
    {
        id = Session.Save(currency.Name, currency.Map);
        tx.Commit();

        Assert.NotNull(id);
    }

    Session.Clear();

    using (var tx = Session.BeginTransaction())
    {
        var loadedCurrency = Session.Load(currency.Name, id);
        tx.Commit();

        Assert.NotNull(loadedCurrency);
    }

    Session.Flush();
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;blockquote&gt;
&lt;p&gt;In the above test, for Session I use the ISession.GetSession(EntityMode.Map).&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;Download the sample code &lt;a href=&quot;https://github.com/downloads/moodmosaic/BonusBits.CodeSamples/DynamicEntity_Complete.zip&quot; target=&quot;_self&quot;&gt;here&lt;/a&gt;. Updated versions will be available &lt;a href=&quot;https://github.com/moodmosaic/BonusBits.CodeSamples/tree/master/BonusBits.CodeSamples.NHibernate&quot; target=&quot;_blank&quot; title=&quot;BonusBits Blog source-code for NHibernate.&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;



</description>
			<pubDate>Mon, 28 Mar 2011 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Unit Testing Events (The SpinWait.SpinUntil Method)</title>
			<link>http://nikosbaxevanis.com/2011/03/13/unit-testing-events-the-spinwait-spinuntil-method</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/03/13/unit-testing-events-the-spinwait-spinuntil-method</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;The&amp;nbsp;&lt;a title=&quot;Spins until the specified condition is satisfied.&quot; href=&quot;http://msdn.microsoft.com/en-us/library/system.threading.spinwait.spinuntil.aspx&quot; target=&quot;_blank&quot;&gt;SpinWait.SpinUntil&lt;/a&gt;&amp;nbsp;method spins until a specified condition is satisfied.&amp;nbsp;This&amp;nbsp;greatly improves the unit testing of events.&lt;/p&gt;


&lt;p&gt;Let's see first, how we test an event using hybrid thread synchronization constructs:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Fact]
public void FooEvent()
{
    bool raised = false;
    ManualResetEventSlim done = new ManualResetEventSlim(false);
    ThreadPool.QueueUserWorkItem(delegate
    {
        Foo += new EventHandler&amp;lt;FooEventArgs&amp;gt;(
            (sender, e) =&amp;gt; { raised = true; done.Set(); });
        RaiseFoo();
    }, null);
    done.Wait();
    Assert.True(raised);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Here is how the above test looks like when using&amp;nbsp;the SpinWait.SpinUntil&amp;nbsp;method:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Fact]
public void FooEvent()
{
    bool raised = false;
    ThreadPool.QueueUserWorkItem(delegate
    {
        Foo += new EventHandler&amp;lt;FooEventArgs&amp;gt;(
            (sender, e) =&amp;gt; { raised = true; });
        RaiseFoo();
    }, null);
    SpinWait.SpinUntil(() =&amp;gt; raised == true);
    Assert.True(raised);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;The above tests are exactly the same. The one with the SpinWait.SpinUntil method is easier to read and it also requires less code. Pretty cool.&lt;/p&gt;



</description>
			<pubDate>Sun, 13 Mar 2011 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Persistence specification testing combined with AutoFixture</title>
			<link>http://nikosbaxevanis.com/2011/03/13/persistence-specification-testing-combined-with-autofixture</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/03/13/persistence-specification-testing-combined-with-autofixture</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;When working with NHibernate you need to make sure that your mappings are correct. At least, you have to make sure that when you&amp;nbsp;save an item you can also qet that item back.&lt;/p&gt;


&lt;p&gt;If you are using FluentNHibernate you can use the &lt;a href=&quot;https://github.com/jagregory/fluent-nhibernate/tree/master/src/FluentNHibernate/Testing&quot; target=&quot;_blank&quot;&gt;PersistenceSpecification&amp;lt;T&amp;gt; class&lt;/a&gt;. However, the&amp;nbsp;PersistenceSpecification&amp;lt;T&amp;gt; class requires that you pass the property to check and also a value for that property.&lt;/p&gt;


&lt;p&gt;By using &lt;a title=&quot;AutoFixture makes it easier for developers to do Test-Driven Development by automating non-relevant Test Fixture Setup, allowing the Test Developer to focus on the essentials of each test case.&quot; href=&quot;http://autofixture.codeplex.com/&quot; target=&quot;_blank&quot;&gt;AutoFixture&lt;/a&gt; you can easily create objects that you can pass inside the CheckXx methods:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[Fact]
public void ShouldVerifyTheMappings()
{
    var fixture = new Fixture();

    using (session)
    {
        new PersistenceSpecification&amp;lt;EventType&amp;gt;(session)
            .CheckProperty(x =&amp;gt; x.EventTypeId, 
                fixture.CreateAnonymous&amp;lt;long&amp;gt;())
            .CheckProperty(x =&amp;gt; x.EventTypeName, 
                fixture.CreateAnonymous&amp;lt;string&amp;gt;())
            .CheckProperty(x =&amp;gt; x.ExchangeServerId, 
                fixture.CreateAnonymous&amp;lt;int&amp;gt;())
            .CheckProperty(x =&amp;gt; x.LastUpdatedOn, 
                DateTime.Today)
            .CheckProperty(x =&amp;gt; x.NextMarketId, 
                fixture.CreateAnonymous&amp;lt;long&amp;gt;())
            .CheckReference(x =&amp;gt; x.Bookmaker, 
                fixture.CreateAnonymous&amp;lt;Bookmaker&amp;gt;())
            .VerifyTheMappings();
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Combining&amp;nbsp;AutoFixture with the PersistenceSpecification&amp;lt;T&amp;gt; class results in&amp;nbsp;writing less code when testing NHibernate mappings, specially when dealing with complex types.&lt;/p&gt;



</description>
			<pubDate>Sun, 13 Mar 2011 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Creating Test Fixtures easily with AutoFixture</title>
			<link>http://nikosbaxevanis.com/2011/02/22/creating-test-fixtures-easily-with-autofixture</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/02/22/creating-test-fixtures-easily-with-autofixture</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;When doing TDD there are many times that we use an &lt;a href=&quot;http://martinfowler.com/bliki/ObjectMother.html&quot; target=&quot;_blank&quot; title=&quot;An object mother is a kind of class used in testing to help create example objects that you use for testing.&quot;&gt;ObjectMother&lt;/a&gt;&amp;#0160;class for test fixtures.&amp;#0160;In large domains, writing such classes can become tedious work. If we want random data things get even more complicated.&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://autofixture.codeplex.com/&quot; target=&quot;_blank&quot; title=&quot;AutoFixture makes it easier for developers to do Test-Driven Development by automating non-relevant Test Fixture Setup, allowing the Test Developer to focus on the essentials of each test case.&quot;&gt;AutoFixture&lt;/a&gt; is a library written by&amp;#0160;&lt;a href=&quot;http://blog.ploeh.dk/default.aspx&quot; target=&quot;_blank&quot; title=&quot;Mark Seemann&amp;#39;s .NET blog&quot;&gt;Mark Seemann&lt;/a&gt; and can&amp;#0160;automate test fixture creation thereby saving time and making tests cleaner, faster, flexible and customizable.&lt;/p&gt;


&lt;p&gt;Here is an example:&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8052/8397466545_578ec5d2b7_o.png&quot; alt=&quot;Unit Testing a class which contains an interface&quot; style=&quot;display: block;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;Here I setup Moq to return a sequence of&amp;#0160;&lt;span style=&quot;color: #2b91af; font-family: monospace; font-size: 13px;&quot;&gt;EventItem&amp;#0160;&lt;/span&gt;objects when I call the FindAll method. In the Setup method I pass a delegate where I use AutoFixture to create the sequence.&amp;#0160;What I&amp;#0160;&lt;span style=&quot;text-decoration: underline;&quot;&gt;really like&lt;/span&gt;&amp;#0160;here is that even though the&amp;#0160;&lt;span style=&quot;color: #2b91af; font-family: monospace; font-size: 13px;&quot;&gt;EventItem&lt;/span&gt;&amp;#0160;contains interfaces AutoFixture can successfully create the sequence.&lt;/p&gt;


&lt;p&gt;This is made possible by calling the Customize method and passing an instance of the&amp;#0160;&lt;span style=&quot;color: #2b91af; font-family: monospace; font-size: 13px;&quot;&gt;AutoMoqCustomization&amp;#0160;&lt;/span&gt;type. This way we instruct AutoFixture to become an &lt;a href=&quot;http://blog.ploeh.dk/2010/08/19/AutoFixtureAsAnAutomockingContainer.aspx&quot; target=&quot;_blank&quot; title=&quot;AutoFixture as an auto-mocking container.&quot;&gt;auto-mocking container&lt;/a&gt;&amp;#0160;and mock the interface types.&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8087/8397466531_9ab4150533_o.png&quot; alt=&quot;One of the class properties which is an interface&quot; /&gt;&lt;/p&gt;




&lt;p&gt;AutoFixture includes an assembly called Ploeh.AutoFixture.AutoMoq that uses Moq (which in turn Moq uses Castle DynamicProxy to&amp;#0160;generate proxies on the fly at runtime).&lt;/p&gt;


&lt;blockquote&gt;
&lt;p&gt;There is also&amp;#0160;Ploeh.AutoFixture.Xunit assembly for xUnit.net &lt;a href=&quot;http://blog.ploeh.dk/2010/10/08/AutoDataTheoriesWithAutoFixture.aspx&quot; target=&quot;_blank&quot; title=&quot;AutoData Theories with AutoFixture&quot;&gt;data theories&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;All this stuff is amazing, and I would like to mention that the source code is perfectly written, contains a lot of patterns and best practises (like the&amp;#0160;&lt;a href=&quot;http://www.natpryce.com/articles/000714.html&quot; target=&quot;_blank&quot; title=&quot;Test Data Builders: an alternative to the Object Mother pattern&quot;&gt;Test Data Builder&lt;/a&gt; pattern). I am very happy with it.&lt;/p&gt;



</description>
			<pubDate>Tue, 22 Feb 2011 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Parameterized Tests with xUnit.net</title>
			<link>http://nikosbaxevanis.com/2011/02/17/parameterized-tests-with-xunit-net</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/02/17/parameterized-tests-with-xunit-net</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Sometimes you have several unit-tests implementing the same test algorithm. These tests are exactly the same, having only different data.&lt;/p&gt;


&lt;p&gt;With &lt;a href=&quot;http://research.microsoft.com/en-us/projects/pex/&quot; target=&quot;_blank&quot; title=&quot;Pex enables a new development experience in Visual Studio Team System, taking test-driven development to the next level.&quot;&gt;Pex&lt;/a&gt;&amp;#0160;you can cover your code with&amp;#0160;parameterized tests (there is also a tutorial&amp;#0160;&lt;a href=&quot;http://www.springerlink.com/content/f270xp230131pr93/&quot; target=&quot;_blank&quot; title=&quot;Parameterized Unit Testing with Pex (Tutorial)&quot;&gt;here&lt;/a&gt;).&amp;#0160;However, you can also do it with&amp;#0160;&lt;a href=&quot;http://xunit.codeplex.com/&quot; target=&quot;_blank&quot; title=&quot;xUnit.net is a unit testing tool for the .NET Framework.&quot;&gt;xUnit.net&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Add a reference to xunit.extensions.dll and decorate any parameterized test methods with&amp;#0160;&lt;span style=&quot;font-family: monospace; font-size: 13px;&quot;&gt;[&lt;span style=&quot;color: #2b91af;&quot;&gt;Theory&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;]&amp;#0160;&lt;/span&gt;&lt;/span&gt;attribute (instead of&amp;#0160;&lt;span style=&quot;font-family: monospace; font-size: 13px;&quot;&gt;[&lt;span style=&quot;color: #2b91af;&quot;&gt;Fact&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;]&lt;/span&gt;&lt;/span&gt;). Then decorate it with&amp;#0160;&lt;span style=&quot;font-family: monospace; font-size: 13px;&quot;&gt;[&lt;span style=&quot;color: #2b91af;&quot;&gt;InlineData&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;]&lt;/span&gt;&lt;/span&gt;attribute if the data is coming from inlined values.&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8048/8397465711_5ba90cb909_o.png&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;


&lt;p&gt;There are also additional attributes (each one taking parameters so xUnit.net can successfully locate the test data):&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;PropertyDataAttribute&lt;/li&gt;
&lt;li&gt;ExcelDataAttribute&lt;/li&gt;
&lt;li&gt;SqlServerDataAttribute&lt;/li&gt;
&lt;li&gt;OleDbDataAttribute&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Choose the one that suits your needs.&lt;/p&gt;



</description>
			<pubDate>Thu, 17 Feb 2011 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Edit and Continue with TestDriven.Net</title>
			<link>http://nikosbaxevanis.com/2011/02/11/edit-and-continue-with-testdriven-net</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/02/11/edit-and-continue-with-testdriven-net</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;TestDriven.Net (2.0 RTM and greater) comes with a (hidden) test runner&amp;#0160;for &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/x17d7wxw.aspx&quot; target=&quot;_blank&quot; title=&quot;With Edit and Continue for C#, you can make changes to your code in break mode while debugging. The changes can be applied without having to stop and restart the debugging session. In run mode, the source editor is read-only.&quot;&gt;Edit and Continue&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;To enabled it, edit the&amp;#0160;&lt;em&gt;TestDriven.dll.config&lt;/em&gt;&amp;#0160;file and uncomment the lines with:&amp;#0160;&lt;em&gt;&amp;lt;button command=&amp;quot;DebuggerEaC&amp;quot; /&amp;gt;&lt;/em&gt;&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8466/8397466345_ee491826a5_o.png&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;


&lt;p&gt;Below are the places in the .config file where the command can be found, so you may choose which one of those you wish to uncomment:&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;Project and Solution Context Menus/Item&lt;/li&gt;
&lt;li&gt;Project and Solution Context Menus/Folder&lt;/li&gt;
&lt;li&gt;Project and Solution Context Menus/Project&lt;/li&gt;
&lt;li&gt;Project and Solution Context Menus/Cross Project Multi Project&lt;/li&gt;
&lt;li&gt;Project and Solution Context Menus/Reference Item&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;After you restart Visual Studio you will have an additional option in the context menu:&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8514/8397466333_c3c9374b84_o.png&quot; alt=&quot;Debugger (E&amp;amp;C) additional option is now available in the context menu&quot;/&gt;&lt;/p&gt;


&lt;p&gt;This test runner may &amp;#39;touch&amp;#39; project files when used with source control (this is why it&amp;#39;s disabled by default).&amp;#0160;You can also can read about it &lt;a href=&quot;http://www.testdriven.net/ReleaseNotes.html&quot; target=&quot;_blank&quot; title=&quot;705: Add (hidden) support for &amp;#39;Test With... E&amp;amp;C&amp;#39;&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;



</description>
			<pubDate>Fri, 11 Feb 2011 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Why I Love My MacBook Pro</title>
			<link>http://nikosbaxevanis.com/2011/01/21/why-i-love-my-macbook-pro</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/01/21/why-i-love-my-macbook-pro</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8045/8397459235_3a3e2fa062_o.png&quot; alt=&quot;Apple logo&quot; /&gt;&lt;/p&gt;




&lt;p&gt;It is the perfect solution if you want to work out, for example at Starbucks.&amp;nbsp;I take a long break every time I need to charge the &lt;a title=&quot;Apple - MacBook Pro - Learn all about the breakthrough battery.&quot; href=&quot;http://www.apple.com/macbookpro/battery/&quot; target=&quot;_blank&quot;&gt;battery&lt;/a&gt;. This means that every ~4-6* hours I will get a an hour off for full refreshment. :-)&lt;/p&gt;


&lt;p&gt;* with Visual Studio, VirtualBox and about 25-30 open tabs in Chrome.&lt;/p&gt;



</description>
			<pubDate>Fri, 21 Jan 2011 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Code Coverage without NCover</title>
			<link>http://nikosbaxevanis.com/2011/01/21/net-code-coverage-without-ncover</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/01/21/net-code-coverage-without-ncover</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Let&amp;#39;s analyze code coverage in the&amp;#0160;&lt;a href=&quot;http://dynamicviewmodel.codeplex.com/&quot; target=&quot;_blank&quot; title=&quot;This project aims to provide a way to implement the Model View ViewModel (MVVM) architectural pattern using Plain Old CLR Objects (POCOs) while taking full advantage of .NET 4.0 DynamicObject Class.&quot;&gt;DynamicViewModel&lt;/a&gt;&amp;#0160;project.&lt;/p&gt;


&lt;p&gt;I currently work with Visual Studio 2010 Premium. This product comes with Code Coverage so I thought I should give it a try with, the&amp;#0160;unit testing tool I use,&amp;#0160;&lt;a href=&quot;http://xunit.codeplex.com/&quot; target=&quot;_blank&quot; title=&quot;xUnit.net is a unit testing tool for the .NET Framework.&quot;&gt;xUnit.net&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;First of all, if you do a lot of unit testing, I suggest using the&amp;#0160;&lt;a href=&quot;http://www.google.gr/url?sa=t&amp;amp;source=web&amp;amp;cd=2&amp;amp;ved=0CBoQFjAB&amp;amp;url=http%3A%2F%2Fwww.testdriven.net%2F&amp;amp;ei=I3A5TeO8Dczssgbw2bzzBg&amp;amp;usg=AFQjCNFFiRlQapOFMcbUcbKyl37SNWRygw&amp;amp;sig2=B37qeEgk0LSAevdmGq5z_A&quot; target=&quot;_blank&quot; title=&quot;http://www.testdriven.net/&quot;&gt;TestDriven.Net&lt;/a&gt;&amp;#0160;add-in for Visual Studio because it is fully integrated with xUnit.net (and many other unit testing tools).&lt;/p&gt;


&lt;p&gt;Right-Click on the project under test, select Test With &amp;gt; Coverage:&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8500/8398555174_7a12f17243_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;The Code Coverage Results tab shows the % of Not Covered/Covered Blocks:&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8353/8398555110_237199b896_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;Using the object explorer we navigate to the methods that are not fully covered:&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8376/8398555104_1ff09f326f_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;Right-Click on any method &amp;gt; Go to source code. This will navigates us to the target method:&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8497/8397466461_7af064d53c_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;In the target method we can now see the portion of the code that is not covered.&amp;#0160;&lt;/p&gt;


&lt;p&gt;Here we can see that there are no unit tests covering the case for invalid property names when binding in the view model:&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8330/8397466403_e126a224be_o.png&quot; alt=&quot;Code not covered by tests&quot;/&gt;&lt;/p&gt;




&lt;p&gt;Let&amp;#39;s add a unit test for that:&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8188/8397466387_3fd667c4b5_o.png&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;




&lt;p&gt;Again, Right-Click on the project under test, select Test With &amp;gt; Coverage:&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8356/8397466379_3ddd680253_o.png&quot; alt=&quot;Code is covered by tests&quot;/&gt;&lt;/p&gt;




&lt;p&gt;That&amp;#39;s it!&amp;#0160;Visual Studio 2010 Cove Coverage feature (on Premium and Ultimate products) plays nicely with TestDriven.Net and xUnit.net!&lt;/p&gt;



</description>
			<pubDate>Fri, 21 Jan 2011 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Replace C# primitive types with FCL types in Visual Studio</title>
			<link>http://nikosbaxevanis.com/2011/01/01/replace-csharp-primitive-types-with-fcl-types-in-visual-studio</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2011/01/01/replace-csharp-primitive-types-with-fcl-types-in-visual-studio</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;blockquote&gt;
&lt;p&gt;A nice Visual Studio macro, for those who prefer not to use the C# language primitive types and use the&amp;#0160;corresponding&amp;#0160;FCL types instead.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;Many people writing C# code prefer to use the FCL types:&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;String&lt;/li&gt;
&lt;li&gt;Int32&lt;/li&gt;
&lt;li&gt;etc.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;As far as I know in Visual Studio there is no way to automate this process. It would be good if you could just select some code and just hide built-in type names. For that reason I wrote &lt;a href=&quot;https://github.com/moodmosaic/BonusBits.CodeSamples/tree/master/VSMacros&quot; target=&quot;_self&quot;&gt;this&lt;/a&gt; Visual Studio macro.&lt;/p&gt;




&lt;p&gt;Download here,&amp;#0160;&lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/downloads/BonusBits.vsmacros&quot; target=&quot;_blank&quot;&gt;right-click save as&lt;/a&gt;.&lt;/p&gt;

</description>
			<pubDate>Sat, 01 Jan 2011 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>A Sneak Preview of WebSocket-enabled WCF Services</title>
			<link>http://nikosbaxevanis.com/2010/12/25/a-sneak-preview-of-websocket-enabled-wcf-services</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/12/25/a-sneak-preview-of-websocket-enabled-wcf-services</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Recently the Interoperability Bridges and Labs Center (run by the Microsoft Interoperability Strategy Group) released a prototype&amp;#0160;&amp;#0160;implementation (in managed code) of two drafts of the WebSockets protocol specification:&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-75&quot; target=&quot;_blank&quot; title=&quot;The Web Socket protocol draft-hixie-thewebsocketprotocol-75&quot;&gt;draft-hixie-thewebsocketprotocol-75&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76&quot; target=&quot;_blank&quot; title=&quot;The WebSocket protocol draft-hixie-thewebsocketprotocol-76.&quot;&gt;draft-hixie-thewebsocketprotocol-76&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;The prototype can be found at&amp;#0160;&lt;a href=&quot;http://html5labs.interoperabilitybridges.com/&quot; target=&quot;_blank&quot; title=&quot;The HTML5 Labs site is the place where Microsoft prototypes early and unstable web standard specifications from standards bodies such as the W3C.&quot;&gt;HTML5 Labs&lt;/a&gt;, however (at the time of this&amp;#0160;writing) the samples did not come with source code and they were delay signed (which means you have to &lt;a href=&quot;http://mailinglist.interoperabilitybridges.com/scripts/wa-INTEROP.exe?A2=HTML5_WEBSOCKETS;e6d276d8.1012&quot; target=&quot;_self&quot;&gt;follow the instructions&lt;/a&gt;&amp;#0160;to run them).&amp;#0160;After running the samples (and since I had no access to the source code) I opened with reflector and had a look under the hood.&lt;/p&gt;


&lt;p&gt;What I noticed is that a WebSocket-enabled service in .NET will be written like any other WCF service with &lt;span style=&quot;text-decoration: underline;&quot;&gt;two differences&lt;/span&gt;:&lt;/p&gt;


&lt;p&gt;The service implementation has to derive from the base WebSocketService class:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;[ServiceBehavior(
    InstanceContextMode=InstanceContextMode.PerSession, 
    ConcurrencyMode=ConcurrencyMode.Multiple)]
internal sealed class NotificationService : WebSocketsService
{
    // ...
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;The service host is a type deriving from the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.servicemodel.servicehost.aspx&quot; target=&quot;_blank&quot; title=&quot;Provides a host for services.&quot;&gt;ServiceHost&lt;/a&gt;&amp;#0160;named&amp;#0160;WebSocketsHost:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;Uri baseAddress = new Uri(&amp;quot;&amp;lt;uriString goes here&amp;gt;&amp;quot;);            
WebSocketsHost&amp;lt;NotificationService&amp;gt; host =
    new WebSocketsHost&amp;lt;NotificationService&amp;gt;(baseAddress);
host.AddWebSocketsEndpoint();
host.Open();&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Notice, that since your specify &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.servicemodel.concurrencymode.aspx&quot; target=&quot;_self&quot; title=&quot;Specifies whether a service class supports single-threaded or multi-threaded modes of operation.&quot;&gt;ConcurrencyMode.Multipe&lt;/a&gt; you have to manually handle synchronization and state using a synchronization construct. That means if the clients need only write-access to the data you can use a mutual exclusive lock (like the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.threading.monitor.aspx&quot; target=&quot;_blank&quot; title=&quot;Provides a mechanism that synchronizes access to objects.&quot;&gt;Monitor Class&lt;/a&gt;)&amp;#0160;otherwise you can use a lock like the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.threading.readerwriterlockslim.aspx&quot; target=&quot;_blank&quot; title=&quot;Represents a lock that is used to manage access to a resource, allowing multiple threads for reading or exclusive access for writing.&quot;&gt;ReaderWriterLockSlim Class&lt;/a&gt;&amp;#0160;(or a faster one).&lt;/p&gt;


&lt;p&gt;Here is a summary of links about the WebSocket prototype for .NET:&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;HTML5 Labs, &lt;a href=&quot;http://html5labs.interoperabilitybridges.com/prototypes/available-for-download/websockets&quot; target=&quot;_blank&quot; title=&quot;HTML5 Labs, WebSockets.&quot;&gt;WebSockets prototype&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Tomasz Janczuk&amp;#39;s,&amp;#0160;&lt;a href=&quot;http://blogs.msdn.com/b/interoperability/archive/2010/12/21/introducing-the-websockets-prototype.aspx&quot; target=&quot;_blank&quot; title=&quot;Introducing the WebSockets prototype draft-montenegro-hybi-upgrade-hello-handshake-00&quot;&gt;Blog post&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Interoperability @ Microsoft, &lt;a href=&quot;http://blogs.msdn.com/b/interoperability/archive/2010/12/21/introducing-the-websockets-prototype.aspx&quot; target=&quot;_blank&quot; title=&quot;Introducing the WebSockets Prototype.&quot;&gt;Blog post&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;&lt;a href=&quot;http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=5962224&quot; rel=&quot;tag&quot; style=&quot;display: none;&quot;&gt;CodeProject&lt;/a&gt;&lt;/p&gt;



</description>
			<pubDate>Sat, 25 Dec 2010 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>MVVM using POCOs with .NET 4.0 and the DynamicViewModel Class</title>
			<link>http://nikosbaxevanis.com/2010/12/17/mvvm-using-pocos-with-net-4-0-and-the-dynamicviewmodel-class</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/12/17/mvvm-using-pocos-with-net-4-0-and-the-dynamicviewmodel-class</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;blockquote&gt;
&lt;p&gt;This post aims to provide a way to implement the Model View ViewModel (MVVM) architectural pattern using Plain Old CLR Objects (POCOs) while taking full advantage of .NET 4.0 DynamicObject Class.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;In order to apply the Model View ViewModel (MVVM) architectural pattern we need:&lt;/p&gt;


&lt;ol&gt;
&lt;li&gt;An instance of the View, (e.g. a UserControl type).&lt;/li&gt;
&lt;li&gt;An instance of the ViewModel, which in most scenarios is a class implementing the INotifyPropertyChanged interface (or inherits from a base class getting the implementation for free).&lt;/li&gt;
&lt;li&gt;An instance of the Model inside the ViewModel class, for getting the properties to display (and format them if necessary) and also for invoking commands on the model.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;While we can not avoid step 1 (we need to have something to display to the user) and step 3 (we need to have something the user can read/edit), for basic scenarios we can try to avoid step 2.&amp;#0160;&lt;/p&gt;


&lt;p&gt;Taking advantage of the .NET 4.0 and the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.dynamic.dynamicobject.aspx&quot; target=&quot;_blank&quot; title=&quot;Provides a base class for specifying dynamic behavior at run time. This class must be inherited from; you cannot instantiate it directly.&quot;&gt;DynamicObject&lt;/a&gt;&amp;#0160;Class, we can create a type deriving from the DynamicObject Class and&amp;#0160;specify dynamic behavior at run time. Furthermore, we can implement the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx&quot; target=&quot;_blank&quot; title=&quot;Notifies clients that a property value has changed.&quot;&gt;INotifyPropertyChanged&lt;/a&gt;&amp;#0160;Interface on the derived type making it a good candidate for Data Binding.&lt;/p&gt;


&lt;p&gt;Let&amp;#39;s name our class, DynamicViewModel(Of TModel) Class. It must be able to:&lt;/p&gt;


&lt;ol&gt;
&lt;li&gt;Accept references types (any class - a model is usually a class).&lt;/li&gt;
&lt;li&gt;Invoke public instance methods.&lt;/li&gt;
&lt;li&gt;Invoke public instance methods with arguments passed as CommandParameters.&lt;/li&gt;
&lt;li&gt;Get public instance properties.&lt;/li&gt;
&lt;li&gt;Set public instance properties.&lt;/li&gt;
&lt;li&gt;Notify callers when property change by raising the PropertyChanged event.&lt;/li&gt;
&lt;li&gt;If a property change results in chaning other properties, the caller must receive the notification for the other property changes too.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;Here is the &lt;a href=&quot;http://dynamicviewmodel.codeplex.com/SourceControl/changeset/view/9e2b2d03b705#DynamicViewModel%2fDynamicViewModel.cs&quot; target=&quot;_blank&quot; title=&quot;The DynamicViewModel(Of TModel) Class adds dynamic ViewModel behavior to any class at runtime.&quot;&gt;DynamicViewModel(Of TModel)&lt;/a&gt; Class:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Dynamic;
using System.Linq;
using System.Reflection;
using System.Threading;
 
internal sealed class DynamicViewModel&amp;lt;TModel&amp;gt;
    : DynamicObject, INotifyPropertyChanged where TModel : class
{
    private static readonly IDictionary&amp;lt;string, MethodInfo&amp;gt; methodInfos
        = GetPublicInstanceMethods();
 
    private static readonly IDictionary&amp;lt;string, PropertyInfo&amp;gt; propInfos
        = GetPublicInstanceProperties();
 
    private readonly TModel model;

    private IDictionary&amp;lt;string, object&amp;gt; propertyValues;
 
    public DynamicViewModel(TModel model)
    {
        this.model = model;
        NotifyChangedProperties();
    }
 
    public DynamicViewModel(Func&amp;lt;TModel&amp;gt; @delegate)
        : this(@delegate.Invoke()) { }
 
    public override bool TryInvokeMember(InvokeMemberBinder binder,
        object[] args, out object result)
    {
        result = null;
 
        MethodInfo methodInfo;
        if (!methodInfos.TryGetValue(binder.Name,
            out methodInfo)) { return false; }
 
        methodInfo.Invoke(this.model, args);
        NotifyChangedProperties();
        return true;
    }
 
    public override bool TryGetMember(GetMemberBinder binder,
        out object result)
    {
        var propertyValues = Interlocked.CompareExchange(
            ref this.propertyValues, GetPropertyValues(), null);
 
        if (!propertyValues.TryGetValue(binder.Name,
            out result)) { return false; }
 
        return true;
    }
 
    public override bool TrySetMember(SetMemberBinder binder, object value)
    {
        PropertyInfo propInfo = propInfos[binder.Name];
        propInfo.SetValue(this.model, value, null);
 
        NotifyChangedProperties();
        return true;
    }
 
    public void NotifyChangedProperties()
    {
        Interlocked.CompareExchange(
            ref this.propertyValues, GetPropertyValues(), null);

        IDictionary&amp;lt;string, object&amp;gt; previousPropValues
            = this.propertyValues;

        IDictionary&amp;lt;string, object&amp;gt; currentPropValues
            = GetPropertyValues();
 
        this.propertyValues
            = currentPropValues;
 
        foreach (KeyValuePair&amp;lt;string, object&amp;gt; propValue
            in currentPropValues.Except(previousPropValues))
        {
            RaisePropertyChanged(propValue.Key);
        }
    }
 
    private static IDictionary&amp;lt;string, MethodInfo&amp;gt; GetPublicInstanceMethods()
    {
        var methodInfoDictionary = new Dictionary&amp;lt;string, MethodInfo&amp;gt;();
        MethodInfo[] methodInfos = typeof(TModel).GetMethods(
            BindingFlags.Public | BindingFlags.Instance);
        foreach (MethodInfo methodInfo in methodInfos)
        {
            if (methodInfo.Name.StartsWith(&amp;quot;get_&amp;quot;) ||
                methodInfo.Name.StartsWith(&amp;quot;set_&amp;quot;)) { continue; }
            methodInfoDictionary.Add(methodInfo.Name, methodInfo);
        }
 
        return methodInfoDictionary;
    }
 
    private static IDictionary&amp;lt;string, PropertyInfo&amp;gt;
        GetPublicInstanceProperties()
    {
        var propInfoDictionary = new Dictionary&amp;lt;string, PropertyInfo&amp;gt;();
        PropertyInfo[] propInfos = typeof(TModel).GetProperties(
            BindingFlags.Public | BindingFlags.Instance);
        foreach (PropertyInfo propInfo in propInfos)
        {
            propInfoDictionary.Add(propInfo.Name, propInfo);
        }
 
        return propInfoDictionary;
    }

    private IDictionary&amp;lt;string, object&amp;gt; GetPropertyValues()
    {
        var bindingPaths = new Dictionary&amp;lt;string, object&amp;gt;();
        PropertyInfo[] propInfos = typeof(TModel).GetProperties(
            BindingFlags.Public | BindingFlags.Instance);
        foreach (PropertyInfo propInfo in propInfos)
        {
            bindingPaths.Add(
                propInfo.Name,
                propInfo.GetValue(this.model, null));
        }
 
        return bindingPaths;
    }
 
    private void RaisePropertyChanged(string propertyName)
    {
        OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
    }
 
    private void OnPropertyChanged(PropertyChangedEventArgs e)
    {
        PropertyChangedEventHandler temp =
            Interlocked.CompareExchange(ref PropertyChanged, null, null);
 
        if (temp != null)
        {
            temp(this, e);
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;The sample application for this post comes with a simple ContactView which has no specific viewModel but instead uses the DynamicViewModel(Of TModel) class.&lt;/p&gt;




&lt;p&gt;The DynamicViewModel(Of TModel) Class is able to update the View which binds to an instance of this class.&lt;/p&gt;




&lt;p&gt;Here is what the sample application does:&lt;/p&gt;


&lt;ol&gt;
&lt;li&gt;Changing the First Name will result in changing the Full Name and the Reversed Full Name.&lt;/li&gt;
&lt;li&gt;The same rules apply when chaning the Last Name.&amp;#0160;&lt;/li&gt;
&lt;li&gt;The&amp;#0160;hyper-link is enabled only if the user presses the Clear Names button.&amp;#0160;&lt;/li&gt;
&lt;li&gt;The Clear Names button is enabled only when the Full Name text is not empty.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;Here is the POCO model class that I have used:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;using System;
 
internal sealed class ContactDetails
{ 
    public string FirstName
    {
        get
        {
            return this.firstName;
        }
 
        set
        {
            this.firstName = value;
 
            SetFullName();
            SetReversedFullName();
        }
    }
 
    public string LastName
    {
        get
        {
            return this.lastName;
        }
 
        set
        {
            this.lastName = value;
 
            SetFullName();
            SetReversedFullName();
        }
    }
 
    public string FullName
    {
        get
        {
            return this.fullName;
        }
 
        set
        {
            this.fullName = value;
        }
    }
 
    public void ClearFullName()
    {
        FirstName = string.Empty;
        LastName  = string.Empty;
    }
 
    /// &amp;lt;summary&amp;gt;
    /// Navigates to this contact's website.
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name=&amp;quot;uriString&amp;quot;&amp;gt;The URI string.&amp;lt;/param&amp;gt;
    public void NavigateTo(string uriString)
    {
        System.Diagnostics.Process.Start(uriString);
    }
 
    private void SetFullName()
    {
        FullName = FirstName + &amp;quot; &amp;quot; + LastName;
    }
 
    // (Less important members not shown)
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;As you notice, this class &lt;em&gt;does not implement any interface or base class&lt;/em&gt;. In fact, this class can be used successfully in ORM scenarios too (when you need to bind on the same classes that are used in your mappings).&lt;/p&gt;


&lt;p&gt;Finally, I would like to show how the View&amp;#39;s DataContext is initialized properly to accept the DynamicViewModel(Of TModel) Class wrapper around the model class:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;/// &amp;lt;summary&amp;gt;
/// Interaction logic for ContactView.xaml
/// &amp;lt;/summary&amp;gt;
internal partial class ContactView : UserControl
{
    public static readonly RoutedCommand ClearNamesCommand
        = new RoutedCommand();
 
    public static readonly RoutedCommand NavigateUriCommand
        = new RoutedCommand();
 
    public ContactView()
    {
        InitializeComponent();
 
        // Create a new instance. Once created
        // do not call methods directly on this
        // object. (Use the dynamic viewModel).
        var instance  = new ContactDetails() {
            FirstName = &amp;quot;Nikos&amp;quot;,
            LastName  = &amp;quot;Baxevanis&amp;quot;
        };
 
        dynamic viewModel = new DynamicViewModel&amp;lt;ContactDetails&amp;gt;(instance);
 
        // Wire the ClearNamesCommand from the view to the viewModel.
        CommandManager.RegisterClassCommandBinding(typeof(ContactView),
            new CommandBinding(
                ClearNamesCommand,
                (sender, e) =&amp;gt; { viewModel.ClearFullName(); },
                (sender, e) =&amp;gt; { e.CanExecute = !string.IsNullOrWhiteSpace(
                     viewModel.FullName); }));
 
        // Wire the NavigateUriCommand from the view to the viewModel.
        CommandManager.RegisterClassCommandBinding(typeof(ContactView),
            new CommandBinding(
                NavigateUriCommand,
                (sender, e) =&amp;gt; { viewModel.NavigateTo(e.Parameter); },
                (sender, e) =&amp;gt; { e.CanExecute =                
                    string.IsNullOrWhiteSpace(viewModel.FullName); }));
 
        DataContext = viewModel;
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Notice that wiring between the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.windows.input.icommand.aspx&quot; target=&quot;_blank&quot; title=&quot;Defines a command.&quot;&gt;ICommand&lt;/a&gt;&amp;#0160;Interface and the model class is done outside the dynamic ViewModel wrapper using the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.windows.input.commandmanager.aspx&quot; target=&quot;_blank&quot; title=&quot;Provides command related utility methods that register CommandBinding and InputBinding objects for class owners and commands, add and remove command event handlers, and provides services for querying the status of a command.&quot;&gt;CommandManager&lt;/a&gt;&amp;#0160;Class which acts as a &lt;a href=&quot;http://en.wikipedia.org/wiki/Mediator_pattern&quot; target=&quot;_blank&quot; title=&quot;Provides a unified interface to a set of interfaces in a subsystem.&quot;&gt;mediator&lt;/a&gt; between the View and the ViewModel. This give us the flexibility to define static reusable commands or specific commands for each view (as I&amp;#39;ve done above).&lt;/p&gt;




&lt;p&gt;The sample application can be found &lt;a href=&quot;http://dynamicviewmodel.codeplex.com/releases/view/57761&quot; target=&quot;_blank&quot; title=&quot;moodmosaic / DynamicViewModel&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
			<pubDate>Fri, 17 Dec 2010 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>ComponentBase(Of T) Class for NHibernate Components</title>
			<link>http://nikosbaxevanis.com/2010/12/10/componentbase-of-t-class-for-nhibernate-component</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/12/10/componentbase-of-t-class-for-nhibernate-component</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;blockquote&gt;
&lt;p&gt;This post aims to provide a way to implement a base class for NHibernate components also known as Value Objects in Domain-driven design.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8494/8398555268_0491f387b3_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;


&lt;p&gt;In my &lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2010/12/component-collections-in-nhibernate.html&quot; target=&quot;_blank&quot; title=&quot;Component Collections in NHibernate.&quot;&gt;previous post&lt;/a&gt; I discussed about the case where you want to map a component with NHibernate and introduced the ComponentBase(Of T) class. However, to make it&amp;#0160;straightforward&amp;#0160;that you need to override Equals (you also need to override GetHashCode) in your derived classes, I modified the ComponentBase(Of T) class to implement the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms131187.aspx&quot; target=&quot;_blank&quot; title=&quot;Defines a generalized method that a value type or class implements to create a type-specific method for determining equality of instances.&quot;&gt;IEquatable(Of T)&lt;/a&gt; interface.&amp;#0160;Furthermore, since NHibernate works only with reference types (that is, a class) I also constrained it to accept only reference types.&lt;/p&gt;


&lt;p&gt;Here is the Component(Of T) class:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;using System;
 
public abstract class ComponentBase&amp;lt;T&amp;gt; 
    : IEquatable&amp;lt;T&amp;gt; where T : class 
{
    /// &amp;lt;summary&amp;gt;
    /// Indicates whether the current object is equal to another
    /// object of the same type.
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name=&amp;quot;other&amp;quot;&amp;gt;An object to compare with this object.
    /// &amp;lt;/param&amp;gt;
    /// &amp;lt;returns&amp;gt;true if the current object is equal to the other
    /// parameter; otherwise, false.&amp;lt;/returns&amp;gt;
    public abstract bool Equals(T other);
 
    /// &amp;lt;summary&amp;gt;
    /// Serves as a hash function for a particular type,
    /// suitable for use in hashing
    /// algorithms and data structures such as a hash table.
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;returns&amp;gt;
    /// A hash code for this instance of the type.
    /// &amp;lt;/returns&amp;gt;
    public abstract int GetHashCodeForType();
 
    /// &amp;lt;summary&amp;gt;
    /// Determines whether the specified &amp;lt;see cref=&amp;quot;System.Object&amp;quot;/&amp;gt;
    /// is equal to this instance.
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name=&amp;quot;obj&amp;quot;&amp;gt;The &amp;lt;see cref=&amp;quot;System.Object&amp;quot;/&amp;gt; to
    /// compare with this instance.
    /// &amp;lt;/param&amp;gt;
    /// &amp;lt;returns&amp;gt;
    ///     &amp;lt;c&amp;gt;true&amp;lt;/c&amp;gt; if the specified &amp;lt;see cref=&amp;quot;System.Object&amp;quot;/&amp;gt;
    ///     is equal to this instance;
    ///     otherwise, &amp;lt;c&amp;gt;false&amp;lt;/c&amp;gt;.
    /// &amp;lt;/returns&amp;gt;
    public sealed override bool Equals(object obj)
    {
        // The given object to compare to can't be null.
        if (obj == null) { return false; }
 
        // If objects are different types, they can't be equal.
        if (this.GetType() != obj.GetType()) { return false; }
 
        return Equals(obj as T);
    }
 
    /// &amp;lt;summary&amp;gt;
    /// Returns a hash code for this instance.
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;returns&amp;gt;
    /// A hash code for this instance, suitable for
    /// use in hashing algorithms and data structures
    /// like a hash table.
    /// &amp;lt;/returns&amp;gt;
    public sealed override int GetHashCode()
    {
        return GetHashCodeForType();
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Below are some test cases:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;using System;
using Xunit;
 
public sealed class ComponentBaseTest
{
    private sealed class MockType 
         : ComponentBase&amp;lt;MockType&amp;gt; { /* ... */ }
 
    [Fact]
    public void TheSameInstanceHasTheSameHashCode()
    {
        MockType mt1 = new MockType(5);
        MockType mt2 = mt1;
        Assert.Equal(mt1.GetHashCode(), mt2.GetHashCode());
    }
 
    [Fact]
    public void DiffInstancesWithSameCtorParamsHaveTheSameHashCode()
    {
        MockType mt1 = new MockType(5);
        MockType mt3 = new MockType(5);
        Assert.Equal(mt1.GetHashCode(), mt3.GetHashCode());
    }
 
    [Fact]
    public void TestDiffInstancesWithSameCtorParamsAreEqual()
    {
        MockType mt1 = new MockType(5);
        MockType mt3 = new MockType(5);
        // Objects are equal.
        Assert.True(mt1.Equals(mt3));
        // References are not equal.
        Assert.False(object.ReferenceEquals(mt1, mt3));
    }
 
    [Fact]
    public void TestDiffInstancesWithDiffCtorParamsAreNotEqual()
    {
        MockType mt1 = new MockType(1);
        MockType mt3 = new MockType(3);
        // Objects are not equal.
        Assert.False(mt1.Equals(mt3));
        // References are not equal.
        Assert.False(object.ReferenceEquals(mt1, mt3));
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;You can use this class in your component collections. If you want to map a Set (that is, an unordered collection of unique entities where duplicates are not allowed)&amp;#0160;just derive your component types from ComponentBase(Of T).&amp;#0160;Derived types need to implement the&amp;#0160;strongly-typed version of Equals and also the GetHashCode methods.&lt;/p&gt;



</description>
			<pubDate>Fri, 10 Dec 2010 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Component Collections in NHibernate</title>
			<link>http://nikosbaxevanis.com/2010/12/09/component-collections-in-nhibernate</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/12/09/component-collections-in-nhibernate</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt;&amp;#0160;In &lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2010/12/component-base-class-nhibernate.html&quot; target=&quot;_blank&quot; title=&quot;ComponentBase(Of T) Class for NHibernate Components.&quot;&gt;this post&lt;/a&gt; I discuss further about the ComponentBase(Of T) Class.&lt;/p&gt;


&lt;p&gt;Objects that are used to describe certain&amp;#0160;aspects of a domain, and which do not have identity, are named&amp;#0160;Value Objects (do not confuse them with .NET Value Types). Value Object is a term used in &lt;a href=&quot;http://en.wikipedia.org/wiki/Domain-driven_design&quot; target=&quot;_blank&quot; title=&quot;omain-driven design (DDD) is an approach to developing software for complex needs by deeply connecting the implementation to an evolving model of the core business concepts.&quot;&gt;Domain-driven design&lt;/a&gt; (DDD). In NHibernate, such kind of objects are declared using the &lt;i&gt;component&lt;/i&gt; tag. However, &lt;span style=&quot;text-decoration: underline;&quot;&gt;collections of components&lt;/span&gt; are declared with a &lt;i&gt;composite-element&lt;/i&gt; tag.&lt;/p&gt;


&lt;p&gt;Here is an example with &lt;a href=&quot;http://www.fluentnhibernate.org/&quot; target=&quot;_blank&quot;&gt;Fluent NHibernate&lt;/a&gt;:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;/*
&amp;lt;set name=&amp;quot;MandatoryCoverages&amp;quot;
    table=&amp;quot;CarUseMandatoryCoverageFees&amp;quot; mutable=&amp;quot;true&amp;quot;&amp;gt;
&amp;lt;key&amp;gt;
    &amp;lt;column name=&amp;quot;CarUse_id&amp;quot; /&amp;gt;
&amp;lt;/key&amp;gt;
&amp;lt;composite-element class=&amp;quot;Domain.Car.CarCoverageFee, ..&amp;quot;&amp;gt;
    &amp;lt;property name=&amp;quot;NetFeePercentage&amp;quot; type=&amp;quot;System.Double, ..&amp;quot;&amp;gt;
    &amp;lt;column name=&amp;quot;NetFeePercentage&amp;quot; /&amp;gt;
    &amp;lt;/property&amp;gt;
    &amp;lt;many-to-one class=&amp;quot;Domain.Car.CarCoverageFee,
                fetch=&amp;quot;join&amp;quot; name=&amp;quot;Coverage&amp;quot;&amp;gt;
    &amp;lt;column name=&amp;quot;Coverage_id&amp;quot; /&amp;gt;
    &amp;lt;/many-to-one&amp;gt;
&amp;lt;/composite-element&amp;gt;
&amp;lt;/set&amp;gt;
*/
HasMany&amp;lt;CarCoverageFee&amp;gt;(x =&amp;gt; x.MandatoryCoverages)
    .AsSet()
    .Table(&amp;quot;CarUseMandatoryCoverageFees&amp;quot;)
    .Component(fee =&amp;gt;
    {
        fee.References&amp;lt;Coverage&amp;gt;(x =&amp;gt; x.Coverage).Fetch.Join();
        fee.Map(x =&amp;gt; x.NetFeePercentage);
    });&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;br /&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;/*
&amp;lt;set name=&amp;quot;OptionalCoverages&amp;quot;
    table=&amp;quot;CarUseOptionalCoverageFees&amp;quot; mutable=&amp;quot;true&amp;quot;&amp;gt;
&amp;lt;key&amp;gt;
    &amp;lt;column name=&amp;quot;CarUse_id&amp;quot; /&amp;gt;
&amp;lt;/key&amp;gt;
&amp;lt;composite-element class=&amp;quot;Domain.Car.CarCoverageFee, ..&amp;quot;&amp;gt;
    &amp;lt;property name=&amp;quot;NetFeePercentage&amp;quot; type=&amp;quot;System.Double, ..&amp;quot;&amp;gt;
    &amp;lt;column name=&amp;quot;NetFeePercentage&amp;quot; /&amp;gt;
    &amp;lt;/property&amp;gt;
    &amp;lt;many-to-one class=&amp;quot;Domain.Car.CarCoverageFee,
                fetch=&amp;quot;join&amp;quot; name=&amp;quot;Coverage&amp;quot;&amp;gt;
    &amp;lt;column name=&amp;quot;Coverage_id&amp;quot; /&amp;gt;
    &amp;lt;/many-to-one&amp;gt;
&amp;lt;/composite-element&amp;gt;
&amp;lt;/set&amp;gt;
*/
HasMany&amp;lt;CarCoverageFee&amp;gt;(x =&amp;gt; x.OptionalCoverages)
    .AsSet()
    .Table(&amp;quot;CarUseOptionalCoverageFees&amp;quot;)
    .Component(fee =&amp;gt;
    {
        fee.References&amp;lt;Coverage&amp;gt;(x =&amp;gt; x.Coverage).Fetch.Join();
        fee.Map(x =&amp;gt; x.NetFeePercentage);
    });&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;The&amp;#0160;CarCoverageFee class is a component (a Value Object for DDD) so &lt;span style=&quot;text-decoration: underline;&quot;&gt;it does not have an identity field&lt;/span&gt;.&amp;#0160;This creates a lot of noise between the application and the database as we can see from the image below:&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8183/8397466663_aa3d5e1fca_b.jpg&quot; alt=&quot;Profiler output, without overriding Equals and GetHashCode&quot; /&gt;&lt;/p&gt;




&lt;p&gt;We can define an abstract base class for our components. Inside this class we override the Equals method and immediately throw an exception to the caller indicating that this method must be overridden by the caller:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public abstract class ComponentBase
{
    /// &amp;lt;summary&amp;gt;
    /// Determines whether the specified
    /// &amp;lt;see cref=&amp;quot;System.Object&amp;quot;/&amp;gt; is equal
    /// to this instance.
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name=&amp;quot;obj&amp;quot;&amp;gt;The &amp;lt;see cref=&amp;quot;System.Object&amp;quot;/&amp;gt;
    /// to compare with this instance.&amp;lt;/param&amp;gt;
    /// &amp;lt;returns&amp;gt;
    ///     &amp;lt;c&amp;gt;true&amp;lt;/c&amp;gt; if the specified
    ///     &amp;lt;see cref=&amp;quot;System.Object&amp;quot;/&amp;gt; is equal to this
    ///     instance; otherwise, &amp;lt;c&amp;gt;false&amp;lt;/c&amp;gt;.
    /// &amp;lt;/returns&amp;gt;
    /// &amp;lt;exception cref=&amp;quot;T:System.NullReferenceException&amp;quot;&amp;gt;
    /// The &amp;lt;paramref name=&amp;quot;obj&amp;quot;/&amp;gt; parameter is null.
    /// &amp;lt;/exception&amp;gt;
    public override bool Equals(object obj)
    {
        throw new MethodAccessException(
            &amp;quot;Components must be compared using property values.&amp;quot;);
    }
 
    /// &amp;lt;summary&amp;gt;
    /// Returns a hash code for this instance.
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;returns&amp;gt;
    /// A hash code for this instance, suitable for
    /// use in hashing algorithms and data structures
    /// like a hash table.
    /// &amp;lt;/returns&amp;gt;
    public override int GetHashCode()
    {
        throw new MethodAccessException(
            &amp;quot;Components must be hashed using property values.&amp;quot;);
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Here is the class, modified to inherit from the ComponentBase class:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public class CarCoverageFee : ComponentBase
{
    /// &amp;lt;summary&amp;gt;
    /// Gets or sets the coverage.
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;value&amp;gt;The coverage.&amp;lt;/value&amp;gt;
    public virtual Coverage Coverage { get; set; }
 
    /// &amp;lt;summary&amp;gt;
    /// Gets or sets the fee.
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;value&amp;gt;The fee.&amp;lt;/value&amp;gt;
    public virtual double NetFeePercentage { get; set; }
 
    /// &amp;lt;summary&amp;gt;
    /// Determines whether the specified
    /// &amp;lt;see cref=&amp;quot;System.Object&amp;quot;/&amp;gt; is equal
    /// to this instance.
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name=&amp;quot;obj&amp;quot;&amp;gt;The &amp;lt;see cref=&amp;quot;System.Object&amp;quot;/&amp;gt;
    /// to compare with this instance.&amp;lt;/param&amp;gt;
    /// &amp;lt;returns&amp;gt;
    ///     &amp;lt;c&amp;gt;true&amp;lt;/c&amp;gt; if the specified
    ///     &amp;lt;see cref=&amp;quot;System.Object&amp;quot;/&amp;gt; is equal to this
    ///     instance; otherwise, &amp;lt;c&amp;gt;false&amp;lt;/c&amp;gt;.
    /// &amp;lt;/returns&amp;gt;
    /// &amp;lt;exception cref=&amp;quot;T:System.NullReferenceException&amp;quot;&amp;gt;
    /// The &amp;lt;paramref name=&amp;quot;obj&amp;quot;/&amp;gt; parameter is null.
    /// &amp;lt;/exception&amp;gt;
    public override bool Equals(object obj)
    {
        // The given object to compare to can't be null.
        if (obj == null) { return false; }
 
        // If objects are different types, they can't be equal.
        if (this.GetType() != obj.GetType()) { return false; }
 
        // At this point, we really know that obj is really
        // a CarCoverageFee object. Cast obj to CarCoverageFee.
        if (Coverage.Code != ((CarCoverageFee)obj)
            .Coverage.Code) { return false; }
 
        return true;
    }
 
    /// &amp;lt;summary&amp;gt;
    /// Returns a hash code for this instance.
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;returns&amp;gt;
    /// A hash code for this instance, suitable for
    /// use in hashing algorithms and data structures
    /// like a hash table.
    /// &amp;lt;/returns&amp;gt;
    public override int GetHashCode()
    {
        return Coverage.Name.GetHashCode()
             + Coverage.Code.GetHashCode();
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;After overriding Equals and GetHashCode methods, I compared the Sessions:&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8079/8398555276_1b307eb2dd_b.jpg&quot; alt=&quot;The Diff after overriding Equals and GetHashCode&quot; /&gt;&lt;/p&gt;




&lt;p&gt;Now, everything looks fine; No necessary inserts and deletes.&lt;/p&gt;



</description>
			<pubDate>Thu, 09 Dec 2010 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Building a Metro UI with WPF</title>
			<link>http://nikosbaxevanis.com/2010/12/01/building-a-metro-ui-with-wpf</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/12/01/building-a-metro-ui-with-wpf</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8075/8397466987_1b6913aa26_o.png&quot; alt=&quot;A very metro-ish image&quot; /&gt;&lt;/p&gt;




&lt;p&gt;Have you ever used the &lt;a href=&quot;http://www.zune.net/&quot; target=&quot;_blank&quot; title=&quot;The Zune software organizes the media in its library and allows users to add to the library by ripping from CDs, syncing with a Zune device, and downloading from the Zune Marketplace. The Zune software also allows one to organize song metadata. It can automatically download album art and metadata tag data for content in the library.&quot;&gt;Zune&lt;/a&gt; software? I guess so, but I haven&amp;#39;t until version&amp;#0160;4.7.1404.0 came out. This version comes with significant changes:&amp;#0160;Windows Phone 7 support and integration with Windows Live Essentials 2011 among other.&lt;/p&gt;


&lt;p&gt;When I first run the software I got amazed by the user interface (UI). I told to myself, &amp;quot;this must not be WPF, no way!&amp;quot;. The text was so clear and the UI was so responsive. I also looked in &lt;a href=&quot;http://en.wikipedia.org/wiki/Zune#Zune_software&quot; target=&quot;_blank&quot; title=&quot;Zune software History&quot;&gt;Wikipedia&lt;/a&gt; and read that the first versions of Zune software were released back in 2006. At this time WPF was about to be released with .NET 3.0 (release date was Nov 2006).&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8091/8398555764_9d52a62608_o.png&quot; alt=&quot;Zune&quot; /&gt;&lt;/p&gt;




&lt;p&gt;Since the UI is not built with WPF then what kind of technology did the Zune team used? Could it be MFC or some other unmanaged UI? To find out, I&amp;#0160;launched the &lt;a href=&quot;http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx&quot; target=&quot;_blank&quot; title=&quot;Process Explorer, also known as procexp.exe, shows you information about which handles and DLLs processes have opened or loaded.&quot;&gt;Process Explorer&lt;/a&gt;&amp;#0160;utility and looked for the Zune executable. By default, .NET Processes are highlighted with yellow as shown in the image below.&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8368/8397467077_6cca0076df_o.png&quot; alt=&quot;Zune process in Process Explorer&quot; /&gt;&lt;/p&gt;




&lt;p&gt;Great, so Zune software is a managed application, or better, if it&amp;#39;s an unmanaged application at least it hosts the CLR in it&amp;#39;s process. (Any Windows application can host the CLR). A quick look in the installation directory yield the following output:&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8508/8398555562_ee8f743d37_o.png&quot; alt=&quot;Zune assemblies&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Followed by a quick view with Reflector:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8331/8398555552_8b74a6d427_o.png&quot; alt=&quot;Zune UIX assembly in Reflector&quot; /&gt;&lt;/p&gt;




&lt;p&gt;As you can see, the root namespace is &lt;em&gt;Microsoft.Iris&lt;/em&gt;. A quick search returned this blog&amp;#0160;&lt;a href=&quot;http://www.istartedsomething.com/20071116/microsoft-iris-uix-framework-zune/&quot; target=&quot;_blank&quot; title=&quot;Mysterious Microsoft Iris UI Framework “UIX” behind the new Zune software eye-candy.&quot;&gt;post&lt;/a&gt;&amp;#0160;and&amp;#0160;this &lt;a href=&quot;http://www.withinwindows.com/2010/03/17/what-the-heck-is-microsoft-iris-here-are-my-notes-thus-far/&quot; target=&quot;_blank&quot; title=&quot;What is Microsoft Iris? Here are my notes thus far.&quot;&gt;one&lt;/a&gt;. It looks like some kind of WPF&amp;#0160;ancestor combined with &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/bb189388.aspx&quot; target=&quot;_blank&quot; title=&quot;Media Center Markup Language Reference&quot;&gt;MCML&lt;/a&gt;.&amp;#0160;&lt;/p&gt;


&lt;p&gt;Is it possible to build a similar UI with WPF?&lt;/p&gt;


&lt;p&gt;The first difficulties came when setting the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.windows.windowstyle.aspx&quot; target=&quot;_blank&quot; title=&quot;WindowStyle Enumeration&quot;&gt;WindowStyle&lt;/a&gt;&amp;#0160;enumeration to None. We need that because with this style only the client area is visible - the title bar and border are not shown.&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8051/8397466915_dc8ae4c3ce_o.png&quot; alt=&quot;First attempt to create a Zune style window&quot; /&gt;&lt;/p&gt;


&lt;p&gt;The image above is not what we want. We need to hide the window boundaries. This can be done by setting the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.windows.resizemode.aspx&quot; target=&quot;_blank&quot; title=&quot;Specifies whether a window can be resized and, if so, how it can be resized.&quot;&gt;ResizeMode&lt;/a&gt; enumeration to NoResize. But now, we can&amp;#39;t move the window, we can&amp;#39;t resize it and the mouse events are not raised! Here is a very nice blog &lt;a href=&quot;http://blogs.msdn.com/b/dwayneneed/archive/2008/09/08/transparent-windows-in-wpf.aspx&quot; target=&quot;_blank&quot; title=&quot;Transparent Windows in WPF&quot;&gt;post&lt;/a&gt; discussing in very detail (among other) the reason for that.&lt;/p&gt;

&lt;p&gt;&lt;span style=&quot;text-decoration: underline;&quot;&gt;How can we move the window?&lt;/span&gt;&lt;/p&gt;


&lt;p&gt;By adding a Shape (ex. a &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.windows.shapes.rectangle.aspx&quot; target=&quot;_blank&quot; title=&quot;Draws a rectangle.&quot;&gt;Rectangle&lt;/a&gt;) and registering on it&amp;#39;s&amp;#0160;PreviewMouseDown event:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;// Is this a double-click?
if (DateTime.Now.Subtract(this.headerLastClicked) &amp;lt;= doubleClick)
{
    // Execute the code inside the event handler for the
    // restore button click passing null for the sender
    // and null for the event args.
    HandleRestoreClick(null, null);
}
 
this.headerLastClicked = DateTime.Now;
 
if (Mouse.LeftButton == MouseButtonState.Pressed)
{
    DragMove();
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;&lt;span style=&quot;text-decoration: underline;&quot;&gt;How can we resize the window?&lt;/span&gt;&lt;/p&gt;


&lt;p&gt;By adding Shapes (ex.&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.windows.shapes.rectangle.aspx&quot; target=&quot;_blank&quot; title=&quot;Draws a rectangle.&quot;&gt;Rectangles&lt;/a&gt;) one on each side of the window (left, top, right, bottom) and registering on it&amp;#39;s&amp;#0160;PreviewMouseDown event:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;Rectangle clickedRectangle = (Rectangle)sender;
 
switch (clickedRectangle.Name)
{
    case &amp;quot;top&amp;quot;:
        Cursor = Cursors.SizeNS;
        ResizeWindow(ResizeDirection.Top);
        break;
    case &amp;quot;bottom&amp;quot;:
        Cursor = Cursors.SizeNS;
        ResizeWindow(ResizeDirection.Bottom);
        break;
    // ...
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Here is the code for resizing the window. It uses the underlying &lt;a href=&quot;http://en.wikipedia.org/wiki/Windows_User&quot; target=&quot;_blank&quot; title=&quot;Windows USER is a component of the Microsoft Windows operating system that provides core functionality for building simple user interfaces. The component has existed in all versions of Windows, and includes functionality for window management, message passing, input processing and standard controls.&quot;&gt;Windows USER&lt;/a&gt; component.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;/// &amp;lt;summary&amp;gt;
/// Resizes the window.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;direction&amp;quot;&amp;gt;The direction.&amp;lt;/param&amp;gt;
private void ResizeWindow(ResizeDirection direction)
{
    NativeMethods.SendMessage(this.hwndSource.Handle, WM_SYSCOMMAND,
        (IntPtr)(61440 + direction), IntPtr.Zero);
}
 
[DllImport(&amp;quot;user32.dll&amp;quot;, CharSet = CharSet.Auto)]
internal static extern IntPtr SendMessage(
    IntPtr hWnd,
    UInt32 msg,
    IntPtr wParam,
    IntPtr lParam);&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;&lt;span style=&quot;text-decoration: underline;&quot;&gt;How can we add a drop shadow to the window?&lt;/span&gt;&lt;/p&gt;


&lt;p&gt;At the time of this&amp;#0160;writing, I know two ways of doing this:&lt;/p&gt;


&lt;p&gt;The first one (which is described &lt;a href=&quot;http://groups.google.com/group/wpf-disciples/browse_thread/thread/82d408e569e0b5f9&quot; target=&quot;_blank&quot; title=&quot;OS Composed DropShadows on WPF Windows with Custom Chrome Options.&quot;&gt;here&lt;/a&gt;) uses the&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa969540(VS.85).aspx&quot; target=&quot;_blank&quot; title=&quot;The desktop composition feature, introduced in Windows Vista, fundamentally changed the way applications display pixels on the screen. When desktop composition is enabled, individual windows no longer draw directly to the screen or primary display device as they did in previous versions of Windows. Instead, their drawing is redirected to off-screen surfaces in video memory, which are then rendered into a desktop image and presented on the display.&quot;&gt;Desktop Window Manager&lt;/a&gt;&amp;#0160;(DWM)&amp;#0160;API. Specifically it uses the&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa969524(VS.85).aspx&quot; target=&quot;_blank&quot; title=&quot;Sets the value of the specified attributes for non-client rendering to apply to the window.&quot;&gt;DwmSetWindowAttribute&lt;/a&gt; Function combined with the &amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa969512(VS.85).aspx&quot; target=&quot;_blank&quot; title=&quot;Extends the window frame behind the client area.&quot;&gt;DwmExtendFrameIntoClientArea &lt;/a&gt;Function to place a drop shadow around the window area. This method works by registering at the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.windows.window.sourceinitialized.aspx&quot; target=&quot;_blank&quot; title=&quot;This event is raised to support interoperation with Win32.&quot;&gt;SourceInitialized&lt;/a&gt; event. When this event is raised, it is a good place to call any code that can&amp;#0160;interoperate&amp;#0160;with the underlying Win32 window.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;/// &amp;lt;summary&amp;gt;
/// Raises the &amp;lt;see cref=&amp;quot;FrameworkElement.Initialized&amp;quot;/&amp;gt; event.
/// This method is invoked whenever
/// &amp;lt;see cref=&amp;quot;P:FrameworkElement.IsInitialized&amp;quot;/&amp;gt;
/// is set to true internally.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;e&amp;quot;&amp;gt;The &amp;lt;see cref=&amp;quot;T:RoutedEventArgs&amp;quot;/&amp;gt;
/// that contains the event data.&amp;lt;/param&amp;gt;
protected override void OnInitialized(EventArgs e)
{
    AllowsTransparency    = false;
    ResizeMode            = ResizeMode.NoResize;
    Height                = 480;
    Width                 = 852; 
    WindowStartupLocation = WindowStartupLocation.CenterScreen;
    WindowStyle           = WindowStyle.None;
 
    SourceInitialized    += HandleSourceInitialized;
 
    base.OnInitialized(e);
}
 
/// &amp;lt;summary&amp;gt;
/// Handles the source initialized.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;sender&amp;quot;&amp;gt;The sender.&amp;lt;/param&amp;gt;
/// &amp;lt;param name=&amp;quot;e&amp;quot;&amp;gt;The &amp;lt;see cref=&amp;quot;System.EventArgs&amp;quot;/&amp;gt;
/// instance containing the event data.&amp;lt;/param&amp;gt;
private void HandleSourceInitialized(object sender, EventArgs e)
{
    this.hwndSource = (HwndSource)PresentationSource.FromVisual(this);
 
    // Returns the HwndSource object for the window
    // which presents WPF content in a Win32 window.
    HwndSource.FromHwnd(this.hwndSource.Handle).AddHook(
        new HwndSourceHook(NativeMethods.WindowProc));
 
    // http://msdn.microsoft.com/en-us/library/aa969524(VS.85).aspx
    int DWMWA_NCRENDERING_POLICY = 2;
    NativeMethods.DwmSetWindowAttribute(
        this.hwndSource.Handle,
        DWMWA_NCRENDERING_POLICY,
        ref DWMWA_NCRENDERING_POLICY,
        4);
 
    // http://msdn.microsoft.com/en-us/library/aa969512(VS.85).aspx
    NativeMethods.ShowShadowUnderWindow(this.hwndSource.Handle);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8212/8397466875_a3a92be9ed_o.png&quot; alt=&quot;Metro window Without the drop shadow&quot; /&gt;&lt;/p&gt;


&lt;p style=&quot;text-align: center;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-size: 8pt;&quot;&gt;Without the drop shadow&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8075/8398555504_6cf93d7b35_o.png&quot; alt=&quot;Metro window with the drop shadow&quot; /&gt;&lt;/p&gt;


&lt;p style=&quot;text-align: center;&quot;&gt;&lt;em&gt;&lt;span style=&quot;font-size: 8pt;&quot;&gt;With the drop shadow&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;There is a problem here though. If the user goes to System Properties, Performance Options and uncheck the &amp;quot;Show shadows under windows&amp;quot; checkbox, the shadow will not be visible.&lt;/p&gt;


&lt;p&gt;&lt;span style=&quot;text-decoration: underline;&quot;&gt;The Zune software still keeps it&amp;#39;s drop shadow visible even if the &amp;quot;Show shadows under windows&amp;quot; checkbox is unchecked.&lt;/span&gt;&amp;#0160;&lt;/p&gt;


&lt;p&gt;&lt;em&gt;&amp;#0160;&amp;#0160;&amp;#0160;&amp;#0160;How can this possibly be? &lt;/em&gt;&lt;/p&gt;


&lt;p&gt;Well, the Zune software does not use the DWM API to place drop shadows. Instead, it uses four external, transparent, windows on each size to create an illusion of a drop shadow. The drop shadow is actually &amp;quot;composed&amp;quot; by four transparent windows on each side.&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8192/8398555496_21ef88e090_o.png&quot; alt=&quot;The drop shadows as they are composed by four transparent windows on each side&quot; /&gt;&lt;/p&gt;


&lt;p&gt;The second way, of placing the drop shadows, via external windows is the main reason for this post.&lt;/p&gt;

&lt;p&gt;Here is what I had to do:&lt;/p&gt;


&lt;ol&gt;
&lt;li&gt;Create a transparent window in code (and also set it&amp;#39;s background).&lt;/li&gt;
&lt;li&gt;Find the Main Window position on screen. Fortunately I could access the Left and Top properties and by it&amp;#39;s width and height I could calculate the window boundary.&lt;/li&gt;
&lt;li&gt;Calculate position for each external window.&lt;/li&gt;
&lt;li&gt;When moving the Main Window the external windows had to &amp;quot;glue&amp;quot; or better &amp;quot;dock&amp;quot; with the Main Window.&lt;/li&gt;
&lt;li&gt;When resizing the Main Window the external windows had to resize as well, according to the Main Window size.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;..Sounds like a lot of work to do for displaying a drop shadow that remains visible even if the user&amp;#0160;unchecks the &amp;quot;Show shadows under windows&amp;quot; checkbox!&lt;/p&gt;


&lt;p&gt;Creating the transparent window in code was easy:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;/// &amp;lt;summary&amp;gt;
/// Initializes the surrounding windows.
/// &amp;lt;/summary&amp;gt;
private void InitializeSurrounds()
{
    // Top.
    this.wndT = CreateTransparentWindow();
 
    // Left.
    this.wndL = CreateTransparentWindow();
 
    // Bottom.
    this.wndB = CreateTransparentWindow();
 
    // Right.
    this.wndR = CreateTransparentWindow();
 
    SetSurroundShadows();
}
 
/// &amp;lt;summary&amp;gt;
/// Creates an empty window.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
private static Window CreateTransparentWindow()
{
    Window wnd             = new Window();
    wnd.AllowsTransparency = true;
    wnd.ShowInTaskbar      = false;
    wnd.WindowStyle        = WindowStyle.None;
    wnd.Background         = null;
 
    return wnd;
}
 
/// &amp;lt;summary&amp;gt;
/// Sets the artificial drop shadow.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;active&amp;quot;&amp;gt;if set to &amp;lt;c&amp;gt;true&amp;lt;/c&amp;gt; [active].&amp;lt;/param&amp;gt;
private void SetSurroundShadows(bool active = true)
{
    if (active)
    {
        double cornerRadius = 1.75;
 
        this.wndT.Content = GetDecorator(
            &amp;quot;Images/ACTIVESHADOWTOP.PNG&amp;quot;);
        this.wndL.Content = GetDecorator(
            &amp;quot;Images/ACTIVESHADOWLEFT.PNG&amp;quot;, cornerRadius);
        this.wndB.Content = GetDecorator(
            &amp;quot;Images/ACTIVESHADOWBOTTOM.PNG&amp;quot;);
        this.wndR.Content = GetDecorator(
            &amp;quot;Images/ACTIVESHADOWRIGHT.PNG&amp;quot;, cornerRadius);
    }
    else
    {
        this.wndT.Content = GetDecorator(
            &amp;quot;Images/INACTIVESHADOWTOP.PNG&amp;quot;);
        this.wndL.Content = GetDecorator(
            &amp;quot;Images/INACTIVESHADOWLEFT.PNG&amp;quot;);
        this.wndB.Content = GetDecorator(
            &amp;quot;Images/INACTIVESHADOWBOTTOM.PNG&amp;quot;);
        this.wndR.Content = GetDecorator(
            &amp;quot;Images/INACTIVESHADOWRIGHT.PNG&amp;quot;);
    }
}
 
[DebuggerStepThrough]
private Decorator GetDecorator(string imageUri, double radius = 0)
{
    Border border       = new Border();
    border.CornerRadius = new CornerRadius(radius);
    border.Background   = new ImageBrush(
        new BitmapImage(
            new Uri(BaseUriHelper.GetBaseUri(this),
                imageUri)));
 
    return border;
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Calculating the position, width and height for each external window was also not difficult:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;/// &amp;lt;summary&amp;gt;
/// Raises the &amp;lt;see cref=&amp;quot;FrameworkElement.Initialized&amp;quot;/&amp;gt; event.
/// This method is invoked whenever
/// &amp;lt;see cref=&amp;quot;FrameworkElement.IsInitialized&amp;quot;/&amp;gt;
/// is set to true internally.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;e&amp;quot;&amp;gt;The &amp;lt;see cref=&amp;quot;T:RoutedEventArgs&amp;quot;/&amp;gt;
/// that contains the event data.&amp;lt;/param&amp;gt;
protected override void OnInitialized(EventArgs e)
{
    // ...
 
    LocationChanged += HandleLocationChanged;
    SizeChanged     += HandleLocationChanged;
    StateChanged    += HandleWndStateChanged;
 
    InitializeSurrounds();
    ShowSurrounds();
 
    base.OnInitialized(e);
}
 
/// &amp;lt;summary&amp;gt;
/// Handles the location changed.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;sender&amp;quot;&amp;gt;The sender.&amp;lt;/param&amp;gt;
/// &amp;lt;param name=&amp;quot;e&amp;quot;&amp;gt;The &amp;lt;see cref=&amp;quot;System.EventArgs&amp;quot;/&amp;gt;
/// instance containing the event data.&amp;lt;/param&amp;gt;
private void HandleLocationChanged(object sender, EventArgs e)
{
    this.wndT.Left   = Left  - edgeWndSize;
    this.wndT.Top    = Top   - this.wndT.Height;
    this.wndT.Width  = Width + edgeWndSize * 2;
    this.wndT.Height = edgeWndSize;
 
    this.wndL.Left   = Left - this.wndL.Width;
    this.wndL.Top    = Top;
    this.wndL.Width  = edgeWndSize;
    this.wndL.Height = Height;
 
    this.wndB.Left   = Left  - edgeWndSize;
    this.wndB.Top    = Top   + Height;
    this.wndB.Width  = Width + edgeWndSize * 2;
    this.wndB.Height = edgeWndSize;
 
    this.wndR.Left   = Left + Width;
    this.wndR.Top    = Top;
    this.wndR.Width  = edgeWndSize;
    this.wndR.Height = Height;
}
 
/// &amp;lt;summary&amp;gt;
/// Handles the windows state changed.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;sender&amp;quot;&amp;gt;The sender.&amp;lt;/param&amp;gt;
/// &amp;lt;param name=&amp;quot;e&amp;quot;&amp;gt;The &amp;lt;see cref=&amp;quot;System.EventArgs&amp;quot;/&amp;gt;
/// instance containing the event data.&amp;lt;/param&amp;gt;
private void HandleWndStateChanged(object sender, EventArgs e)
{
    if (WindowState == WindowState.Normal)
    {
        ShowSurrounds();
    }
    else
    {
        HideSurrounds();
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8225/8398555440_33b04b6bea_o.png&quot; alt=&quot;The final result as composed by four transparent windows on each side&quot; /&gt;&lt;/p&gt;




&lt;p&gt;I hope you find this post useful, there is a lot of information around but I think this post connects the pieces.&lt;/p&gt;


&lt;p&gt;The &lt;a href=&quot;https://github.com/moodmosaic/BonusBits.CodeSamples/tree/master/BonusBits.CodeSamples.MetroUI&quot; target=&quot;_blank&quot; title=&quot;BonusBits Blog source-code for Windows Presentation Foundation&quot;&gt;solution&lt;/a&gt; contains two projects. The first one uses the 1st method for displaying the drop shadow. The second one uses the method described above.&lt;/p&gt;


&lt;p&gt;Due to popular demand, you can download the sample projects &lt;a href=&quot;https://github.com/downloads/moodmosaic/BonusBits.CodeSamples/MetroUI-1.zip&quot; target=&quot;_blank&quot; title=&quot;MetroUI Sample 1&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;https://github.com/downloads/moodmosaic/BonusBits.CodeSamples/MetroUI-2.zip&quot; target=&quot;_blank&quot; title=&quot;MetroUI Sample 2&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=5962224&quot; rel=&quot;tag&quot; style=&quot;display: none;&quot;&gt;CodeProject&lt;/a&gt;&lt;/p&gt;



</description>
			<pubDate>Wed, 01 Dec 2010 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>SingleInstance(Of T) Class for Windows Phone 7</title>
			<link>http://nikosbaxevanis.com/2010/11/20/singleinstance-of-t-class-for-windows-phone-7</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/11/20/singleinstance-of-t-class-for-windows-phone-7</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;When building applications for&amp;nbsp;a mobile operating system such as Windows Phone 7 (WP7) you might want (at times) to defer the creation of large objects, &amp;nbsp;specifically when this creation is going to increase memory consumption.&lt;/p&gt;

&lt;p&gt;While in the desktop CLR there is the &lt;a title=&quot;Provides support for lazy initialization.&quot; href=&quot;http://msdn.microsoft.com/en-us/library/dd642331.aspx&quot; target=&quot;_blank&quot;&gt;Lazy(Of T) Class&lt;/a&gt;, when working on WP7 this class does not exist (at least not at the time of this writing).&lt;/p&gt;

&lt;p&gt;I find it a very&amp;nbsp;repetitive task to manually produce a single instance object:&lt;/p&gt;


&lt;ol&gt;
&lt;li&gt;Make it's constructor private.&lt;/li&gt;
&lt;li&gt;Write the code for initialization.&lt;/li&gt;
&lt;li&gt;Provide a getter method that returns the one and only instance.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;While you can not avoid step 2, it is possible to create a generic class that produces step 1 and step 3. Then, from the class constructor, you can pass the code that creates the object using a &lt;a title=&quot;Encapsulates a method that has no parameters and returns a value of the type specified by the TResult parameter.&quot; href=&quot;http://msdn.microsoft.com/en-us/library/bb534960.aspx&quot; target=&quot;_blank&quot;&gt;Func(TResult) Delegate&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;


&lt;h2&gt;SingleInstance(Of T) Class&lt;/h2&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;using System;
using System.Threading;
 
internal sealed class SingleInstance&amp;lt;T&amp;gt; where T : class
{
    private readonly object  lockObj = new object();
    private readonly Func&amp;lt;T&amp;gt; @delegate;
    private bool isDelegateInvoked;
 
    private T @value;
 
    public SingleInstance()
        : this(() =&amp;gt; default(T)) { }
 
    public SingleInstance(Func&amp;lt;T&amp;gt; @delegate)
    {
        this.@delegate = @delegate;
    }
 
    public T Instance
    {
        get
        {
            if (!this.isDelegateInvoked)
            {
                T temp = this.@delegate();
                Interlocked.CompareExchange&amp;lt;T&amp;gt;(ref this.@value, temp, null);
 
                bool lockTaken = false;
 
                try
                {
                    // WP7 does not support the overload with the
                    // Boolean indicating if the lock was taken.
                    Monitor.Enter(this.lockObj); lockTaken = true;
 
                    this.isDelegateInvoked = true;
                }
                finally
                {
                    if (lockTaken) { Monitor.Exit(this.lockObj); }
                }
            }
 
            return this.@value;
        }
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;blockquote&gt;
&lt;p&gt;The code inside the &quot;T Instance&quot; public property&amp;nbsp;uses interlocked constructs to&amp;nbsp;produce a single T object. It has been discussed in the book CLR via C#, 3rd Edition, Microsoft Press, page&amp;nbsp;846.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;The SingleInstance(Of T) class has many differences from the &amp;nbsp;System.Lazy(Of T)&amp;nbsp;class in the desktop CLR.&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;The System.Lazy(Of T) class takes a&amp;nbsp;&lt;a title=&quot;Specifies how a System.Lazy(Of T) instance synchronizes access among multiple threads.&quot; href=&quot;http://msdn.microsoft.com/en-us/library/system.threading.lazythreadsafetymode.aspx&quot; target=&quot;_self&quot;&gt;LazyThreadSafetyMode&lt;/a&gt;&amp;nbsp;enumeration. This enumeration contains 3 members (None, PublicationOnly, ExecutionAndPublication). The SingleInstance(Of T) class uses the interlocked constructs to produce a single instance. This is similar with passing LazyThreadSafetyMode.ExecutionAndPublication in the System.Lazy(Of T) class.&lt;/li&gt;
&lt;li&gt;The System.Lazy(Of T) class works with classes (reference types) and structs (value types). The value types are boxed internally. The SingleInstance(Of T) class works only with reference types.&lt;/li&gt;
&lt;li&gt;Finally, the System.Lazy(Of T) class is written, tested and supported by Microsoft, while the SingleInstance(Of T) is not.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Keep in mind that the SingleInstance(Of T)&amp;nbsp;class uses a&amp;nbsp;Func(TResult) Delegate.&amp;nbsp;There is a known performance hit when calling delegates compared to direct method calls. (See the Delegates section &lt;a title=&quot;Writing Faster Managed Code: Know What Things Cost by Jan Gray.&quot; href=&quot;http://msdn.microsoft.com/en-us/library/ms973852.aspx&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;).&lt;/p&gt;



</description>
			<pubDate>Sat, 20 Nov 2010 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Going Asynchronous with Sterling for Windows Phone 7</title>
			<link>http://nikosbaxevanis.com/2010/11/13/going-asynchronous-with-sterling-for-windows-phone-7</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/11/13/going-asynchronous-with-sterling-for-windows-phone-7</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;blockquote&gt;
&lt;p&gt;In this post I discuss about the various programming models that can be used with Sterling Isolated Storage Database for Windows Phone 7. Further, I discuss how one can benefit from the Power Threading Library when using Sterling.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8376/8398554602_56f1f5bce8_o.png&quot; alt=&quot;Extension methods for the ISterlingDatabaseInstance interface&quot; /&gt;&lt;/p&gt;




&lt;p&gt;I have &lt;a href=&quot;http://www.nikosbaxevanis.com/bonus-bits/2010/11/testing-domain-driven-design-with-sterling-for-windows-phone-7.html&quot; target=&quot;_blank&quot; title=&quot;Testing Domain-Driven Design with Sterling for Windows Phone 7.&quot;&gt;already discussed&lt;/a&gt; about the basics of Sterling Isolated Storage Database (Sterling)&amp;#0160;when building application for Windows Phone 7 (WP7). At times you might want to do some operation on the background while your code executes something else.&lt;/p&gt;


&lt;p&gt;Sterling supports the&amp;#0160;Event-based Asynchronous Pattern (EAP) which means you can write the following code against the&amp;#0160;&lt;a href=&quot;http://sterling.codeplex.com/SourceControl/changeset/view/68865#1253296&quot; target=&quot;_blank&quot; title=&quot;Wintellect.Sterling.ISterlingDatabaseInstance&quot;&gt;ISterlingDatabaseInstance&lt;/a&gt; interface:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;private void ExecuteWithEventBased()
{
    IList&amp;lt;Cargo&amp;gt; cargos = new List&amp;lt;Cargo&amp;gt;();
    for (int n = 0; n &amp;lt; iterations; n++)
    {
        Cargo cargo = CargoFactory.CreateNew(&amp;quot;Glyfada&amp;quot; + n, &amp;quot;Perachora&amp;quot; + n);
        cargos.Add(cargo);
    }
 
    var bw = App.Database.SaveAsync&amp;lt;Cargo&amp;gt;(cargos);
    bw.RunWorkerCompleted += (sender, e) =&amp;gt; {
        SetStatus(&amp;quot;Event-based completed.&amp;quot;, StatusState.Ready); };
 
    bw.RunWorkerAsync();
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;I can imagine, the reason the EAP is implemented is because you can have progress notification while the I/O executes in the background and also for handling the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.threading.synchronizationcontext.aspx&quot; target=&quot;_blank&quot; title=&quot;Provides the basic functionality for propagating a synchronization context in various synchronization models.&quot;&gt;SynchronizationContext&lt;/a&gt;&amp;#0160;and/or the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.aspx&quot; target=&quot;_blank&quot; title=&quot;Provides services for managing the queue of work items for a thread.&quot;&gt;Dispatcher&lt;/a&gt;&amp;#0160;internally.&lt;/p&gt;


&lt;p&gt;In my applications, I prefer to use the&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/magazine/cc163467.aspx&quot; target=&quot;_blank&quot; title=&quot;Implementing the CLR Asynchronous Programming Model by Jeffrey Richter.&quot;&gt;IAsyncResult&lt;/a&gt;, the CLR’s Asynchronous Programming Model (APM). For that reason, I wrote some extension methods for the ISterlingDatabaseInstance interface that allows you to use the APM when working with Sterling.&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8324/8398554702_77b7df68b4_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;Power Threading library comes with an implementation of the IAsyncResult interface, so one can take a method that executes synchronously and implement the APM. In the code above you can see the APM for the&amp;#0160;&lt;span style=&quot;font-family: Consolas; font-size: 13px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt; Save&amp;lt;T&amp;gt;(T instance) &lt;span style=&quot;color: blue;&quot;&gt;where&lt;/span&gt; T : &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;();&amp;#0160;&lt;/span&gt;method in ISterlingDatabaseInstance interface.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;/// &amp;lt;summary&amp;gt;
/// Asynchronous version of ISterlingDatabaseInstance Save method (Begin part).
/// &amp;lt;/summary&amp;gt;
public static IAsyncResult BeginSave&amp;lt;T&amp;gt;(
    this ISterlingDatabaseInstance sterling,
    T instance,
    AsyncCallback callback,
    object state) where T : class, new()
{
    // Create IAsyncResult object identifying the asynchronous operation.
    AsyncResult ar = new AsyncResult(callback, state);
 
    // Use a thread pool thread to perform the operation.
    ThreadPool.QueueUserWorkItem((obj) =&amp;gt;
    {
        var asyncResult = (AsyncResult)obj;
        try
        {
            // Perform the operation.
            sterling.Save&amp;lt;T&amp;gt;(instance);
            asyncResult.SetAsCompleted(null, false);
        }
        catch (Exception e)
        {
            // If operation fails, set the exception.
            asyncResult.SetAsCompleted(e, false);
        }
    }, ar);
 
    return ar; // Return the IAsyncResult to the caller.
}
 
///&amp;lt;summary&amp;gt;
/// Asynchronous version of ISterlingDatabaseInstance Save method (End part).
/// &amp;lt;/summary&amp;gt;
public static void EndSave(
    this ISterlingDatabaseInstance instance,
    IAsyncResult asyncResult)
{
    AsyncResult ar = (AsyncResult)asyncResult;
    ar.EndInvoke();
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;blockquote&gt;
&lt;p&gt;AsyncResult class resides in the PowerThreading library. It is written by Jeffrey Richter and can be obtained from the&amp;#0160;&lt;a href=&quot;http://www.wintellect.com/&quot; target=&quot;_blank&quot; title=&quot;Wintellect is a nationally recognized consulting, training and debugging firm dedicated to helping companies build better software, faster through a concentration on .NET and Windows technologies.&quot;&gt;Wintellect&lt;/a&gt;&amp;#0160;website.&amp;#0160;&lt;/p&gt;
&lt;p&gt;Sterling Isolated Storage Database can be obtained from the &lt;a href=&quot;http://sterling.codeplex.com/&quot; target=&quot;_blank&quot; title=&quot;Sterling Isolated Storage Database with LINQ for Silverlight and Windows Phone 7.&quot;&gt;CodePlex&lt;/a&gt; website.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;Armed with the above extension method you can write the following code which combines the APM implementation with the &lt;a href=&quot;http://msdn.microsoft.com/en-gb/magazine/cc546608.aspx&quot; target=&quot;_blank&quot; title=&quot;Simplified APM With The AsyncEnumerator by Jeffrey Richter.&quot;&gt;AsyncEnumerator&lt;/a&gt; class.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;// Inside your method create an instance of an AsyncEnumerator class,
// specifying the iterator method to be driven by the AsyncEnumerator.
AsyncEnumerator ae = new AsyncEnumerator();
ae.BeginExecute(ExecuteWithAsyncEnumerator(ae), ae.EndExecute, null);

private IEnumerator&amp;lt;int&amp;gt; ExecuteWithAsyncEnumerator(AsyncEnumerator ae)
{
    for (int n = 0; n &amp;lt; iterations; n++)
    {
        Cargo cargo = CargoFactory.CreateNew(&amp;quot;Glyfada&amp;quot; + n, &amp;quot;Perachora&amp;quot; + n);
        App.Database.BeginSave&amp;lt;Cargo&amp;gt;(cargo, ae.End(), null);
    }
 
    // AsyncEnumerator captures the calling thread's SynchronizationContext.
    // Set the SyncContext to null so that the callback continues
    // on a ThreadPool thread.
    ae.SyncContext = null;
 
    yield return iterations;
 
    for (Int32 n = 0; n &amp;lt; iterations; n++)
    {
        App.Database.EndSave(ae.DequeueAsyncResult());
    }
 
    // AsyncEnumerator captures the synchronization context.
    SetStatus(&amp;quot;AsyncEnumerator completed.&amp;quot;, StatusState.Ready);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;The sample Windows Phone 7 application can be found &lt;a href=&quot;https://github.com/moodmosaic/BonusBits.CodeSamples&quot; target=&quot;_blank&quot; title=&quot;BonusBits Blog source-code.&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;



</description>
			<pubDate>Sat, 13 Nov 2010 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Testing Domain-Driven Design with Sterling for Windows Phone 7</title>
			<link>http://nikosbaxevanis.com/2010/11/10/testing-domain-driven-design-with-sterling-for-windows-phone-7</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/11/10/testing-domain-driven-design-with-sterling-for-windows-phone-7</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8084/8397459857_48e3dfb8a6_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;When building applications targeting the Windows Phone 7 (WP7) you often need to create and maintain any kind of data. And while (for security reasons we all understand)&amp;#0160;you can&amp;#39;t access the local&amp;#0160;file system, you can benefit from the&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ff402541(VS.92).aspx&quot; target=&quot;_blank&quot; title=&quot;Isolated Storage Overview for Windows Phone.&quot;&gt;Isolated Storage&lt;/a&gt;. It&amp;#39;s API is similar with the one exposed in the Silverlight namespace.&amp;#0160;&lt;/p&gt;


&lt;p&gt;A good design of a&amp;#0160;&lt;a href=&quot;http://en.wikipedia.org/wiki/Domain_model&quot; target=&quot;_blank&quot; title=&quot;A domain model, or Domain Object Model (DOM) in problem solving and software engineering can be thought of as a conceptual model of a domain of interest (often referred to as a problem domain) which describes the various entities, their attributes and relationships, plus the constraints that govern the integrity of the model elements comprising that problem domain.&quot;&gt;Domain model&lt;/a&gt;&amp;#0160;knows nothing about persistence. You can use an in-memory database, a relational database, or ..&lt;strong&gt;&amp;quot;&lt;strong&gt;an&amp;#0160;Object-Oriented Database&amp;#0160;for WP7 that works with Isolated Storage classes and&amp;#0160;supports full LINQ to Object queries over keys and indexes for fast retrieval of information from large data sets!&lt;/strong&gt;&amp;quot;&amp;#0160;&lt;/strong&gt;Enter&amp;#0160;&lt;a href=&quot;http://sterling.codeplex.com/&quot; target=&quot;_blank&quot; title=&quot;Sterling is a lightweight object-oriented database implementation for Silverlight and Windows Phone 7 that works with your existing class structures. Sterling supports full LINQ to Object queries over keys and indexes for fast retrieval of information from large data sets.&quot;&gt;Sterling&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Here is a sample repository implementation using Sterling to store and retrieve data:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;internal class SterlingRepository&amp;lt;T&amp;gt; where T: class, new()
{
    public void Save(T instance)
    {
        App.Database.Save&amp;lt;T&amp;gt;(instance);
    }
 
    public T LoadById&amp;lt;TKey&amp;gt;(TKey id) where TKey : class
    {
        var query = App.Database.Query&amp;lt;T, TKey&amp;gt;()
                                .Where((table) =&amp;gt; table.Key == id)
                                .FirstOrDefault();
 
        return query.LazyValue.Value ?? default(T);
    }
 
    public ICollection&amp;lt;T&amp;gt; FindAll&amp;lt;TKey&amp;gt;()
    {
        var items = App.Database.Query&amp;lt;T, TKey&amp;gt;()
                                .Select((table) =&amp;gt; table.LazyValue.Value)
                                .ToList&amp;lt;T&amp;gt;();
        return items;
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;blockquote&gt;
&lt;p&gt;In the sample application I use the domain&amp;#0160;model based on the cargo example used in&amp;#0160;&lt;a href=&quot;http://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1238687848&amp;amp;sr=8-1&quot; target=&quot;_blank&quot; title=&quot;http://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215/&quot;&gt;Eric Evans&amp;#39; book&lt;/a&gt;&amp;#0160;which can be found&amp;#0160;&lt;a href=&quot;http://dddsamplenet.codeplex.com/&quot; target=&quot;_blank&quot; title=&quot;A .NET implementation of Domain Driven Design (DDD) sample application based on Eric Evans&amp;#39; examples included in his great book. Project is intended to be used in training, demonstration and experiments.&quot;&gt;here&lt;/a&gt;.&amp;#0160;&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h2&gt;CargoRepository&lt;/h2&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;internal sealed class CargoRepository : 
    SterlingRepository&amp;lt;Cargo&amp;gt;, ICargoRepository
{

    public void Store(Cargo cargo)
    {
        Save(cargo);
    }
 
    public Cargo Find(TrackingId trackingId)
    {
        return LoadById(trackingId.IdString);
    }
 
    public ICollection&amp;lt;Cargo&amp;gt; FindAll()
    {
        return FindAll&amp;lt;string&amp;gt;();
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;h2&gt;CargoFactory&lt;/h2&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;internal static class CargoFactory
{
    public static Cargo CreateNew(string origin, string destination)
    {
        // Method implementation can be found in the sample application.
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Armed with the above classes you can create a Cargo, save it using the CargoRepository and load it. Sterling will save the whole object graph and when you load, it will &amp;#0160;defer the creation of the whole object using the&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/dd642331.aspx&quot; target=&quot;_blank&quot; title=&quot;http://msdn.microsoft.com/en-us/library/dd642331.aspx&quot;&gt;Lazy&amp;lt;T&amp;gt;&lt;/a&gt; class.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public sealed class CargoPageViewModel : PropertyChangedBase
{
    private readonly ICargoRepository repository;
 
    public SterlingPageViewModel(ICargoRepository repository)
    {
        this.repository = repository;
    }
 
    public void StoreAndFind()
    {
        Cargo cargo = CargoFactory.CreateNew(&amp;quot;Glyfada&amp;quot;, &amp;quot;Perachora&amp;quot;);
        this.repository.Store(cargo);
 
        Cargo saved = this.repository.Find(cargo.TrackingId);
 
        Debug.Assert(cargo.RouteSpecification.Equals(saved.RouteSpecification));
        Debug.Assert(cargo.Delivery.Equals(saved.Delivery));
        Debug.Assert(cargo.Equals(saved));
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Your domain model classes can be&amp;#0160;&lt;a href=&quot;http://en.wikipedia.org/wiki/Plain_Old_CLR_Object&quot; target=&quot;_blank&quot; title=&quot;Plain Old CLR Object or POCO is a play on the term POJO, from the Java EE programming world, and is used by developers targeting the Common Language Runtime of the .NET Framework.&quot;&gt;POCOs&lt;/a&gt;. That is, you don&amp;#39;t have to inherit from anything in order to persist an instance of a type in the database. It just works!&lt;/p&gt;


&lt;p&gt;The documentation can be found &lt;a href=&quot;http://sterling.codeplex.com/documentation&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. The sample application can be found &lt;a href=&quot;https://github.com/moodmosaic/BonusBits.CodeSamples&quot; target=&quot;_blank&quot; title=&quot;BonusBits Blog source-code.&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
			<pubDate>Wed, 10 Nov 2010 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>Using Reflection to Dynamically Invoke the NHibernate Profiler</title>
			<link>http://nikosbaxevanis.com/2010/11/03/using-reflection-to-dynamically-invoke-the-nhibernate-profiler</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/11/03/using-reflection-to-dynamically-invoke-the-nhibernate-profiler</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;If you are using NHibernate&amp;#0160;as your Object-relational mapping (ORM) solution, then chances are you are also using the &lt;a href=&quot;http://nhprof.com&quot; target=&quot;_blank&quot; title=&quot;NHibernate Profiler is a real-time visual debugger allowing a development team to gain valuable insight and perspective into their usage of NHibernate. The product is architected with input coming from many top industry leaders within the NHibernate community.&quot;&gt;NHibernate Profiler&lt;/a&gt;. You can see the exact SQL queries sent to the database and also detect&amp;#0160;&lt;a href=&quot;http://nhprof.com/Learn/Alerts&quot; target=&quot;_blank&quot; title=&quot;Alerts are presented in a concise code-review manner indicating patterns of misuse by your application.&quot;&gt;common pitfalls&lt;/a&gt;, among others.&lt;/p&gt;


&lt;p&gt;NHibernate Profiler&amp;#0160;is developed by Hibernating Rhinos and&amp;#0160;Blue Spire Consulting, Inc. The &lt;a href=&quot;http://nhprof.com/About&quot; target=&quot;_blank&quot; title=&quot;The NHibernate Profiler was developed by Hibernating Rhinos. The user interface was built by Blue Spire Consulting, Inc.&quot;&gt;main contributers&lt;/a&gt; behind this tool are Oren Eini (NHibernate, Castle Project, RavenDB), Christopher Bennage (Sams Teach Yourself WPF in 24 Hours) and Rob Eisenberg (Sams Teach Yourself WPF in 24 Hours, Caliburn, Caliburn Micro). As you can see, this tool is not only interesting for what it does, but it has also interesting people behind it.&lt;/p&gt;


&lt;p&gt;Using the NHibernate Profiler in your application is very easy:&lt;/p&gt;


&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Add a reference&lt;/strong&gt; to HibernatingRhinos.Profiler.Appender.dll assembly.&lt;/li&gt;
&lt;li&gt;Invoke the NHibernateProfiler.Initialize method from your code.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;The problem is, you (might) need to remove the referenced assembly&amp;#0160;every time you ship. Even if you decide to keep it, you need to invoke the Initialize method from your code inside a method marked with the&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.diagnostics.conditionalattribute.aspx&quot; target=&quot;_blank&quot; title=&quot;Indicates to compilers that a method call or attribute should be ignored unless a specified conditional compilation symbol is defined.&quot;&gt;ConditionalAttribute&lt;/a&gt;&amp;#0160;class so the compiler ignores it unless you are running in debug mode.&lt;/p&gt;


&lt;p&gt;You can avoid adding a reference (step 1), and invoke the Initialize method dynamically&amp;#0160;using reflection:&lt;/p&gt;


&lt;p&gt;1. In the&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa903313(VS.71).aspx&quot; target=&quot;_blank&quot; title=&quot;Contains custom application settings. This is a predefined configuration section provided by the .NET Framework.&quot;&gt;&amp;lt;appSettings&amp;gt;&lt;/a&gt; element include the following keys:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='xml'&gt;&amp;lt;appSettings&amp;gt;
    &amp;lt;add key=&amp;quot;NHibernate_ProfilerAssembly&amp;quot;
         value=&amp;quot;HibernatingRhinos.Profiler.Appender.dll&amp;quot;/&amp;gt;
    &amp;lt;add key=&amp;quot;NHibernate_ProfilerDirectory&amp;quot;
         value=&amp;quot;&amp;lt;your_path&amp;gt;&amp;quot;/&amp;gt;
    &amp;lt;add key=&amp;quot;NHibernate_ProfilerMethod&amp;quot;
         value=&amp;quot;Initialize&amp;quot;/&amp;gt;
    &amp;lt;add key=&amp;quot;NHibernate_ProfilerType&amp;quot;
         value=&amp;quot;NHibernateProfiler&amp;quot;/&amp;gt;
&amp;lt;/appSettings&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;2. For housekeeping you can define an interface.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public interface IIntegrateProfiler
{
    void SetNHibernateProfiler(string directory, string assembly);
 
    bool CanUseProfiler { get; }
 
    string ProfilerPath { get; }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;3. Inside the&amp;#0160;your bootstrapper class, or the class where the&amp;#0160;&lt;a href=&quot;http://nhibernate.svn.sourceforge.net/viewvc/nhibernate/trunk/nhibernate/src/NHibernate/ISessionFactory.cs?revision=5259&amp;amp;view=markup&quot; target=&quot;_blank&quot; title=&quot;Usually an application has a single SessionFactory. Threads servicing client requests obtain ISession&amp;#39;s from the factory.&quot;&gt;ISessionFactory&lt;/a&gt;&amp;#0160;is built, implement the above interface.&lt;/p&gt;


&lt;blockquote&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;In the example below the ValidateDirectory and ValidateFileName methods are not included as well as the&amp;#0160;this.profilerPath &amp;#0160;private instance field.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public void SetNHibernateProfiler(string directory, string assembly)
{
    if (ValidateDirectory(directory))
    {
        string profilerPath = Path.Combine(directory, assembly);
 
        if (ValidateFileName(profilerPath))
        {
            this.profilerPath = profilerPath;
        }
        else
        {
            this.profilerPath = string.Empty;
        }
    }
}

public bool CanUseProfiler
{
    get { return !string.IsNullOrWhiteSpace(this.profilerPath); }
}
 
public string ProfilerPath
{
    get { return this.profilerPath; }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;4. Finally, from your code you can check whether the&amp;#0160;&lt;span style=&quot;font-family: Consolas; font-size: 13px;&quot;&gt;CanUseProfiler&amp;#0160;&lt;/span&gt;property returns true and call the&amp;#0160;&lt;span style=&quot;font-family: Consolas; font-size: 13px;&quot;&gt;InitializeProfiler&amp;#0160;&lt;/span&gt;method below:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;private void InitializeProfiler()
{
    Assembly asm  = Assembly.LoadFileLoadFrom(this.options.ProfilerPath);
    Type profiler = asm.GetExportedTypes().Where(x =&amp;gt; 
        x.Name == ConfigurationManager.AppSettings[&amp;quot;NHibernate_ProfilerType&amp;quot;])
            .FirstOrDefault();
 
     if (profiler != null)
     {
         MethodInfo initialize = profiler.GetMethods().Where(x =&amp;gt; 
           x.Name == ConfigurationManager
             .AppSettings[&amp;quot;NHibernate_ProfilerMethod&amp;quot;]).FirstOrDefault();
         if (initialize != null)
         {
             initialize.Invoke(null, null);
         }
     }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;blockquote&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;Actually, the same technique can be used for the other profilers too (&lt;a href=&quot;http://efprof.com/&quot; target=&quot;_blank&quot; title=&quot;Entity Framework Profiler is a real-time visual debugger allowing a development team to gain valuable insight and perspective into their usage of Entity Framework. The product is architected with input coming from many top industry leaders within the OR/M community.&quot;&gt;EFProf&lt;/a&gt;,&amp;#0160;&lt;a href=&quot;http://l2sprof.com/&quot; target=&quot;_blank&quot; title=&quot;Linq to Sql Profiler is a real-time visual debugger allowing a development team to gain valuable insight and perspective into their usage of Linq to Sql. The product is architected with input coming from many top industry leaders within the OR/M community.&quot;&gt;L2SProf&lt;/a&gt;, etc).&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;Don&amp;#39;t forget to remove the&amp;#0160;referenced assembly from your project.&lt;/p&gt;



</description>
			<pubDate>Wed, 03 Nov 2010 00:00:00 GTB Standard Time</pubDate>
		</item>
		
		<item>
			<title>The Task-based Asynchronous Pattern - Part 1 (The Basics)</title>
			<link>http://nikosbaxevanis.com/2010/10/31/the-task-based-asynchronous-pattern-part-1-the-basics</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/10/31/the-task-based-asynchronous-pattern-part-1-the-basics</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;blockquote&gt;
&lt;p&gt;The future of asynchronous programming in C# adheres to&amp;#0160;a new language feature and a new framework pattern.&amp;#0160;&lt;/p&gt;
&lt;p&gt;Asynchronous&amp;#0160;programming will be similar to synchronous programming.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;Today hosting in the cloud has become popular. You’re paying for each virtual machine (VM) that is running so your service must scale or else you have to pay for another VM to handle the load.&amp;#0160;&amp;#0160;Both the classic APM and the EAP require you to split your code in a callback function so many people even chose to write their code synchronous.&amp;#0160;No matter if you call a web service or access a file on disk (that is,&amp;#0160;I/O-Bound Asynchronous Operations) or if you want to compute PI (a Periodic Compute-Bound Operation) your&amp;#0160;application has to be scalable and responsive.&amp;#0160;&amp;#0160; &amp;#0160;&lt;/p&gt;


&lt;p&gt;I have&amp;#0160;&lt;a href=&quot;http://nikosbaxevanis.com/categories/Windows_Phone/&quot; target=&quot;_blank&quot; title=&quot;Exposing asynchronous features to client code.&quot;&gt;already&amp;#0160;discussed&lt;/a&gt;&amp;#0160;about the two patterns that are available in the .NET Framework for&amp;#0160;asynchronous&amp;#0160;programming.&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;Callback-based&amp;#0160;Asynchronous Pattern&amp;#0160;(APM)&lt;/li&gt;
&lt;li&gt;Event-based&amp;#0160;Asynchronous Pattern (EAP) &amp;#0160; &amp;#0160;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;I like the APM because with a good IAsyncResult implementation in hand you can easily expose&amp;#0160;asynchronous&amp;#0160;features to all versions of the .NET Framework (1.0-today) and also target Microsoft&amp;#0160;Silverlight, Windows Phone 7, etc.&amp;#0160;&lt;/p&gt;


&lt;p&gt;To start, here is some code that executes&amp;#0160;synchronously:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;private void FetchStockQuotesSync(WebService svc)
{
    // This blocks. You don't know when the FetchStockQuotes
    // method returns. It may takes from minutes, to hours or
    // it may not return at all.
    IStockQuote qt = svc.FetchStockQuotes();
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Fortunately the WebService class implements the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.iasyncresult.aspx&quot; target=&quot;_blank&quot; title=&quot;Represents the status of an asynchronous operation.&quot;&gt;IAsyncResult&lt;/a&gt; interface, so the same code can be executed asynchronously:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;private void FetchStockQuotesApm(WebService svc)
{
    // This never blocks. Your code returns immediately.
    svc.BeginFetchStockQuotes(FetchStockQuotesApmCallback, svc);
}
 
private void FetchStockQuotesApmCallback(IAsyncResult ar)
{
    // The operation completed asynchrnously.
    WebService svc = (WebService)ar.AsyncState;
    IStockQuote qt = svc.EndFetchStockQuotes(ar);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Event if the WebService class does not implement the IAsyncResult interface, you can define a delegate and invoke it&amp;#0160;asynchronously,&amp;#0160;via BeginInvoke.&lt;/p&gt;


&lt;blockquote&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;The following code below is here just for the demo.&amp;#0160;There is a known performance hit when calling delegates compared to direct method calls. (See the Delegates section &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms973852.aspx&quot; target=&quot;_blank&quot; title=&quot;Writing Faster Managed Code: Know What Things Cost by Jan Gray.&quot;&gt;here&lt;/a&gt;).&lt;/p&gt;
&lt;/blockquote&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;private void FetchStockQuotesApm(WebService svc)
{
    // This never blocks. Your code returns immediately.
    Func&amp;lt;IStockQuote&amp;gt; @delegate = svc.FetchStockQuotes;
    @delegate.BeginInvoke(FetchStockQuotesApmCallback, @delegate);
}
 
private void FetchStockQuotesApmCallback(IAsyncResult ar)
{
    // The operation completed asynchrnously.
    Func&amp;lt;IStockQuote&amp;gt; @delegate = (Func&amp;lt;IStockQuote&amp;gt;)ar.AsyncState;
    IStockQuote qt  = @delegate.EndInvoke(ar);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;blockquote&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;Unfortunately,&amp;#0160;it turns out that the APM does not look so sexy and most of the developers just don&amp;#39;t use it.&amp;#0160;&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;The future of asynchronous programming in C# adheres to a new framework pattern called the &lt;strong&gt;Task-based Asynchronous Pattern (TAP)&lt;/strong&gt;.
&lt;/p&gt;


&lt;p&gt;The new language features &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;await&lt;/code&gt; and the TAP allow you to do this:&lt;/p&gt;

&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;private async void FetchStockQuotesAsyncCtp(WebService svc)
{
    IStockQuote qt = await svc.FetchStockQuotesTaskAsync();
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Well, this is exciting. &amp;#0160;The method is marked as async. This means that the method body is compiled specially, allowing parts of&amp;#0160;it to be turned into callbacks.&amp;#0160;The FetchStockQuotesTaskAsync method returns a Task&amp;lt;IStockQuote&amp;gt; by converting the BeginFetchStockQuotes/EndFetchStockQuotes methods into a task. Until the task completes, there is nothing to do but await for it.&lt;/p&gt;


&lt;p&gt;Here is how the&amp;#0160;FetchStockQuotesTaskAsync method is written:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;public static Task&amp;lt;IStockQuote&amp;gt; FetchStockQuotesTaskAsync(this IWebService svc)
{
    return Task&amp;lt;IStockQuote&amp;gt;.Factory.FromAsync(
        svc.BeginFetchStockQuotes, // BeginPart
        svc.EndFetchStockQuotes,   // EndPart
        null);                     // State, Options
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;blockquote&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;FetchStockQuotesTaskAsync&amp;#0160;is an extension method, because adding this feature directly to the WebService class will break compatibility with previous versions of the .NET Framework (1.0, 1.1, 2.0). Also, if you don&amp;#39;t own the code of the WebService class you would define it as an extension method anyway.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;It becomes very clear that in the near future it&amp;#39;s the programming language that will handle most of the asynchronous stuff and not the programmer. Currently, you can download and install the &lt;a href=&quot;http://go.microsoft.com/fwlink/?LinkId=203690&quot; target=&quot;_blank&quot; title=&quot;Download a CTP with new syntax and APIs for asynchronous development.&quot;&gt;Async CTP&lt;/a&gt;. For more information around the new features you can visit the official website&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/vstudio/async.aspx&quot; target=&quot;_blank&quot; title=&quot;Asynchronous Programming for C# and Visual Basic&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;The sample application can be found &lt;a href=&quot;https://github.com/moodmosaic/BonusBits.CodeSamples&quot; target=&quot;_blank&quot; title=&quot;BonusBits Blog source-code.&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;



</description>
			<pubDate>Sun, 31 Oct 2010 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>An alternative (.NET 2.0) to the Task-based Asynchronous Pattern</title>
			<link>http://nikosbaxevanis.com/2010/10/31/an-alternative-net-2-0-approach-to-the-task-based-asynchronous-pattern</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/10/31/an-alternative-net-2-0-approach-to-the-task-based-asynchronous-pattern</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;blockquote&gt;
&lt;p&gt;Write code that looks like&amp;#0160;synchronous but actually executes&amp;#0160;asynchronously with the PowerThreading library and the AsyncEnumerator class.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;In the &lt;a href=&quot;http://nikosbaxevanis.com/2010/10/31/the-task-based-asynchronous-pattern-part-1-the-basics/&quot; target=&quot;_blank&quot; title=&quot;The Task-based Asynchronous Pattern - Part 1 (The Basics)&quot;&gt;previous post&lt;/a&gt; I discussed about the new language features that will help the developers write&amp;#0160;asynchronous&amp;#0160;code easily without having to split their flow in callback methods. In this post I want to show you an alternative way of doing this using the AsyncEnumerator class. This works for .NET 2.0+ and it is very similar with the upcoming features.&lt;/p&gt;


&lt;blockquote&gt;
&lt;p&gt;AsyncEnumerator class resides in the PowerThreading library. It is written by Jeffrey Richter and can be obtained from the&amp;#0160;&lt;a href=&quot;http://www.wintellect.com/&quot; target=&quot;_blank&quot; title=&quot;Wintellect is a nationally recognized consulting, training and debugging firm dedicated to helping companies build better software, faster through a concentration on .NET and Windows technologies.&quot;&gt;Wintellect&lt;/a&gt;&amp;#0160;website.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;I will start, again, with some code that executes&amp;#0160;synchronously:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;private void FetchStockQuotesSync(WebService svc)
{
    // This blocks. You don't know when the FetchStockQuotes
    // method returns. It may takes from minutes, to hours or
    // it may not return at all.
    IStockQuote qt = svc.FetchStockQuotes();
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Fortunately the WebService class implements the&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.iasyncresult.aspx&quot; target=&quot;_blank&quot; title=&quot;Represents the status of an asynchronous operation.&quot;&gt;IAsyncResult&lt;/a&gt;&amp;#0160;interface, so the same code can be executed asynchronously using the AsyncEnumerator class:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;// Inside your method create an instance of an AsyncEnumerator class,
// specifying the iterator method to be driven by the AsyncEnumerator.
AsyncEnumerator ae = new AsyncEnumerator();
ae.BeginExecute(GetStockQuotesAsyncEnumerator(ae, svc), ae.EndExecute);
 
private static IEnumerator&amp;lt;int&amp;gt; GetStockQuotesAsyncEnumerator(
    AsyncEnumerator ae, WebService svc)
{
    svc.BeginGetStockQuotes(ae.End(), null);
    yield return 1;
    IStockQuote qt = svc.EndGetStockQuotes(ae.DequeueAsyncResult());
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;This technique is similar to the &lt;a href=&quot;http://msdn.microsoft.com/en-us/vstudio/async.aspx&quot; target=&quot;_blank&quot; title=&quot;Async CTP&quot;&gt;new language features&lt;/a&gt; for asynchronous programming. In fact, what I&amp;#39;ve discussed works from .NET 2.0 up to any future version.&lt;/p&gt;


&lt;blockquote&gt;
&lt;p&gt;A very interesting&amp;#0160;topic regarding the AsyncEnumerator class and the Async CTP can be found at the PowerTheading &lt;a href=&quot;http://tech.groups.yahoo.com/group/PowerThreading/message/836&quot; target=&quot;_blank&quot; title=&quot;Where do you see AsyncEnumurator in regards to the Async CTP.&quot;&gt;discussion group&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;Until the Async CTP is shipped you can benefit from what already exists. I have been using the AsyncEnumerator class for quite a long time and I am very happy with it. However, the Async CTP looks promising but it would be very interesting to see some performance measurements in the future.&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=5962224&quot; rel=&quot;tag&quot; style=&quot;display: none;&quot;&gt;CodeProject&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;The sample application can be found &lt;a href=&quot;https://github.com/moodmosaic/BonusBits.CodeSamples&quot; target=&quot;_blank&quot; title=&quot;BonusBits Blog source-code.&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
			<pubDate>Sun, 31 Oct 2010 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>A pragmatic approach on open source software</title>
			<link>http://nikosbaxevanis.com/2010/10/27/a-pragmatic-approach-on-open-source-software</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/10/27/a-pragmatic-approach-on-open-source-software</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Using a product because you can view or modify the source code is not the point. It is like watching a movie that is split in 2 parts (or 2 disks) and you are in the beginning of the first one. Can you guess the ending yet? (Only if you are not watching it for the first time). Some people are&amp;#0160;&lt;a href=&quot;http://en.wikipedia.org/wiki/Cinephilia&quot; target=&quot;_blank&quot; title=&quot;Cinephilia is the term used to refer to a passionate interest in cinema, film theory and film criticism. The term is a portmanteau of the words cinema and philia, one of the four ancient Greek words for love.[1] A person with a passionate interest in cinema is called a cinephile.&quot;&gt;cinephile&lt;/a&gt;&amp;#0160;and can really guess a lot still from the&amp;#0160;beginning. But such kind of people are not the majority.&lt;/p&gt;


&lt;p&gt;The same applies when building a product. You need to be an experienced architect in order to choose the right tools from the beginning, trying to look as far as possible in the future to prevent drawbacks and bottlenecks.&lt;/p&gt;


&lt;p&gt;There are really too many kinds of combinations:&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;Those that don&amp;#39;t have a clue about open-source software, (period).&lt;/li&gt;
&lt;li&gt;Those that don&amp;#39;t have a clue about open-source software,&amp;#0160;but they are using it.&lt;/li&gt;
&lt;li&gt;Those that know what open-source software is, but don&amp;#39;t actually use it, maybe because they are retired, or whatever (I don&amp;#39;t want to be negative).&lt;/li&gt;
&lt;li&gt;Those that know what open-source software is, they use it, but they never modify it (the majority).&lt;/li&gt;
&lt;li&gt;Those that know what open-source software is, they use it, modify it, send patches (maybe they commit also).&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;From the above, if I run a company (&lt;a href=&quot;http://en.wikipedia.org/wiki/Independent_software_vendor&quot; target=&quot;_blank&quot; title=&quot;Independent software vendor (ISV) is a business term for companies specializing in making or selling software, designed for mass marketing or for niche markets.&quot;&gt;ISV&lt;/a&gt;) or if I was a manager in a large organization doing&amp;#0160;&lt;a href=&quot;http://en.wikipedia.org/wiki/Enterprise_software&quot; target=&quot;_blank&quot; title=&quot;Enterprise software, also known as enterprise application software (EAS), is software used in organizations, such as a business or government, as opposed to software chosen by individuals (for example, retail software).&quot;&gt;enterprise software&lt;/a&gt;,&amp;#0160;I would only chose to work with people from the last 2 bullets. Do you know why? Well let me give you an example: &lt;em&gt;What components do you need for an enterprise software using .NET?&lt;/em&gt;&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;AOP&lt;/li&gt;
&lt;li&gt;Caching&lt;/li&gt;
&lt;li&gt;Data Access&lt;/li&gt;
&lt;li&gt;DI&lt;/li&gt;
&lt;li&gt;Logging&lt;/li&gt;
&lt;li&gt;Policy&lt;/li&gt;
&lt;li&gt;Security&lt;/li&gt;
&lt;li&gt;Validation&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Ask now a few which tools they would use for the above? You will get answers like &amp;quot;NHibernate for Data Access&amp;quot; and &amp;quot;Castle Windsor or StructureMap for DI&amp;quot;. These are the most popular not to say the de facto.&amp;#0160;So, why bother writing your own ORM since you can use NHibernate, why bother writing your own DI container since you can use an existing (and mature) one?&lt;/p&gt;


&lt;p&gt;Let&amp;#39;s be pragmatic.&lt;/p&gt;


&lt;p&gt;Why we are getting paid? We are getting paid to deliver a responsive, scalable, working product. In order to achieve this we need to get&amp;#0160;equipped with the components mentioned above. Why not write our owns? Because (repeat) &amp;quot;we are getting paid to deliver a responsive, scalable, working product&amp;quot; we are not getting paid to build a specific reusable application block. But since we need to reuse as much code as possible we try to build around reusable application blocks.&amp;#0160;Why we are not using commercial (closed-source) products? Because if something fails in 02:00 AM we won&amp;#39;t have access to the source code? This is a false statement, in 02:00 AM even if you have access to the source, you have no brain to study it. Actually you may, even, need some time to to build from source and start debuggin.&amp;#0160;&lt;/p&gt;


&lt;blockquote&gt;
&lt;p&gt;Wake up at 02:00 AM and try to workaround on what I have&amp;#0160;&lt;a href=&quot;http://nikosbaxevanis.com/2010/10/20/adventures-using-rhino-servicebus/&quot; target=&quot;_blank&quot; title=&quot;Adventures using Rhino ServiceBus&quot;&gt;previously discussed&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;Let&amp;#39;s say though, you build the source, find the bug and fix it. Then what? You would send a patch and hope that it will be out with the next release. If not, then you need to maintain your local copy and keep it sync with the current public stable release.&amp;#0160;&lt;/p&gt;


&lt;p&gt;What happens if you don&amp;#39;t find the bug? Or don&amp;#39;t know how to fix it? Or you can&amp;#39;t get support in the forums? Do you know that there are companies out there selling commercial support for open-source software? Yes, you read it, commercial support for open-source software! What&amp;#39;s the difference with using a commercial product now?&amp;#0160;The difference is the community :-) It&amp;#39;s about the community of the open-source users, the culture, and knowledge sharing in forums, discussion groups and blogs. Yes, I buy this! But I don&amp;#39;t buy commercial support for an open-source product. If I had to chose this way, I would prefer to change career.&lt;/p&gt;



</description>
			<pubDate>Wed, 27 Oct 2010 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Knockout! MVVM with HTML + JavaScript</title>
			<link>http://nikosbaxevanis.com/2010/10/24/knockout-mvvm-with-html-javascript</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/10/24/knockout-mvvm-with-html-javascript</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;ul&gt;
&lt;li&gt;Download notepad2.&lt;/li&gt;
&lt;li&gt;Unzip, Run.&lt;/li&gt;
&lt;li&gt;Copy-paste the markup below.&lt;/li&gt;
&lt;li&gt;Save.&lt;/li&gt;
&lt;/ul&gt;


&lt;div&gt;
  &lt;pre&gt;&lt;code class='html'&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=utf-8&amp;quot; /&amp;gt;
    &amp;lt;script type=&amp;quot;text/javascript&amp;quot;
        src=&amp;quot;http://knockoutjs.com/js/knockout-2.1.0.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;
        In this example, the two text boxes are bound to
        &amp;lt;em&amp;gt;observable&amp;lt;/em&amp;gt; variables on a data model. The &amp;quot;full name&amp;quot;
        display is bound to a &amp;lt;em&amp;gt;dependent observable&amp;lt;/em&amp;gt;, whose value
        is computed in terms of the observables.&amp;lt;/p&amp;gt;
      &amp;lt;h2&amp;gt;
        Live example&amp;lt;/h2&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;p&amp;gt;
          First name:
          &amp;lt;input data-bind=&amp;quot;value: firstName&amp;quot; /&amp;gt;&amp;lt;/p&amp;gt;
        &amp;lt;p&amp;gt;
          Last name:
          &amp;lt;input data-bind=&amp;quot;value: lastName&amp;quot; /&amp;gt;&amp;lt;/p&amp;gt;
        &amp;lt;h2&amp;gt;
          Hello, &amp;lt;span data-bind=&amp;quot;text: fullName&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;!&amp;lt;/h2&amp;gt;
        &amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;
          var viewModel = {
            firstName: ko.observable(&amp;quot;&amp;quot;),
            lastName : ko.observable(&amp;quot;&amp;quot;)
          };
          viewModel.fullName = ko.dependentObservable(function () {
            return viewModel.firstName() + &amp;quot; &amp;quot; + viewModel.lastName();
          });
          ko.applyBindings(viewModel);
        &amp;lt;/script&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Don&amp;rsquo;t forget to visit the &lt;a href=&quot;http://knockoutjs.com/&quot; title=&quot;Knockout is a JavaScript library that helps you to create rich, responsive display and editor user interfaces with a clean underlying data model. Any time you have sections of UI that update dynamically (e.g., changing depending on the user’s actions or when an external data source changes), KO can help you implement it more simply and maintainably.&quot; target=&quot;_blank&quot;&gt;Knockout&lt;/a&gt; website.&lt;/p&gt;
</description>
			<pubDate>Sun, 24 Oct 2010 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Hosting Agatha in a Managed Application</title>
			<link>http://nikosbaxevanis.com/2010/10/23/hosting-agatha-in-a-managed-application</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/10/23/hosting-agatha-in-a-managed-application</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;When designing your &lt;a href=&quot;http://en.wikipedia.org/wiki/Enterprise_Service_Layer&quot; target=&quot;_blank&quot; title=&quot;The Enterprise Service Layer (ESL) is the highest level of abstraction in a SOA architecture.&quot;&gt;Service Layer&lt;/a&gt; you need to choose a communication mechanism according to your needs. Duplex, Fire and Forget, Reliable Sessions and &lt;a href=&quot;http://en.wikipedia.org/wiki/Request-response&quot; target=&quot;_blank&quot; title=&quot;Request-response, also known as request-reply, is a message exchange pattern in which a requestor sends a request message to a replier system which receives and processes the request, ultimately returning a message in response.&quot;&gt;Request Response&lt;/a&gt; are the most common messaging patterns.&lt;/p&gt;


&lt;p&gt;With Request-response, the client expects to receive a response for every message that&amp;#39;s been sent. You can design such a Service Layer using an &lt;a href=&quot;http://en.wikipedia.org/wiki/Enterprise_service_bus#ESB_architecture&quot; target=&quot;_blank&quot; title=&quot;In an enterprise architecture making use of an ESB, an application will communicate via the bus, which acts as a message broker between applications.&quot;&gt;ESB architecture&lt;/a&gt; if you need to connect different applications (even from different platforms). Though, if you need to write a typical client - back-end - database application you can choose not to go with an ESB (Rhino ServiceBus, NServiceBus) and use WCF.&lt;/p&gt;


&lt;blockquote&gt;
&lt;p&gt;When using NHibernate in an enterprise application the most common issue is how to automatically open and close a Session (per Request). With WCF you need to follow the steps described &lt;a href=&quot;http://igloocoder.com/archive/2008/07/21/nhibernate-on-wcf.aspx&quot; target=&quot;_blank&quot; title=&quot;NHibernate on WCF&quot;&gt;here&lt;/a&gt;. Also&amp;#0160;for each of your services you need to expose an&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa480190.aspx#introt_topic2&quot; target=&quot;_blank&quot; title=&quot;The mnemonic &amp;quot;ABC&amp;quot; can be used to remember Address / Binding / Contract.&quot;&gt;ABC&lt;/a&gt;&amp;#0160;via app.config.&amp;#0160;On the other hand using Rhino ServiceBus and NServiceBus makes your life a lot easier.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;Davy Brion mentions &lt;a href=&quot;http://davybrion.com/blog/2009/07/why-i-dislike-classic-or-typical-wcf-usage/&quot; target=&quot;_blank&quot; title=&quot;Why I Dislike Classic Or Typical WCF Usage.&quot;&gt;here&lt;/a&gt;&amp;#0160;with more detail what I&amp;#39;ve discussed above and he provides the &lt;a href=&quot;http://code.google.com/p/agatha-rrsl/&quot; target=&quot;_blank&quot; title=&quot;agatha-rrsl - Implementation of the Request/Response Service Layer for .NET.&quot;&gt;Agatha&lt;/a&gt; project. With it, you define &lt;a href=&quot;http://code.google.com/p/agatha-rrsl/source/browse/trunk/Agatha.ServiceLayer/RequestHandler.cs&quot; target=&quot;_blank&quot; title=&quot;Agatha.ServiceLayer.RequestHandler&quot;&gt;RequestHandlers&lt;/a&gt; (like &lt;a href=&quot;http://github.com/hibernating-rhinos/rhino-esb/blob/master/Rhino.ServiceBus/ConsumerOf.cs&quot; target=&quot;_blank&quot; title=&quot;Rhino.ServiceBus.ConsumerOf&amp;lt;T&amp;gt;&quot;&gt;Consumers&lt;/a&gt; in the ESB world) and Agatha infrastructure will handle the rest. Everything is done with a single endpoint which makes you forget about app.config and ABCs.&lt;/p&gt;


&lt;blockquote&gt;
&lt;p&gt;With Agatha NHibernate Session-per-Request is easy. You can use your favorite DI container and have a session provided through your handler&amp;#39;s constructor. You can even abstract the session by following the steps described &lt;a href=&quot;http://davybrion.com/blog/2009/12/using-nhibernate-in-your-service-layer/&quot; target=&quot;_blank&quot; title=&quot;Using NHibernate In Your Service Layer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;With Agatha, you can host your services easily on IIS or in a Console Application using &lt;a href=&quot;http://www.coretechnologies.com/products/AlwaysUp/&quot; target=&quot;_blank&quot; title=&quot;AlwaysUp runs your application (32/64-bit executable, batch file, shortcut, java, perl, etc.) as a Windows Service, managing and monitoring it constantly to ensure 100% uptime.&quot;&gt;AlwaysUp&lt;/a&gt;. If you choose the latter there are a few things to do inside your Main() method.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;Uri  baseAddress = new Uri(&amp;quot;&amp;lt;uriString goes here&amp;gt;&amp;quot;);
ServiceHost host = new ServiceHost(typeof(WcfRequestProcessor), baseAddress);
host.Open();
 
// Agatha's WcfRequestProcessor handles the requests.
// Your service is up. There is really nothing else to do here.

System.Console.ReadKey(false);
host.Close();&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Here I create an instance of the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.servicemodel.servicehost.aspx&quot; target=&quot;_blank&quot; title=&quot;Provides a host for services.&quot;&gt;ServiceHost&lt;/a&gt; class, passing a &lt;a href=&quot;http://code.google.com/p/agatha-rrsl/source/browse/trunk/Agatha.ServiceLayer/WCF/WcfRequestProcessor.cs&quot; target=&quot;_blank&quot; title=&quot;Agatha.ServiceLayer.WCF.WcfRequestProcessor&quot;&gt;WcfRequestProcessor&lt;/a&gt;&amp;#0160;type that represents the service type and the base address Uniform Resource Identifier (URI) to the ServiceHost.&lt;/p&gt;


&lt;p&gt;Here is the generic app.config that Agatha needs:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='xml'&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;
&amp;lt;configuration&amp;gt;
  &amp;lt;system.serviceModel&amp;gt;
    &amp;lt;services&amp;gt;
      &amp;lt;service name=&amp;quot;Agatha.ServiceLayer.WCF.WcfRequestProcessor&amp;quot;
               behaviorConfiguration=&amp;quot;RequestProcessorBehavior&amp;quot;&amp;gt;
        &amp;lt;endpoint address=&amp;quot;&amp;quot;
                  contract=&amp;quot;Agatha.Common.WCF.IWcfRequestProcessor&amp;quot;
                  binding=&amp;quot;basicHttpBinding&amp;quot;
                  bindingConfiguration=&amp;quot;RequestProcessorBinding&amp;quot;/&amp;gt;
      &amp;lt;/service&amp;gt;
    &amp;lt;/services&amp;gt;
    &amp;lt;bindings&amp;gt;
      &amp;lt;basicHttpBinding&amp;gt;
        &amp;lt;binding name=&amp;quot;RequestProcessorBinding&amp;quot;
                 maxReceivedMessageSize=&amp;quot;2147483647&amp;quot;
                 receiveTimeout=&amp;quot;00:30:00&amp;quot;
                 sendTimeout=&amp;quot;00:30:00&amp;quot;&amp;gt;
          &amp;lt;readerQuotas maxStringContentLength=&amp;quot;2147483647&amp;quot;
                        maxArrayLength=&amp;quot;2147483647&amp;quot;/&amp;gt;
          &amp;lt;security mode=&amp;quot;None&amp;quot; /&amp;gt;
        &amp;lt;/binding&amp;gt;
      &amp;lt;/basicHttpBinding&amp;gt;
    &amp;lt;/bindings&amp;gt;
    &amp;lt;behaviors&amp;gt;
      &amp;lt;serviceBehaviors&amp;gt;
        &amp;lt;behavior name=&amp;quot;RequestProcessorBehavior&amp;quot;&amp;gt;
          &amp;lt;serviceMetadata httpGetEnabled=&amp;quot;true&amp;quot;/&amp;gt;
          &amp;lt;serviceDebug includeExceptionDetailInFaults=&amp;quot;true&amp;quot;/&amp;gt;
          &amp;lt;dataContractSerializer maxItemsInObjectGraph=&amp;quot;2147483647&amp;quot;/&amp;gt;
          &amp;lt;serviceThrottling maxConcurrentCalls=&amp;quot;500&amp;quot;
                             maxConcurrentInstances=&amp;quot;500&amp;quot;/&amp;gt;
        &amp;lt;/behavior&amp;gt;
      &amp;lt;/serviceBehaviors&amp;gt;
    &amp;lt;/behaviors&amp;gt;
  &amp;lt;/system.serviceModel&amp;gt;
  &amp;lt;startup&amp;gt;
    &amp;lt;supportedRuntime version=&amp;quot;v4.0&amp;quot;
                      sku=&amp;quot;.NETFramework,Version=v4.0&amp;quot;/&amp;gt;
  &amp;lt;/startup&amp;gt;
  &amp;lt;runtime&amp;gt;
    &amp;lt;gcServer enabled=&amp;quot;true&amp;quot;/&amp;gt;
  &amp;lt;/runtime&amp;gt;
&amp;lt;/configuration&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;I included the&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms229357.aspx&quot; target=&quot;_blank&quot; title=&quot;Specifies whether the common language runtime runs server garbage collection.&quot;&gt;&amp;lt;gcServer&amp;gt;&lt;/a&gt;&amp;#0160;element to instruct CLR to use&amp;#0160;server garbage collection. Inside your Main() method you can include the code below:&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;Console.WriteLine(&amp;quot;{0} is {1}running with server GC.&amp;quot;,
    Assembly.GetEntryAssembly().GetName().Name,
    GCSettings.IsServerGC == true ? string.Empty : &amp;quot;not &amp;quot;);&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;I would really like to share how it looks in &lt;a href=&quot;http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx&quot; target=&quot;_blank&quot; title=&quot;Process Explorer by Mark Russinovich&quot;&gt;Process Explorer&lt;/a&gt; when handling 6000 requests using Agatha.&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8194/8397465885_bb9b3f236e_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;


&lt;p style=&quot;text-align: center;&quot;&gt;&lt;strong&gt;&amp;#0160;&lt;/strong&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;em&gt;Agatha 6000 request-response synchronous&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8366/8398554490_8d5c2ec5cd_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;


&lt;p style=&quot;text-align: center;&quot;&gt;&lt;strong&gt;&amp;#0160;&lt;/strong&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;em&gt;Agatha 6000 request-response asynchronous&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;


&lt;blockquote&gt;
&lt;p&gt;Why in the&amp;#0160;asynchronous case&amp;#0160;the memory consumption is a little higher? Well, this is something expected. Every asynchronous call creates an &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.iasyncresult.aspx&quot; target=&quot;_blank&quot; title=&quot;Represents the status of an asynchronous operation.&quot;&gt;IAsyncResult&lt;/a&gt; object. So even that the calls are non-blocking we have an overhead of 6000 IAsyncResult objects on the heap (yes, on the heap since they are not value types). Though, as you can see from the screenshot, when the GC &amp;#0160;kicks in the memory is reclaimed.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;Well that&amp;#39;s it! Agatha works great, it&amp;#39;s great, I really like it. Goodbye to the existing (and conservative, and painful) WCF usage.&lt;/p&gt;




&lt;p&gt;The sample application can be found &lt;a href=&quot;https://github.com/moodmosaic/BonusBits.CodeSamples&quot; target=&quot;_blank&quot; title=&quot;BonusBits Blog source-code.&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Make sure you are running the application with elevated priviledges else a System.ServiceModel.AddressAccessDeniedException will be thrown indicating that your process does not have access rights to get registered at the base address were your service is hosted.&lt;/p&gt;
</description>
			<pubDate>Sat, 23 Oct 2010 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Adventures using Rhino ServiceBus</title>
			<link>http://nikosbaxevanis.com/2010/10/20/adventures-using-rhino-servicebus</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/10/20/adventures-using-rhino-servicebus</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8513/8397467253_db8789c486_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;Recently, with the team I work,&amp;#0160;we tried&amp;#0160;&lt;a href=&quot;http://hibernatingrhinos.com/open-source/rhino-service-bus&quot; target=&quot;_blank&quot; title=&quot;A developer friendly service bus for .NET&quot;&gt;Rhino ServiceBus&lt;/a&gt;&amp;#0160;on a project. The fact that it has it&amp;#39;s own queuing subsystem&amp;#0160;&lt;a href=&quot;http://github.com/ayende/rhino-queues&quot; target=&quot;_blank&quot; title=&quot;An open source, Xcopy-deployed queuing subsystem.&quot;&gt;Rhino Queues&lt;/a&gt;&amp;#0160;(which requires no installation or administration) and it is integrated with the IoC container (we had already chosen for that project), Castle Windsor, made it a good candidate for spending some weeks trying it.&lt;/p&gt;


&lt;p&gt;While we were doing some sort of&amp;#0160;&lt;a href=&quot;http://en.wikipedia.org/wiki/Stress_testing&quot; target=&quot;_self&quot; title=&quot;Stress testing is a form of testing that is used to determine the stability of a given system or entity.&quot;&gt;stress testing&lt;/a&gt;&amp;#0160;(about 6000 requests), we noticed that&amp;#0160;the memory was increasing (like it does in a memory leak situation).&amp;#0160;&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8515/8397467157_129af3b874_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;Since the behavior was unexpected, we spent some time on ways to workaround it, incl. reading the source code, building with the latest and greatest.&amp;#0160;&lt;span style=&quot;text-decoration: line-through;&quot;&gt;My colleague,&lt;/span&gt; &lt;a href=&quot;http://open-voip.blogspot.com/&quot; target=&quot;_blank&quot; title=&quot;open-voip.blogspot.com is the single destination Blog for VOIP, IP Telephony, IPPBX, Open Souce voip, voip news and voip info based on voice over ip ...&quot;&gt;G. Nikolaropoulos&lt;/a&gt;,&amp;#0160;started also a &lt;a href=&quot;http://groups.google.com/group/rhino-tools-dev/browse_thread/thread/df8ce259df2cdd04&quot; target=&quot;_blank&quot; title=&quot;Memory Consumption of rhino-esb&quot;&gt;thread&lt;/a&gt;&amp;#0160;on the Rhino Tools Dev discussion group. We got feedback very fast:&amp;#0160;&lt;em&gt;the memory is held inside Rhino Queues, to avoid replying with the same message more than once&amp;#0160;in case of network loss. Every 3 minutes, Rhino Queues cleans the list up and memory is freed.&lt;/em&gt;&lt;/p&gt;


&lt;p&gt;We built a very basic sample application but we also tested the&amp;#0160;&lt;a href=&quot;http://github.com/ayende/alexandria&quot; target=&quot;_blank&quot; title=&quot;Sample netflix like application for books.&quot;&gt;article code&lt;/a&gt;&amp;#0160;that was&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/magazine/ff796225.aspx&quot; target=&quot;_blank&quot; title=&quot;Building Distributed Apps with NHibernate and Rhino Service Bus by Oren Eini.&quot;&gt;published&lt;/a&gt;&amp;#0160;on MSDN (there is also a&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/magazine/ff872394.aspx&quot; target=&quot;_blank&quot; title=&quot;Building Distributed Apps with NHibernate and Rhino Service Bus, Part 2 by Oren Eini&quot;&gt;second part&lt;/a&gt;). The behavior was the same even after 3 minutes wait (not to say worse).&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8330/8398555766_539fc0df48_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;We thought it should be fair to investigate even further and ask in person via E-mail. We got a reply fast, instructing that we should set the &lt;a href=&quot;http://en.wikipedia.org/wiki/Extensible_Storage_Engine&quot; target=&quot;_blank&quot; title=&quot;Extensible Storage Engine (ESE), also known as JET Blue, is an Indexed Sequential Access Method (ISAM) data storage technology from Microsoft.&quot;&gt;Extensible Storage Engine&lt;/a&gt; (ESE) CacheSizeMax parameter to 1024. Rhino Queues use ESE internally for message storage.&lt;/p&gt;


&lt;blockquote&gt;
&lt;p&gt;In the sample application which can be found on &lt;a href=&quot;https://github.com/moodmosaic/BonusBits.CodeSamples&quot; target=&quot;_blank&quot; title=&quot;BonusBits Blog source-code.&quot;&gt;here&lt;/a&gt;,&amp;#0160;I set the CacheSizeMax&amp;#0160;to 512.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;But what exactly is the CacheSizeMax parameter?&lt;/p&gt;




&lt;p&gt;Well, Rhino Queues uses &amp;#0160;the &lt;a href=&quot;http://managedesent.codeplex.com/&quot; target=&quot;_blank&quot; title=&quot;ManagedEsent provides managed access to ESENT, the embeddable database engine native to Windows. ManagedEsent uses the esent.dll that is part of Microsoft Windows so there are no extra unmanaged binaries to download and install.&quot;&gt;ManagedEsent&lt;/a&gt; library which provides managed access to ESE. I opened the library with Reflector and searched for the CacheSizeMax which is declared &amp;#0160;inside the JET_param enum.&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8491/8398555724_309f969cb5_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;&lt;span style=&quot;text-decoration: underline;&quot;&gt;Microsoft.Isam.Esent.Interop.JET_param, CacheSizeMax&lt;/span&gt;&amp;#0160;&lt;em&gt;This parameter configures the maximum size of the database page cache. The size is in database pages. If this parameter is left to its default value, then the maximum size of the cache will be set to the size of physical memory when JetInit is called.&amp;#0160;&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8500/8398555748_e1575041cd_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;Setting the Microsoft.Isam.Esent.Interop.SystemParameters.CacheSizeMax to 1024 or 512 seems to solve the problem with the increasing memory usage.&amp;#0160;The question is, if this call sets a global variable then it may have a negative impact to the rest applications using the ESE (ex. Microsoft Exchange).&lt;/p&gt;


&lt;p&gt;I decided to contact &lt;a href=&quot;http://blogs.msdn.com/b/laurionb/&quot; target=&quot;_blank&quot; title=&quot;ESE/ESENT Database Stuff&quot;&gt;Laurion Burchall&lt;/a&gt;, a Software Engineer on the ESE/ESENTteam, with my question.&amp;#0160;The answer: &lt;em&gt;The setting is per-process so it won’t cause problems with other applications that use ESENT.&amp;#0160;By default ESENT will automatically manage the cache size so you shouldn’t need to worry. We look at the amount of free memory on the system, the amount of paging activity and the amount of database I/O when deciding on the cache size. Although the cache is growing you should find that the system isn’t paging and that if you start using memory in other applications ESENT will actually shrink its cache.&lt;/em&gt;&lt;/p&gt;


&lt;p&gt;It is very easy to use and deploy with Rhino ServiceBus.&amp;#0160;If you are planning to use it, I hope you find this&amp;#0160;information&amp;#0160;useful.&lt;/p&gt;

</description>
			<pubDate>Wed, 20 Oct 2010 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Exposing asynchronous features to client code for Windows Phone 7</title>
			<link>http://nikosbaxevanis.com/2010/10/17/exposing-asynchronous-features-to-client-code-windows-phone-7</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/10/17/exposing-asynchronous-features-to-client-code-windows-phone-7</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Today, line of Internet and multimedia-enabled smartphones have become popular. Fortunately if you are a .NET developer&amp;#0160;you can use your existing skills and language and target some of the most popular &lt;a href=&quot;http://en.wikipedia.org/wiki/Mobile_operating_system&quot; target=&quot;_blank&quot; title=&quot;A mobile operating system, also known as a mobile OS, a mobile platform, or a handheld operating system, is the operating system that controls a mobile device.&quot;&gt;mobile operating systems&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Windows Phone 7 is a mobile operating system developed by Microsoft, and is the successor to their Windows Mobile platform.&amp;#0160;&lt;/p&gt;


&lt;p&gt;You can expose asynchronous features to client code using one of the following .NET Framework&amp;#39;s&amp;#0160;Asynchronous&amp;#0160;Programming Models:&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;IAsyncResult &lt;em&gt;The CLR’s Asynchronous Programming Model (APM)&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Event-based Asynchronous Pattern &lt;em&gt;(EAP)&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;IAsyncResult has been around since .NET 1.0 and has been used in most&amp;#0160;&lt;a href=&quot;http://en.wikipedia.org/wiki/Base_Class_Library&quot; target=&quot;_blank&quot; title=&quot;The Base Class Library (BCL) is a standard library available to all languages using the .NET Framework.&quot;&gt;BCL&lt;/a&gt; classes, while the main benefit of the EAP is that it integrates with the Visual Studio UI designers.&amp;#0160;You can learn how to properly implement the IAsyncResult interface (APM) from the excellent article on MSDN, &lt;em&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/magazine/cc163467.aspx&quot; target=&quot;_self&quot; title=&quot;Implementing the CLR Asynchronous Programming Model&quot;&gt;Implementing the CLR Asynchronous Programming Model&lt;/a&gt;&lt;/em&gt;, by Jeffrey Richter.&lt;/p&gt;


&lt;p&gt;In this post I will show you how easy it to use types implementing the IAsyncResult interface on Windows Phone 7. I will use the PowerThreading library because it provides a similar (not to say an improved) implementation of the one described in the original MSDN article. I will explain how to use it and how this becomes easier using the AsyncEnumerator class.&lt;/p&gt;


&lt;blockquote&gt;
&lt;p&gt;AsyncEnumerator class resides in the PowerThreading library. It is written by Jeffrey Richter and can be obtained from the &lt;a href=&quot;http://www.wintellect.com/&quot; target=&quot;_blank&quot; title=&quot;Wintellect is a nationally recognized consulting, training and debugging firm dedicated to helping companies build better software, faster through a concentration on .NET and Windows technologies.&quot;&gt;Wintellect&lt;/a&gt; website.&lt;/p&gt;
&lt;p&gt;The sample Windows Phone 7 application can be found &lt;a href=&quot;https://github.com/moodmosaic/BonusBits.CodeSamples&quot; target=&quot;_blank&quot; title=&quot;BonusBits Blog source-code.&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8497/8397466171_850dc3a0c9_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;h2&gt;Sync I/O&amp;#0160;pauses the UI&lt;/h2&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8217/8398554750_01c3311321_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;The code below shows how&amp;#0160;ExecuteWithSyncIO method is implemented. The application shows a MessageBox to the user that the UI will pause while the execution is in progress.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;private void ExecuteWithSyncIO()
{
    for (int n = 0; n &amp;lt; iterations; n++)
    {
        this.webService.GetStockQuotes();
    }
    SetStatus(&amp;quot;Sync/IO completed.&amp;quot;, StatusState.Ready);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;h2&gt;Delegate&amp;#39;s BeginInvoke method is not supported&lt;/h2&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8507/8397466099_216efe6f78_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;private void ExecuteWithDelegateBeginInvoke()
{
    Func&amp;lt;IStockQuote&amp;gt; stockQuoteDelegate = this.webService.GetStockQuotes;
    // NOTE: Calling delegates asynchronously is NOT supported in WP7.
    stockQuoteDelegate.BeginInvoke((ar) =&amp;gt;
    {
        stockQuoteDelegate.EndInvoke(ar);        
    }, null);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;The code below shows how ExecuteWithDelegateBeginInvoke method is implemented. &lt;/p&gt;


&lt;p&gt;This method is here just for the demo, since it is not allowed to invoke a delegate asynchronously in the Compact Framework.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;private void ExecuteWithDelegateBeginInvoke()
{
    Func&amp;lt;IStockQuote&amp;gt; stockQuoteDelegate = this.webService.GetStockQuotes;
    // NOTE: Calling delegates asynchronously is NOT supported in WP7.
    stockQuoteDelegate.BeginInvoke((ar) =&amp;gt;
    {
        stockQuoteDelegate.EndInvoke(ar);        
    }, null);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8085/8398554712_4190f00280_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;h2&gt;IAsyncResult interface&lt;/h2&gt;


&lt;p&gt;The code below shows how the ExecuteWithIAsyncResult method is implemented. The only problem is that, when using the IAsyncResult, you need to specify a method to be called when a corresponding asynchronous operation completes. This can result in using synchronization constructs to avoid race conditions. It also splits the flow of your code. You can inline the callback method using &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/0yw3tz5k(VS.80).aspx&quot; target=&quot;_blank&quot; title=&quot;In versions of C# previous to 2.0, the only way to declare a delegate was to use named methods. C# 2.0 introduces anonymous methods.&quot;&gt;Anonymous Methods&lt;/a&gt; or&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/bb397687.aspx&quot; target=&quot;_blank&quot; title=&quot;In the C# programming language a lambda expression is an anonymous function that can contain expressions and statements.&quot;&gt;Lamda Expressions&lt;/a&gt; as shown below but if your logic is complicated your code will not be beautiful.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;private void ExecuteWithIAsyncResult()
{
    SetStatus(&amp;quot;Working..&amp;quot;, StatusState.Busy);
 
    for (int n = 0; n &amp;lt; iterations; n++)
    {
        this.webService.BeginGetStockQuotes((ar) =&amp;gt;
        {
            // Callback method inlined using Lamda Expressions.

            // NOTE: Code can become ugly here, specially if you need to do 
            // a lot of stuff that touch properties bounded with UI elements.
            if (Interlocked.Increment(ref this.numDone) == iterations)
            {
                Execute.OnUIThread(() =&amp;gt;
                {
                    SetStatus(&amp;quot;IAsyncResult APM completed.&amp;quot;,
                        StatusState.Ready);
                });
            }
        }, null);
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;h2&gt;AsyncEnumerator class&lt;/h2&gt;


&lt;p&gt;The code below shows how&amp;#0160;ExecuteWithAsyncEnumerator method is implemented. As you can see this method makes your code looks like it&amp;#39;s executing synchronously but actually it executes asynchronously. You do not have to split your code in callback methods or inlined delegates. You do not need to marshall calls in the UI thread using the Dispacher or the SynchronizationContext. All this stuff is handled by the AsyncEnumerator class.&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;private IEnumerator&amp;lt;int&amp;gt; ExecuteWithAsyncEnumerator(AsyncEnumerator ae)
{
    for (int n = 0; n &amp;lt; iterations; n++)
    {
        this.webService.BeginGetStockQuotes(ae.End(), null);
    }
 
    // AsyncEnumerator captures the calling thread's SynchronizationContext.
    // Set the Wintellect.Threading.AsyncProgModel.SynchronizationContext to
    // null so that the callback continues on a ThreadPool thread.
    ae.SyncContext = null;
    yield return iterations;

    for (int n = 0; n &amp;lt; iterations; n++)
    {
        this.webService.EndGetStockQuotes(ae.DequeueAsyncResult());
    }
 
    // AsyncEnumerator captures the synchronization context.
    SetStatus(&amp;quot;AsyncEnumerator completed.&amp;quot;, StatusState.Ready);
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8092/8397466137_b21abe090c_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;While what I&amp;#39;ve discussed in this post applies to&amp;#0160;&lt;a href=&quot;http://en.wikipedia.org/wiki/Mobile_application_development&quot; target=&quot;_blank&quot; title=&quot;Mobile application development is the process by which applications are developed for small low-power handheld devices such as personal digital assistants, enterprise digital assistants or mobile phones.&quot;&gt;Mobile application development&lt;/a&gt;, the same principles can be applied to&amp;#0160;&lt;a href=&quot;http://en.wikipedia.org/wiki/Rich_Internet_application&quot; target=&quot;_blank&quot; title=&quot;A Rich Internet Application (RIA) is a web application that has many of the characteristics of desktop applications, typically delivered either by way of a site-specific browser, via a browser plug-in, independent sandboxes, or virtual machines.&quot;&gt;Rich Internet applications&lt;/a&gt; and &lt;a href=&quot;http://en.wikipedia.org/wiki/Smart_client&quot; target=&quot;_blank&quot; title=&quot;A &amp;quot;Smart Client&amp;quot; application can be created in several very different technologies.&quot;&gt;Smart client&lt;/a&gt;. I have been using the AsyncEnumerator class for over two years and I have to say that it changed the way I think about using the APM. At the &lt;em&gt;end&lt;/em&gt;.. delivering responsive applications makes the &lt;em&gt;end&lt;/em&gt;-users happy.&lt;/p&gt;



</description>
			<pubDate>Sun, 17 Oct 2010 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>List of software engineering topics</title>
			<link>http://nikosbaxevanis.com/2010/10/14/list-of-software-engineering-topics</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/10/14/list-of-software-engineering-topics</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/List_of_software_engineering_topics&quot;&gt;This&lt;/a&gt; list along with &lt;a href=&quot;http://en.wikipedia.org/wiki/List_of_software_development_philosophies&quot; target=&quot;_blank&quot; title=&quot;List of software development philosophies - Wikipedia, the free encyclopedia&quot;&gt;this one&lt;/a&gt;&amp;#0160;completes the list of topics a software engineer should be aware of (well, almost!).&lt;/p&gt;



</description>
			<pubDate>Thu, 14 Oct 2010 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>GitHub + Visual Studio = Love</title>
			<link>http://nikosbaxevanis.com/2010/10/14/github-visual-studio-love</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/10/14/github-visual-studio-love</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;I love&amp;#0160;&lt;a href=&quot;http://www.github.com/&quot; target=&quot;_blank&quot; title=&quot;Online project hosting using Git. Includes source-code browser, in-line editing, wikis, and ticketing. Free for public open-source code.&quot;&gt;GitHub&lt;/a&gt;.&amp;#0160;It&amp;#39;s&amp;#0160;&lt;a href=&quot;http://github.com/blog/39-say-hello-to-the-network-graph-visualizer&quot; target=&quot;_blank&quot; title=&quot;Say hello to the Network Graph Visualizer&quot;&gt;Network Graph Visualizer&lt;/a&gt;&amp;#0160;is outstanding! It solves one of the biggest challenges in open-source world; keeping track of what other people have done with the code base.&lt;/p&gt;


&lt;p&gt;If you use Windows for&amp;#0160;writing&amp;#0160;your code you can use the tools described &lt;a href=&quot;http://nikosbaxevanis.com/2010/10/07/building-castle-activerecord-from-source-at-github/&quot; target=&quot;_self&quot;&gt;here&lt;/a&gt;&amp;#0160;to have&amp;#0160;Git on shell context-menu. For Visual Studio support you can use &lt;a href=&quot;http://code.google.com/p/gitextensions/&quot; target=&quot;_blank&quot; title=&quot;Git Extensions is a small toolset to make working with Git under Windows a little more intuitive.&quot;&gt;GitExtensions&lt;/a&gt;&amp;#0160;and/or Joshua Flanagan&amp;#39;s &lt;a href=&quot;http://github.com/joshuaflanagan/gitmacros&quot; target=&quot;_blank&quot; title=&quot;Visual Studio macros for viewing a file on GitHub.&quot;&gt;GitMacros&lt;/a&gt;. The last one requires you to do some steps for adding the macros manually but it&amp;#39;s worth it, since you can have some basic GitHub functionality in minutes (like&amp;#0160;opening&amp;#0160;the GitHub page for the current file).&lt;/p&gt;



</description>
			<pubDate>Thu, 14 Oct 2010 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Quick Comparison of NHibernate Books</title>
			<link>http://nikosbaxevanis.com/2010/10/11/quick-comparison-of-nhibernate-books</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/10/11/quick-comparison-of-nhibernate-books</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;&lt;a href=&quot;http://sourceforge.net/projects/nhibernate/&quot; target=&quot;_blank&quot;&gt;NHibernate&lt;/a&gt;&amp;#0160;is an &lt;a href=&quot;http://en.wikipedia.org/wiki/Object-relational_mapping&quot; target=&quot;_blank&quot; title=&quot;Object-relational mapping (ORM, O/RM, and O/R mapping) in computer software is a programming technique for converting data between incompatible type systems ...&quot;&gt;Object-relational mapping&lt;/a&gt; (ORM) solution for the Microsoft .NET platform. It provides a framework for mapping an object-oriented domain model to a traditional relational database. It is open-source, easy to use (if you are familiar with good design principles) and offers a lot of extensibility points (logging and interception to name a few). The story begins with &lt;a href=&quot;http://www.hibernate.org/&quot; target=&quot;_blank&quot; title=&quot;Hibernate an open source Java persistence framework project. Perform powerful object relational mapping and query databases using HQL and ...&quot;&gt;Hibernate&lt;/a&gt; in Java. In fact, there are &lt;a href=&quot;http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&amp;amp;field-keywords=hibernate&amp;amp;x=0&amp;amp;y=0&quot; target=&quot;_blank&quot;&gt;many books&lt;/a&gt; out there for Hibernate but only a few for NHibernate (so far):&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.manning.com/kuate/&quot; target=&quot;_blank&quot;&gt;NHibernate In Action&lt;/a&gt; (Manning, 2009)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.packtpub.com/nhibernate-2-x-beginners-guide/book&quot; target=&quot;_blank&quot;&gt;NHibernate 2 Beginner&amp;#39;s Guide&lt;/a&gt; (Packt Publishing, 2010)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.packtpub.com/nhibernate-3-0-cookbook/book&quot; target=&quot;_blank&quot;&gt;NHibernate 3.0 Cookbook&lt;/a&gt; (Pack Publishing, 2010)&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;NHibernate In Action is written by members of NHibernate (Pierre Henri Kuaté, Tobin Harris)&amp;#0160;and Hibernate (Christian Bauer, Gavin King) team. It contains a lot of stuff about the internals, such as,&amp;#0160;the persistence lifecycle, the persistence manager, transitive persistence, the NHibernate type system, advanced query techniques, optimizing object retrieval (I could go on).&lt;/p&gt;


&lt;p&gt;NHibernate 2 Beginner&amp;#39;s Guide, written by Aaron Cure,&amp;#0160;targets those who have not used an ORM yet. It helps you find&amp;#0160;about what is NHibernate, why would you use it, where do you get it, and more. It guides you on how to create mappings (XML and &lt;a href=&quot;http://fluentnhibernate.org/&quot; target=&quot;_blank&quot; title=&quot;Fluent NHibernate, a statically compiled alternative to NHibernate&amp;#39;s standard hbm xml mapping.&quot;&gt;Fluently&lt;/a&gt;), types, relationships and more. It contains a whole chapter about Code Generation and even talks about&amp;#0160;&lt;a href=&quot;http://nhforge.org/wikis/burrow/introduction.aspx&quot; target=&quot;_blank&quot; title=&quot;NHibernate.Burrow is a light weight middleware developed to support .NET applications using NHibernate as ORM framework by providing advanced and smart session/transaction management and other facilitates.&quot;&gt;Burrow&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;NHibernate 3.0 Cookbook, written by&amp;#0160;Jason Dentler, is the most recent and most updated. In the chapter about mappings, (besides XML and Fluently) it discuss about creating mappings in code using&amp;#0160;&lt;a href=&quot;http://code.google.com/p/codeconform/&quot; target=&quot;_blank&quot; title=&quot;ORM configuration by code.&quot;&gt;ConfORM&lt;/a&gt;.&amp;#0160;It describes the Conversation per Business Transaction pattern, the use of Futures, NHibernate Spatial and more! It focus on testing and describes the use of NHibernate Profiler and the Fluent NHibernate Persistence Tester among other. It even promotes design patterns and talks about using &lt;a href=&quot;http://en.wikipedia.org/wiki/Dependency_injection&quot; target=&quot;_blank&quot; title=&quot;Dependency injection (DI) in object-oriented computer programming is a design pattern with a core principle of separating behavior from dependency ...&quot;&gt;dependency injection&lt;/a&gt; with entities.&lt;/p&gt;



</description>
			<pubDate>Mon, 11 Oct 2010 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Allowing only one instance of a WPF application to execute</title>
			<link>http://nikosbaxevanis.com/2010/10/11/allowing-only-one-instance-of-a-wpf-application-to-execute</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/10/11/allowing-only-one-instance-of-a-wpf-application-to-execute</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;Sometimes, for any reason, you want to have only one instance per application.&lt;/p&gt;


&lt;p&gt;Search on the internet and you will find&amp;nbsp;&lt;a href=&quot;http://www.google.gr/search?sourceid=chrome&amp;amp;ie=UTF-8&amp;amp;q=wpf+single+instance&quot; target=&quot;_blank&quot;&gt;many different ways&lt;/a&gt; of doing this. However, inside Jeffrey Ricther's &lt;a title=&quot;CLR via C#, Third Edition&quot; href=&quot;http://www.microsoft.com/learning/en/us/book.aspx?ID=13874&quot; target=&quot;_blank&quot;&gt;excellent book&lt;/a&gt;&amp;nbsp;there is a way&amp;nbsp;of allowing only one instance of an application (Console, WinForms, WPF) to execute at any given time using kernel-mode constructs.&lt;/p&gt;


&lt;p&gt;Using what has been described in the book and searching at &lt;a href=&quot;http://www.pinvoke.net/default.aspx/user32/ShowWindow.html&quot; target=&quot;_blank&quot;&gt;P/Invoke.net&lt;/a&gt;, I wrote some code that works with WPF applications. The code also attempts to set focus on the window and if it's minimized it will attempt to restore it.&amp;nbsp;&lt;/p&gt;




&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows;
 
internal partial class App : Application
{
    private static readonly Semaphore singleInstanceWatcher;
    private static readonly bool createdNew;
 
    static App()
    {
        // Ensure other instances of this application are not running.
        singleInstanceWatcher = new Semaphore(
            0, // Initial count.
            1, // Maximum count.
            Assembly.GetExecutingAssembly().GetName().Name,
            out createdNew);
 
        if (createdNew)
        {
            // This thread created the kernel object so no other instance
            // of this application must be running.
        }
        else
        {
            // This thread opened an existing kernel object with the same
            // string name; another instance of this app must be running now.
 
            // Gets a new System.Diagnostics.Process component and the
            // associates it with currently active process.
            Process current = Process.GetCurrentProcess();
 
            // Enumerate through all the process resources on the share
            // local computer that the specified process name.
            foreach (Process process in
                 Process.GetProcessesByName(current.ProcessName))
            {
                if (process.Id != current.Id)
                {
                    NativeMethods.SetForegroundWindow(
                        process.MainWindowHandle);
                    NativeMethods.ShowWindow(process.MainWindowHandle, 
                        WindowShowStyle.Restore);
                    break;
                }
            }
 
            // Terminate this process and gives the underlying operating 
            // system the specified exit code.
            Environment.Exit(-2);
        }
    }
 
    private static class NativeMethods
    {
        /// &amp;lt;summary&amp;gt;
        /// Brings the thread that created the specified window into the
        /// foreground and activates the window. Keyboard input is directed
        /// to the window, and various visual cues are changed for the user.
        /// The system assigns a slightly higher priority to the thread that
        /// created the foreground window than it does to other threads.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name=&amp;quot;hWnd&amp;quot;&amp;gt;A handle to the window that should be
        /// activated and brought to the foreground.
        /// &amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;If the window was brought to the foreground, the
        /// return value is nonzero. &amp;lt;/returns&amp;gt;
        [DllImport(&amp;quot;user32.dll&amp;quot;)]
        internal static extern bool SetForegroundWindow(IntPtr hWnd);
 
        /// &amp;lt;summary&amp;gt;Shows a Window&amp;lt;/summary&amp;gt;
        /// &amp;lt;remarks&amp;gt;
        /// &amp;lt;para&amp;gt;To perform certain special effects when showing or hiding a
        /// window, use AnimateWindow.&amp;lt;/para&amp;gt;
        /// &amp;lt;para&amp;gt;The first time an application calls ShowWindow, it should use
        /// the WinMain function's nCmdShow parameter as its nCmdShow ..
        /// Subsequent calls to ShowWindow must use one of the values in the
        /// given list, instead of the one specified by the WinMain function's
        /// nCmdShow parameter.&amp;lt;/para&amp;gt;
        /// &amp;lt;para&amp;gt;As noted in the discussion of the nCmdShow parameter, the
        /// nCmdShow value is ignored in the first call to ShowWindow if the
        /// program that launched the application specifies startup information
        /// in the structure. In this case, ShowWindow uses the information
        /// specified in the STARTUPINFO structure to show the window. On
        /// subsequent calls, the application must call ShowWindow with ..
        /// set to SW_SHOWDEFAULT to use the startup information provided by ..
        /// program that launched the application. This behavior is designed ..
        /// the following situations: &amp;lt;/para&amp;gt;
        /// &amp;lt;list type=&amp;quot;&amp;quot;&amp;gt;
        ///    &amp;lt;item&amp;gt;Applications create their main window by calling ..
        ///    with the WS_VISIBLE flag set. &amp;lt;/item&amp;gt;
        ///    &amp;lt;item&amp;gt;Applications create their main window by calling ..
        ///    with the WS_VISIBLE flag cleared, and later call ShowWindow ..
        ///    SW_SHOW flag set to make it visible.&amp;lt;/item&amp;gt;
        /// &amp;lt;/list&amp;gt;&amp;lt;/remarks&amp;gt;
        /// &amp;lt;param name=&amp;quot;hWnd&amp;quot;&amp;gt;Handle to the window.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name=&amp;quot;nCmdShow&amp;quot;&amp;gt;Specifies how the window is to be shown.
        /// This parameter is ignored the first time an application calls
        /// ShowWindow, if the program that launched the application provides a
        /// STARTUPINFO structure. Otherwise, the first time ShowWindow .. ,
        /// the value should be the value obtained by the WinMain function ..
        /// nCmdShow parameter. In subsequent calls, this parameter ..
        /// the WindowShowStyle members.&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;
        /// If the window was previously visible, the return value is nonzero.
        /// If the window was previously hidden, the return value is zero.
        /// &amp;lt;/returns&amp;gt;
        [DllImport(&amp;quot;user32.dll&amp;quot;)]
        internal static extern bool ShowWindow(IntPtr hWnd,
            WindowShowStyle nCmdShow);
    }
 
    /// &amp;lt;summary&amp;gt;
    /// Enumeration of the different ways of showing a window.&amp;lt;/summary&amp;gt;
    internal enum WindowShowStyle : uint
    {
        /// &amp;lt;summary&amp;gt;Hides the window and activates another window.&amp;lt;/summary&amp;gt;
        /// &amp;lt;remarks&amp;gt;See SW_HIDE&amp;lt;/remarks&amp;gt;
        Hide = 0,
        /// &amp;lt;summary&amp;gt;Activates and displays a window. If the window ..
        /// or maximized, the system restores it to its original size and
        /// position. An application should specify this flag when displaying
        /// the window for the first time.&amp;lt;/summary&amp;gt;
        /// &amp;lt;remarks&amp;gt;See SW_SHOWNORMAL&amp;lt;/remarks&amp;gt;
        ShowNormal = 1,
        /// &amp;lt;summary&amp;gt;Activates the window and displays it ..&amp;lt;/summary&amp;gt;
        /// &amp;lt;remarks&amp;gt;See SW_SHOWMINIMIZED&amp;lt;/remarks&amp;gt;
        ShowMinimized = 2,
        /// &amp;lt;summary&amp;gt;Activates the window and displays it ..&amp;lt;/summary&amp;gt;
        /// &amp;lt;remarks&amp;gt;See SW_SHOWMAXIMIZED&amp;lt;/remarks&amp;gt;
        ShowMaximized = 3,
        /// &amp;lt;summary&amp;gt;Maximizes the specified window.&amp;lt;/summary&amp;gt;
        /// &amp;lt;remarks&amp;gt;See SW_MAXIMIZE&amp;lt;/remarks&amp;gt;
        Maximize = 3,
        /// &amp;lt;summary&amp;gt;Displays a window in its most recent size and position.
        /// This value is similar to &amp;quot;ShowNormal&amp;quot;, except the window is not
        /// actived.&amp;lt;/summary&amp;gt;
        /// &amp;lt;remarks&amp;gt;See SW_SHOWNOACTIVATE&amp;lt;/remarks&amp;gt;
        ShowNormalNoActivate = 4,
        /// &amp;lt;summary&amp;gt;Activates the window and displays it in its current size
        /// and position.&amp;lt;/summary&amp;gt;
        /// &amp;lt;remarks&amp;gt;See SW_SHOW&amp;lt;/remarks&amp;gt;
        Show = 5,
        /// &amp;lt;summary&amp;gt;Minimizes the specified window and activates the next
        /// top-level window in the Z order.&amp;lt;/summary&amp;gt;
        /// &amp;lt;remarks&amp;gt;See SW_MINIMIZE&amp;lt;/remarks&amp;gt;
        Minimize = 6,
        /// &amp;lt;summary&amp;gt;Displays the window as a minimized window. This value is
        /// similar to &amp;quot;ShowMinimized&amp;quot;, except the window ..&amp;lt;/summary&amp;gt;
        /// &amp;lt;remarks&amp;gt;See SW_SHOWMINNOACTIVE&amp;lt;/remarks&amp;gt;
        ShowMinNoActivate = 7,
        /// &amp;lt;summary&amp;gt;Displays the window in its current size and position. This
        /// value is similar to &amp;quot;Show&amp;quot;, except the window ..&amp;lt;/summary&amp;gt;
        /// &amp;lt;remarks&amp;gt;See SW_SHOWNA&amp;lt;/remarks&amp;gt;
        ShowNoActivate = 8,
        /// &amp;lt;summary&amp;gt;Activates and displays the window. If the window is
        /// minimized or maximized, the system restores it to its original size
        /// and position. An application should specify this flag ..
        /// a minimized window.&amp;lt;/summary&amp;gt;
        /// &amp;lt;remarks&amp;gt;See SW_RESTORE&amp;lt;/remarks&amp;gt;
        Restore = 9,
        /// &amp;lt;summary&amp;gt;Sets the show state based on the SW_ value specified ..
        /// STARTUPINFO structure passed to the CreateProcess function by the
        /// program that started the application.&amp;lt;/summary&amp;gt;
        /// &amp;lt;remarks&amp;gt;See SW_SHOWDEFAULT&amp;lt;/remarks&amp;gt;
        ShowDefault = 10,
        /// &amp;lt;summary&amp;gt;Windows 2000/XP: Minimizes a window, even if the thread
        /// that owns the window is hung. This flag should only be used when
        /// minimizing windows from a different thread.&amp;lt;/summary&amp;gt;
        /// &amp;lt;remarks&amp;gt;See SW_FORCEMINIMIZE&amp;lt;/remarks&amp;gt;
        ForceMinimized = 11
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;One improvement would be to restore the window only if it's minimized by checking the return value of SetForegroundWindow method. I leave this to you, go on and adapt it to your own needs.&lt;/p&gt;

</description>
			<pubDate>Mon, 11 Oct 2010 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Let's Pack! Nubular, HornGet and NuPack</title>
			<link>http://nikosbaxevanis.com/2010/10/08/let-s-pack-nubular-hornget-and-nupack</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/10/08/let-s-pack-nubular-hornget-and-nupack</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;&lt;strong&gt;Update: &lt;/strong&gt;At the time of this writting &lt;a href=&quot;http://nuget.codeplex.com/&quot; target=&quot;_blank&quot; title=&quot;NuGet is a Visual Studio extension that makes it easy to install and update third-party libraries and tools.&quot;&gt;NuGet&lt;/a&gt; was called NuPack.&lt;/p&gt;




&lt;p&gt;Package Management is not easy, unless you are doing very (very) small projects. It can be quite complex if your project is &amp;#0160;developed in-house for a company (enterprise).&lt;/p&gt;


&lt;p&gt;If you haven&amp;#39;t tried anything yet, have a look at the following Package Management tools:&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://nu.wikispot.org/Current_Packages&quot; target=&quot;_blank&quot; title=&quot;The Nu Project provides a framework and tools to deal with the current .NET package delivery...&quot;&gt;Nubular&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://github.com/dagda1/horn_src&quot; target=&quot;_blank&quot; title=&quot;The initial mission statement is to take control of building a common set of open source packages that are probably similar to many in the ALT.NET space...&quot;&gt;HornGet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://nupack.codeplex.com/&quot; target=&quot;_blank&quot; title=&quot;NuPack is a free, open source developer focused package management system for the .NET platform intent on simplifying the process of incorporating third party libraries into a .NET application during development.&quot;&gt;NuPack&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Nubular was pretty much the same with &lt;a href=&quot;http://rubygems.org/&quot; target=&quot;_blank&quot; title=&quot;RubyGems.org is the Ruby community&amp;#39;s gem hosting service. Instantly publish your gems and install them. Use the API to interact and find out more...&quot;&gt;RubyGems.org&lt;/a&gt;&amp;#0160;There are pre-uploaded packages that you can download and use in your project. For example, to use Castle Active Record you don&amp;#39;t need to follow the steps described &lt;a href=&quot;http://nikosbaxevanis.com/2010/10/07/building-castle-activerecord-from-source-at-github/&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. Just grab the package, unpack and you are done.&amp;#0160;&lt;/p&gt;


&lt;p&gt;What many don&amp;#39;t understand is the situation where you reference for example &lt;a href=&quot;http://code.google.com/p/moq/&quot; target=&quot;_blank&quot; title=&quot;The simplest mocking library for .NET 3.5 and Silverlight with deep C# 3.0 integration.&quot;&gt;Moq&lt;/a&gt;, &lt;a href=&quot;http://github.com/jbogard/automapper&quot; target=&quot;_blank&quot; title=&quot;A convention-based object-object mapper in .NET&quot;&gt;AutoMapper&lt;/a&gt;&amp;#0160;and &lt;a href=&quot;http://github.com/castleproject/Castle.InversionOfControl&quot; target=&quot;_blank&quot; title=&quot;Castle Project offers two Inversion of Control Containers. The MicroKernel and the Windsor Container.&quot;&gt;Castle Windsor&lt;/a&gt;, all in one project &lt;em&gt;(version numbers are&amp;#0160;fictional)&lt;/em&gt;:&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;Moq uses Castle.DynamicProxy.dll v1.1&lt;/li&gt;
&lt;li&gt;AutoMapper uses Castle.DynamicProxy.dll v1.2&lt;/li&gt;
&lt;li&gt;Castle Windsor uses Castle.DynamicProxy.dll v.1.3 &lt;em&gt;(in fact, latest public release of Windsor has DynamicProxy merged in the same assembly).&amp;quot;&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;HornGet was able to deal with this situation, it could build Moq using the latest and greatest, AutoMapper and Windsor too. You end up with three assemblies that referenced the same version of the depenency/ies.&lt;/p&gt;


&lt;p&gt;Even if you choose this path, it is the hardest one because you need to run all the unit-tests in the projects (Moq, AutoMapper, Windsor) and make sure they pass with the latest version in /trunk of DynamicProxy. And this is not enough, you need to run all the tests (unit and intergration) of your project. After all the above pass, you can go home early. But I am sure that it is already early afternoon and you spent at least 4 hours doing this.&lt;/p&gt;


&lt;p&gt;Of course you may not choose to go with this path and install the different versions of Castle.DynamicProxy.dll in&amp;#0160;&lt;a href=&quot;http://en.wikipedia.org/wiki/Global_Assembly_Cache&quot; target=&quot;_blank&quot; title=&quot;GAC is a machine-wide .NET assemblies cache for Microsoft&amp;#39;s CLR platform.&quot;&gt;GAC&lt;/a&gt;. That way Nubular worked great!&lt;/p&gt;


&lt;p&gt;NuPack is a new Package Management tool for the .NET Framework that aims to make your life a lot more easier. It integrates with Visual Studio 2010 and there are a some interesting&amp;#0160;&lt;a href=&quot;http://nupack.codeplex.com/team/view&quot; target=&quot;_blank&quot;&gt;people&lt;/a&gt;&amp;#0160;behind it.&lt;/p&gt;


&lt;p&gt;Have a look at the &lt;a href=&quot;http://nupack.codeplex.com/documentation?title=Getting%20Started&quot; target=&quot;_blank&quot; title=&quot;The Getting Started guide will help you start using NuPack right away.&quot;&gt;documentation&lt;/a&gt; and start using it.&lt;/p&gt;



</description>
			<pubDate>Fri, 08 Oct 2010 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>Building Castle ActiveRecord from Source at GitHub</title>
			<link>http://nikosbaxevanis.com/2010/10/07/building-castle-activerecord-from-source-at-github</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/10/07/building-castle-activerecord-from-source-at-github</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;To follow the steps described in the post you will need:&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://code.google.com/p/tortoisegit/&quot; target=&quot;_blank&quot; title=&quot;TortoiseGit The coolest Interface to (Git) Version Control&quot;&gt;TortoiseGit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://code.google.com/p/msysgit/downloads/list&quot; target=&quot;_blank&quot; title=&quot;Git for Windows. Please use the download links in the right sidebar, the link starting with &amp;quot;Git&amp;quot; is for the desktop version, the link starting with &amp;quot;PortableGit&amp;quot; is for the portable version.&quot;&gt;msysgit&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Visit&amp;#0160;&lt;a href=&quot;https://github.com/castleproject/ActiveRecord&quot; target=&quot;_blank&quot;&gt;https://github.com/castleproject/ActiveRecord&lt;/a&gt;&amp;#0160;and copy to clipboard the URL for Read-Only access.&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8513/8398555422_2c15a13e0d_b.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;Create an empty directory and select the entry named &amp;quot;Git Clone...&amp;quot; on the Windows Explorer Context Menu.&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8195/8397466785_84623942e0_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;Click OK in the next screen and wait while Git is downloading the project files.&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8230/8397466895_e063ab6f9b_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;When finished, you can browse the project files in the specified directory.&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8513/8398555346_f79731838d_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;The default is to build for version 4.0 of the .NET Framework. If you need to build for an older version you&amp;#0160;can edit the build.cmd file (it is actually a batch file).&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8367/8398555368_d89d8bf827_b.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;The project&amp;#39;s build platform is&amp;#0160;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/wea2sca5(VS.90).aspx&quot; target=&quot;_blank&quot; title=&quot;MSBuild is the new build platform for Microsoft and Visual Studio. This section contains conceptual information about MSBuild.&quot;&gt;MSBuild&lt;/a&gt;&amp;#0160;as you can see from the Console Output above.&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8330/8397466683_0d83ce3950_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;Open folder &amp;quot;build&amp;quot; which is the project&amp;#39;s build output.&lt;/p&gt;




&lt;p&gt;&lt;img src=&quot;http://farm9.staticflickr.com/8363/8397466669_92a7f93348_o.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;




&lt;p&gt;As you may notice, the project now uses &lt;a href=&quot;https://www.re-motion.org/&quot; title=&quot;re-motion is an Open Source development framework targeted at .NET enterprise applications.&quot;&gt;Remotion&amp;#39;s&lt;/a&gt;&amp;#0160;&lt;a href=&quot;https://www.re-motion.org/download/re-linq.pdf&quot; title=&quot;A General Purpose LINQ Foundation&quot;&gt;re-linq&lt;/a&gt;&amp;#0160;provider.&lt;/p&gt;




&lt;p&gt;To have a working data access layer in minutes, add a reference to:&lt;/p&gt;


&lt;ul&gt;
&lt;li&gt;Castle.ActiveRecord.dll&lt;/li&gt;
&lt;li&gt;Castle.Components.Validator.dll&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;The documentation is &lt;a href=&quot;http://stw.castleproject.org/Active%20Record.MainPage.ashx&quot; title=&quot;Castle Active Record&quot;&gt;here&lt;/a&gt;. Feel free to contribute.&lt;/p&gt;

</description>
			<pubDate>Thu, 07 Oct 2010 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
		<item>
			<title>BindingBase.StringFormat Property (System.Windows.Data)</title>
			<link>http://nikosbaxevanis.com/2010/10/07/bindingbase-stringformat-property-system-windows-data</link>
			<guid isPermaLink="true">http://nikosbaxevanis.com/2010/10/07/bindingbase-stringformat-property-system-windows-data</guid>
			<author>nikos.baxevanis@gmail.com (Nikos Baxevanis)</author>
			<description>&lt;p&gt;By default the WPF binding engine uses 2 fractional digits when displaying double values. When those digits are zero though, they are omitted. You can override this by specifying the StringFormat Property on the binding.&lt;/p&gt;


&lt;div&gt;
  &lt;pre&gt;&lt;code class='csharp'&gt;Text=&amp;quot;{Binding Path=Price, StringFormat={}{0:0.00}}&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.windows.data.bindingbase.stringformat.aspx&quot;&gt;StringFormat&lt;/a&gt; can be a predefined, composite, or custom string format. For more information about string formats, see Formatting Types &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/26etazsy.aspx&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;



</description>
			<pubDate>Thu, 07 Oct 2010 00:00:00 GTB Daylight Time</pubDate>
		</item>
		
	</channel>
</rss>