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

<channel>
	<title>Upcom.eu Blog</title>
	<atom:link href="http://blog.upcom.eu/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.upcom.eu</link>
	<description>Comments, remarks, information, solutions from the Upcom team</description>
	<lastBuildDate>Tue, 13 Sep 2011 17:56:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Combining Data Theories in AutoFixture.Xunit extension</title>
		<link>http://blog.upcom.eu/2011/08/29/combining-data-theories-in-autofixture-xunit-extension/</link>
		<comments>http://blog.upcom.eu/2011/08/29/combining-data-theories-in-autofixture-xunit-extension/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 15:09:15 +0000</pubDate>
		<dc:creator>nbaxevanis</dc:creator>
				<category><![CDATA[AutoFixture]]></category>
		<category><![CDATA[Test-Driven Development]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://blog.upcom.eu/?p=104</guid>
		<description><![CDATA[Crossposted from my personal blog. xUnit.net supports parameterized tests via data theories which are types deriving from the Xunit.Extensions.DataAttribute type.&#160;Some popular attributes include: InlineDataAttribute,&#160;PropertyDataAttribute and ClassDataAttribute. AutoFixture.Xunit extension includes a very useful type, for providing auto-data theories, called&#160;AutoMoqDataAttribute.&#160; Imagine a &#8230; <a href="http://blog.upcom.eu/2011/08/29/combining-data-theories-in-autofixture-xunit-extension/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Crossposted from my personal <a title="Combining Data Theories in AutoFixture.Xunit extension" href="http://www.nikosbaxevanis.com/bonus-bits/2011/08/combining-xunit-data-theories.html" target="_blank">blog</a>.</p>
<p><a title="xUnit.net is a unit testing tool for the .NET Framework. Written by the original inventor of NUnit." href="http://xunit.codeplex.com/" target="_blank">xUnit.net</a> supports parameterized tests via data theories which are types deriving from the Xunit.Extensions.DataAttribute type.&nbsp;Some popular attributes include:</p>
<p>InlineDataAttribute,&nbsp;PropertyDataAttribute and ClassDataAttribute.</p>
<p>AutoFixture.Xunit extension includes a very useful type, for providing auto-data theories, called&nbsp;<a title="AutoData Theories with AutoFixture" href="http://blog.ploeh.dk/2010/10/08/AutoDataTheoriesWithAutoFixture.aspx" target="_blank">AutoMoqDataAttribute</a>.&nbsp;</p>
<p>Imagine a Scenario where we have a unit test method with 3 parameters.&nbsp;We want the first parameters to be supplied by InlineData and the rest by AutoFixture using AutoMoqData.</p>
<p><script src="https://gist.github.com/1169205.js?file=InlineAutoDataScenario.cs"></script></p>
<p>This is now possible using the <strong>InlineAutoDataAttribute</strong> type which is now on the trunk and will be available on next public release (after version 2.1).&nbsp;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.</p>
<p>InlineAutoDataAttribute derives from <strong>CompositeDataAttribute</strong>,&nbsp;an implementation of DataAttribute that composes other DataAttribute instances.</p>
<p>Here is how it works:</p>
<ul>
<li>Delegate the GetData method call to the&nbsp;<em>first</em>&nbsp;attribute.</li>
<li>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.
<ul>
<li>If so, yield the object array.</li>
<li>If not, invoke GetData on the&nbsp;<em>next</em>&nbsp;attribute.
<ul>
<li>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.</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li>Recursively repeat this process until all object arrays have the required length.</li>
</ul>
<blockquote>
<p>While this feature comes with AutoFixture.Xunit extension, the CompositeDataAttribute class depends only on the xunit.extensions assembly.</p>
</blockquote>
<p>You may compile the code from the latest&nbsp;<a title="AutoFixture (changesets)" href="http://autofixture.codeplex.com/SourceControl/list/changesets" target="_blank">trunk</a>&nbsp;version, alternatively&nbsp;the latest build (including strong names) can be downloaded from&nbsp;<a href="http://teamcity.codebetter.com/project.html?projectId=project129&amp;tab=projectOverview. " target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.upcom.eu/2011/08/29/combining-data-theories-in-autofixture-xunit-extension/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Heuristics for Static Factory Methods in AutoFixture</title>
		<link>http://blog.upcom.eu/2011/08/29/heuristics-for-static-factory-methods-in-autofixture/</link>
		<comments>http://blog.upcom.eu/2011/08/29/heuristics-for-static-factory-methods-in-autofixture/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 15:08:02 +0000</pubDate>
		<dc:creator>nbaxevanis</dc:creator>
				<category><![CDATA[AutoFixture]]></category>
		<category><![CDATA[Test-Driven Development]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://blog.upcom.eu/?p=102</guid>
		<description><![CDATA[Crossposted from my personal blog. Here is a type with a private constructor: In order to create an instance of that type we have to call one of it&#8217;s static factory methods, for example: If we try to create an &#8230; <a href="http://blog.upcom.eu/2011/08/29/heuristics-for-static-factory-methods-in-autofixture/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Crossposted from my personal <a title="Heuristics for Static Factory Methods in AutoFixture" href="http://www.nikosbaxevanis.com/bonus-bits/2011/08/heuristics-for-static-factory-methods-in-autofixture.html" target="_blank">blog</a>.</p>
<p>Here is a type with a private constructor:</p>
<p><script src="https://gist.github.com/1168857.js?file=TypeWithFactoryMethod.cs"></script></p>
<p>In order to create an instance of that type we have to call one of it&#8217;s static factory methods, for example:</p>
<p><script src="https://gist.github.com/1168857.js?file=CreatingAnInstance.cs"></script></p>
<p>If we try to create an <a title="Anonymous Variables" href="http://blogs.msdn.com/b/ploeh/archive/2008/11/17/anonymous-variables.aspx" target="_blank">Anonymous Variable</a> with <a title="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." href="http://autofixture.codeplex.com" target="_blank">AutoFixture</a> right now (version 2.1) it will throw an exception since there are no public constructors:</p>
<p><script src="https://gist.github.com/1168857.js?file=Version_2point1.cs"></script></p>
<p>Using the latest version from&nbsp;<a title="AutoFixture (changesets)" href="http://autofixture.codeplex.com/SourceControl/list/changesets" target="_blank">trunk</a>&nbsp;(and on the next public release) the above code will work.&nbsp;It will successfully return an instance of the type by using&nbsp;a set of heuristics that enable AutoFixture to search for static factory methods.</p>
<p>The latest build (including strong names) can be downloaded from <a href="http://teamcity.codebetter.com/project.html?projectId=project129&amp;tab=projectOverview. " target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.upcom.eu/2011/08/29/heuristics-for-static-factory-methods-in-autofixture/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enabling Add-In functionality in ASP.NET MVC 3 (Part 2)</title>
		<link>http://blog.upcom.eu/2011/08/23/enabling-add-in-functionality-in-asp-net-mvc-3-part-2/</link>
		<comments>http://blog.upcom.eu/2011/08/23/enabling-add-in-functionality-in-asp-net-mvc-3-part-2/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 22:13:32 +0000</pubDate>
		<dc:creator>nbaxevanis</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[MEF]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Test-Driven Development]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://blog.upcom.eu/?p=94</guid>
		<description><![CDATA[Crossposted from my personal blog. In this post I discussed the implementation of a&#160;Unity-specific controller factory &#160;that could take&#160;a delegate as a parameter in the constructor acting as the fallback factory when the DI container can not supply a controller. &#8230; <a href="http://blog.upcom.eu/2011/08/23/enabling-add-in-functionality-in-asp-net-mvc-3-part-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Crossposted from my personal <a title="Enabling Add-In functionality in ASP.NET MVC 3 (Part 2)" href="http://www.nikosbaxevanis.com/bonus-bits/2011/08/enabling-add-in-functionality-in-aspnet-mvc3-part2.html" target="_blank">blog</a>.</p>
<p>In this <a title="Enabling Add-In functionality in ASP.NET MVC 3" href="http://www.nikosbaxevanis.com/bonus-bits/2011/08/enabling-add-in-functionality-in-aspnet-mvc3.html" target="_blank">post</a> I discussed the implementation of a&nbsp;Unity-specific controller factory &nbsp;that could take&nbsp;a delegate as a parameter in the constructor acting as the fallback factory when the DI container can not supply a controller.</p>
<p>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.</p>
<p>One possible improvement in the design is to introduce a <a title="Composite Pattern" href="http://en.wikipedia.org/wiki/Composite_pattern" target="_blank">composite</a> implementation for an IControllerFactory. That way, we still have the chance to supply a MEF-specific controller factory.</p>
<p>A possible implementation of the <a title="Creates the specified controller by using the specified request context." href="http://msdn.microsoft.com/en-us/library/system.web.mvc.icontrollerfactory.createcontroller.aspx" target="_blank">CreateController</a> method is the one below:</p>
<p><script src="https://gist.github.com/1162543.js?file=CompositeControllerFactory.cs"></script></p>
<p>It will iterate through all controller factories calling their CreateController method. The first IController instance provided by the controller factories is returned.</p>
<p>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.</p>
<p>The&nbsp;<a title="Sets the specified controller factory." href="http://msdn.microsoft.com/en-us/library/dd460275.aspx" target="_blank">SetControllerFactory</a>&nbsp;method can accept an instance of a CompositeControllerFactory type as shown below:</p>
<p><script src="https://gist.github.com/1162543.js?file=BootstrapContainer.cs"></script></p>
<p><a title="CompositeControllerFactory.cs" href="https://github.com/moodmosaic/System.Web.Mvc.Composition/blob/master/Src/System.Web.Mvc.Composition/CompositeControllerFactory.cs" target="_blank">Implementation</a>,&nbsp;<a title="CompositeControllerFactoryFacts.cs" href="https://github.com/moodmosaic/System.Web.Mvc.Composition/blob/master/Src/System.Web.Mvc.CompositionUnitTest/CompositeControllerFactoryFacts.cs" target="_blank">Unit tests</a>&nbsp;and <a title="System.Web.Mvc.Composition" href="http://nuget.org/List/Packages/System.Web.Mvc.Composition" target="_blank">NuGet Package</a>.&nbsp;Sample application available <a title="ExtensibleMvcApplicationDemo-Part2.zip" href="http://goo.gl/bcye3" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.upcom.eu/2011/08/23/enabling-add-in-functionality-in-asp-net-mvc-3-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Does culture matter in outsourcing deals?</title>
		<link>http://blog.upcom.eu/2011/08/21/does-culture-matter-in-outsourcing-deals/</link>
		<comments>http://blog.upcom.eu/2011/08/21/does-culture-matter-in-outsourcing-deals/#comments</comments>
		<pubDate>Sun, 21 Aug 2011 11:19:49 +0000</pubDate>
		<dc:creator>kflokos</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[outsourcing culture]]></category>

		<guid isPermaLink="false">http://blog.upcom.eu/?p=85</guid>
		<description><![CDATA[In a recent article in Outsource Magazine (http://www.outsourcemagazine.co.uk/articles/item/4051-secret-agreements-on-culture-), Brandi Moore contested the ability of integrating outsourcing with local teams without &#8216;talking about the cultural differences&#8217; and trying to find solutions. Esteban Herrera, COO of Horse For Sources Research, rebutted with &#8230; <a href="http://blog.upcom.eu/2011/08/21/does-culture-matter-in-outsourcing-deals/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In a recent article in Outsource Magazine (<a href="http://www.outsourcemagazine.co.uk/articles/item/4051-secret-agreements-on-culture-" target="_blank">http://www.outsourcemagazine.co.uk/articles/item/4051-secret-agreements-on-culture-</a>), Brandi Moore contested the ability of integrating outsourcing with local teams without &#8216;talking about the cultural differences&#8217; and trying to find solutions.<br />
Esteban Herrera, COO of Horse For Sources Research, rebutted with this article <a href="http://www.horsesforsources.com/brandi-esteban" target="_blank">http://www.horsesforsources.com/brandi-esteban</a>.</p>
<p>Reading through both articles one may notice that both agree finally that cultural differences are important in an outsourcing agreement. It&#8217;s just that Mrs Moore advocated that most outsourcing providers do not pay attention to it, while Mr Herrera insisted that this is not the case &#8211; at least anymore!</p>
<p>Allow me to add here that training (at least 3 weeks preached Mr Herrera) is not something that changes the culture of a person! It helps him understand other cultures, but acquiring a new culture is a life-long experience!<br />
Ancient Greek philosophers defined &#8216;<em>Greek</em>&#8216; as &#8216;<em>anyone having taken part in the Greek education (παιδεία)</em>&#8216; which is a lot more than a few weeks training in a closed room!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.upcom.eu/2011/08/21/does-culture-matter-in-outsourcing-deals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enabling Add-In functionality in ASP.NET MVC 3</title>
		<link>http://blog.upcom.eu/2011/08/08/enabling-add-in-functionality-in-asp-net-mvc-3/</link>
		<comments>http://blog.upcom.eu/2011/08/08/enabling-add-in-functionality-in-asp-net-mvc-3/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 01:53:35 +0000</pubDate>
		<dc:creator>nbaxevanis</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[MEF]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://blog.upcom.eu/?p=77</guid>
		<description><![CDATA[Crossposted from my personal blog. Update:&#160;&#160;Part 2 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 &#8230; <a href="http://blog.upcom.eu/2011/08/08/enabling-add-in-functionality-in-asp-net-mvc-3/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Crossposted from my personal <a title="Enabling Add-In functionality in ASP.NET MVC 3" href="http://www.nikosbaxevanis.com/bonus-bits/2011/08/enabling-add-in-functionality-in-aspnet-mvc3.html" target="_blank">blog</a>.</p>
<p><strong>Update:&nbsp;</strong>&nbsp;<a title="Enabling Add-In functionality in ASP.NET MVC 3 (Part 2)" href="http://www.nikosbaxevanis.com/bonus-bits/2011/08/enabling-add-in-functionality-in-aspnet-mvc3-part2.html" target="_blank">Part 2</a></p>
<p>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 <a title="Runtime Callable Wrapper" href="http://en.wikipedia.org/wiki/Runtime_Callable_Wrapper" target="_blank">RCW</a>&nbsp;or else we had to&nbsp;write messy and error-prone VBA code.&nbsp;</p>
<p>Today, anyone who builds applications in managed code (using .NET 4 and above) has built-in&nbsp;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&nbsp;System.ComponentModel.Composition namespace (or else, <a title="Managed Extensibility Framework, or MEF" href="http://msdn.microsoft.com/en-us/library/system.componentmodel.composition.aspx" target="_blank">MEF</a>) for managing the composition of parts.</p>
<p>The host application, is the one shown below. I have selected the interesting types that I will be discussing.</p>
<p><a style="display: inline;" href="http://www.nikosbaxevanis.com/.a/6a0134873b0c0f970c0153908241d5970b-pi"> </a><a style="display: inline;" href="http://www.nikosbaxevanis.com/.a/6a0134873b0c0f970c015390824fde970b-pi"><img class="asset  asset-image at-xid-6a0134873b0c0f970c015390824fde970b" style="display: block; margin-left: auto; margin-right: auto;" title="HostSolutionTree" src="http://www.nikosbaxevanis.com/.a/6a0134873b0c0f970c015390824fde970b-800wi" border="0" alt="HostSolutionTree" /></a></p>
<p><strong>DiscoverableControllerFactory</strong></p>
<p>A MEF-specific <a title="Represents the controller factory that is registered by default." href="http://msdn.microsoft.com/en-us/library/system.web.mvc.defaultcontrollerfactory.aspx" target="_blank">DefaultControllerFactory</a>&nbsp;derived type. It&nbsp;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.</p>
<p><script src="https://gist.github.com/1131026.js?file=DiscoverableControllerFactory.cs"></script></p>
<p><strong>UnityControllerFactory</strong></p>
<p>A Unity-specific DefaultControllerFactory&nbsp;&nbsp;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)&nbsp;using&nbsp;MEF.</p>
<p><script src="https://gist.github.com/1131026.js?file=UnityControllerFactory.cs"></script></p>
<p><strong>Global.asax</strong></p>
<p>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&nbsp;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&#8217;s CreateController method. One last thing to note, this is the application&#8217;s&nbsp;<a title="Composition Root" href="http://blog.ploeh.dk/2011/07/28/CompositionRoot.aspx" target="_blank">Composition Root</a>. The DI container is referenced here, where the composition happens, and&nbsp;<span style="text-decoration: underline;">nowhere else</span>&nbsp;in the entire application.</p>
<p><script src="https://gist.github.com/1131026.js?file=Global.asax.cs"></script></p>
<p>The add-in application is a regular class library and it&#8217;s structure is shown below. I have selected the interesting types that I will be discussing.</p>
<p><a style="display: inline;" href="http://www.nikosbaxevanis.com/.a/6a0134873b0c0f970c014e8a7593dd970d-pi"><img class="asset  asset-image at-xid-6a0134873b0c0f970c014e8a7593dd970d" style="display: block; margin-left: auto; margin-right: auto;" title="AddInSolutionTree" src="http://www.nikosbaxevanis.com/.a/6a0134873b0c0f970c014e8a7593dd970d-800wi" border="0" alt="AddInSolutionTree" /></a></p>
<p><strong>ConceptController</strong></p>
<p>This is a proof of concept&nbsp;Controller for this demo. It is decorated with the&nbsp;<a title="Specifies that a type, property, field, or method provides a particular export." href="http://msdn.microsoft.com/en-us/library/system.componentmodel.composition.exportattribute.aspx" target="_blank">ExportAttribute</a>&nbsp;and&nbsp;<a title="Specifies metadata for a type, property, field, or method marked with the ExportAttribute." href="http://msdn.microsoft.com/en-us/library/system.componentmodel.composition.exportmetadataattribute.aspx" target="_blank">ExportMetadataAttribute</a>. 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&nbsp;<a title="Specifies the CreationPolicy for a part." href="http://msdn.microsoft.com/en-us/library/system.componentmodel.composition.partcreationpolicyattribute.aspx" target="_blank">PartCreationPolicyAttribute</a>&nbsp;is needed in order to specify that a new non-shared (transient) instance will be created for each request.</p>
<p><script src="https://gist.github.com/1131026.js?file=ConceptController.cs"></script></p>
<p><strong>Index.cshtml</strong>, <strong>Web.config</strong></p>
<p>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.</p>
<blockquote>
<p>Make sure to select all the views and set the property &#8220;Copy to Output directory&#8221; to &#8220;<em>Copy if newer&#8221;. </em>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).</p>
</blockquote>
<p>You can download the demo application <a title="ExtensibleMvcApplicationDemo-Part1.zip" href="http://goo.gl/kX4ZP" target="_blank">here</a>. Upon build the Concepts.dll along with it&#8217;s Views will be copied in the Web project&#8217;s &#8220;Extensions&#8221; directory. When run, the application will automatically load the assembly the first time the &#8220;Concepts&#8221; tab is pressed.</p>
<ul>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.upcom.eu/2011/08/08/enabling-add-in-functionality-in-asp-net-mvc-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Following the Composition Root pattern with Enterprise Library</title>
		<link>http://blog.upcom.eu/2011/08/03/following-the-composition-root-pattern-with-enterprise-library/</link>
		<comments>http://blog.upcom.eu/2011/08/03/following-the-composition-root-pattern-with-enterprise-library/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 21:08:03 +0000</pubDate>
		<dc:creator>nbaxevanis</dc:creator>
				<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Enterprise Library]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://blog.upcom.eu/?p=65</guid>
		<description><![CDATA[Crossposted from my personal blog. A question that frequently rises when building enterprise applications is: &#8220;Where should we compose object graphs?&#8221; and the answer is given by the Composition Root pattern: &#8220;As close as possible to the applications entry point.&#8221; The &#8230; <a href="http://blog.upcom.eu/2011/08/03/following-the-composition-root-pattern-with-enterprise-library/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Crossposted from my personal <a title="Following the Composition Root pattern with Enterprise Library" href="http://www.nikosbaxevanis.com/bonus-bits/2011/08/following-the-composition-root-pattern-with-enterprise-library.html" target="_blank">blog</a>.</p>
<p>A question that frequently rises when building enterprise applications is: <em>&#8220;Where should we compose object graphs?&#8221; </em>and the answer is given by the Composition Root pattern: <em>&#8220;As close as possible to the applications entry point.&#8221;</em></p>
<p>The Composition Root pattern is described in the excellent <a title="Dependency Injection in .NET (Mark Seemann)" href="http://manning.com/seemann/" target="_blank">book</a>, Dependency Injection in .NET by Mark Seemann.</p>
<p>Here is the definition from the book:<em><br />
</em></p>
<blockquote><p>A Composition Root is a (preferably) unique location in an application where modules are composed together.</p></blockquote>
<p>When working with the Enterprise Library, it is very common to hide the complexities of initial context creation by using the built-in IServiceLocator implementation provided by the <a title="Entry point for the container infrastructure for Enterprise Library." href="http://msdn.microsoft.com/en-us/library/microsoft.practices.enterpriselibrary.common.configuration.enterpriselibrarycontainer(v=pandp.50).aspx" target="_blank">EnterpriseLibraryContainer</a> class.</p>
<p>Since I completely agree with the statement &#8220;<a href="http://blog.ploeh.dk/2010/02/03/ServiceLocatorIsAnAntiPattern.aspx" target="_blank">Service Locator is an Anti-Pattern</a>&#8221; 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.</p>
<p>Fortunately, the EnterpriseLibraryContainer class contains a method named &#8220;ConfigureContainer&#8221; that reads the current configuration and supplies the corresponding type information to configure a dependency injection container (by default Unity).</p>
<p><script src="https://gist.github.com/1123753.js?file=ConfigureContainer.cs"></script></p>
<p>After, configuring the container in the Composition Root we can resolve any instance of a type from Enterprise Library as with any other object.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.upcom.eu/2011/08/03/following-the-composition-root-pattern-with-enterprise-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSF labels and messages from DB</title>
		<link>http://blog.upcom.eu/2011/01/24/jsf-messages-from-db/</link>
		<comments>http://blog.upcom.eu/2011/01/24/jsf-messages-from-db/#comments</comments>
		<pubDate>Mon, 24 Jan 2011 14:50:17 +0000</pubDate>
		<dc:creator>foikonomopoulos</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.upcom.eu/?p=23</guid>
		<description><![CDATA[The following is a step-by-step tutorial on how to implement the retrieval of jsf labels and messages from a database instead of the usual message resource bundles. 1. Create db tables We&#8217;ll create 3 tables, one for the messages (MESSAGE), one &#8230; <a href="http://blog.upcom.eu/2011/01/24/jsf-messages-from-db/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The following is a step-by-step tutorial on how to implement the retrieval of jsf labels and messages from a database instead of the usual message resource bundles.</p>
<p>1. Create db tables</p>
<p>We&#8217;ll create 3 tables, one for the messages (MESSAGE), one for the supported locales (SUPPORTEDLOCALE) and one for the web applications that need localized messages (INTERNALAPPLICATION). The Message table should have columns for id, application name, locale (foreign key - the id of locale table), message key and message value. The SupportedLocale table should have columns for id, locale and locale description. Finally the InternalApplication (INTERNALAPPLICATION) table should have columns for id, application name and locale (foreign key - the id of locale table).</p>
<p>2. Create POJOs</p>
<p>Create 3 classes with attributes mapped by the table columns.</p>
<p>3. Create dao and hibernate mapping</p>
<p>Create 2 methods &#8211; one for retrieving locales (select * from locale) and one for retrieving messages taking as parameter the locale string (select m from Message m join m.supportedLocale sl where sl.locale=?).</p>
<p>Create messages.hbm.xml file for the mapping.</p>
<p>4. Create service</p>
<p>Create 2 methods that each call the appropriate dao method and return transfer objects as a result.</p>
<p>5. Create message provider class</p>
<p>Create a class that extends HashMap and override method get(Object key).</p>
<p>Call the service method to retrieve all locales and for each supported locale create a map that contains the locale string and a map with the key and value (e.g. localeMaps = new HashMap&lt;locale, Map&lt;key, value&gt;&gt;();). Next, call the service method passing the locale as parameter to retrieve the messages and add the key and the value to the map.</p>
<p>Finally, find the current locale of the application and get the corresponding key.</p>
<p>FacesContext context = FacesContext.getCurrentInstance();<br />
String applicationLocale = context.getViewRoot().getLocale().getLanguage();</p>
<p>value = localeMaps.get(applicationLocale).get(key);</p>
<p>In faces-config.xml define a managed bean with name the resource bundle var and &#8216;application&#8217; scope and that&#8217;s it!!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.upcom.eu/2011/01/24/jsf-messages-from-db/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SOA Antipatterns</title>
		<link>http://blog.upcom.eu/2010/06/20/soa-antipatterns/</link>
		<comments>http://blog.upcom.eu/2010/06/20/soa-antipatterns/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 19:52:24 +0000</pubDate>
		<dc:creator>kflokos</dc:creator>
				<category><![CDATA[Service Oriented Architecture (SOA)]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://blog.upcom.eu/?p=19</guid>
		<description><![CDATA[Interesting article in Oracle about SOA anti-patterns. I am tempted to add the lack of real knowledge of what SOA really means and requires. Just like a boy who dares saying in front of his mates that he&#8217;s not aware &#8230; <a href="http://blog.upcom.eu/2010/06/20/soa-antipatterns/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Interesting article in <a href="http://www.oracle.com/goto/soaantipatterns" target="_blank">Oracle </a>about SOA anti-patterns. I am tempted to add the lack of real knowledge of what SOA really means and requires. Just like a boy who dares saying in front of his mates that he&#8217;s not aware of the new football star in town, most IT professionals pretend understanding the benefits of SOA and are willing to work in such an environment, while in reality they do not even know what it is all about.</p>
<p>Solution: Better educate all professionals playing a role in the new architecture or &#8211; even better &#8211; have them participate in pilot implementations of the new architecture.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.upcom.eu/2010/06/20/soa-antipatterns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Update multiple svn repositories from single project</title>
		<link>http://blog.upcom.eu/2009/05/13/update-multiple-svn-repositories-from-single-project/</link>
		<comments>http://blog.upcom.eu/2009/05/13/update-multiple-svn-repositories-from-single-project/#comments</comments>
		<pubDate>Wed, 13 May 2009 04:31:53 +0000</pubDate>
		<dc:creator>kflokos</dc:creator>
				<category><![CDATA[subversion]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[multiple repositories]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://blog.upcom.eu/?p=17</guid>
		<description><![CDATA[Recently, we came across the requirement to develop using our own subversion repository, while updating the client&#8217;s repository every time an iteration completed and delivered. Our initial thoughts were pretty much pessimistic, with doubtful merges and lots of manual work. &#8230; <a href="http://blog.upcom.eu/2009/05/13/update-multiple-svn-repositories-from-single-project/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently, we came across the requirement to develop using our own subversion repository, while updating the client&#8217;s repository every time an iteration completed and delivered.</p>
<p>Our initial thoughts were pretty much pessimistic, with doubtful merges and lots of manual work. Fortunately the following worked without any problem:</p>
<p>Create two working directories:</p>
<ul>
<li>the master one, linked to the internal svn repository. All development takes place in that working directory. Assume that the connect string is something like svn+ssh://user@server/svn/repo1. If necessary do a checkout from that repository: svn co svn+ssh://user@server/svn/repo1</li>
<li>the client one, linked to the client&#8217;s svn repository. Assume that the connect string is something like svn+ssh://clientUser@clientServer/var/svn/clientRepo1. Perform a checkout the first time to make sure the repository location is properly set: svn co svn+shh://clientUser@clientServer/var/svn/clientRepo1</li>
</ul>
<p>At the end of an iteration, commit all the changes from developers working on this iteration. It is assumed that this would be the version delivered to the client for further testing.</p>
<p>Now move to the client&#8217;s directory and perform an export from the internal repository, using the following operation: svn exp svn+ssh://user@server/svn/repo1. That will bring the latest version of the internal repository to the working directory linked to the client repository. Then, just by performing a simple check in we update the client&#8217;s repository with the latest change: svn ci.</p>
<p>The above process works well only in case the client is not performing changes to the repository simultaneously with your team!If this is not the case, more work is required to get those changes back to the master repository!</p>
<p>It may also be used for occasional snapshots of the master repository to guarantee against its potential failures.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.upcom.eu/2009/05/13/update-multiple-svn-repositories-from-single-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Improving Hibernate performance using second level cache</title>
		<link>http://blog.upcom.eu/2009/01/19/improving-hibernate-performance-using-second-level-cache/</link>
		<comments>http://blog.upcom.eu/2009/01/19/improving-hibernate-performance-using-second-level-cache/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 09:20:43 +0000</pubDate>
		<dc:creator>Nikolaos Konstantinou</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://blog.upcom.eu/?p=15</guid>
		<description><![CDATA[There is a trick that pays off when there are ResultSets or entities in a web application that are not updated so often: second-level caching. Getting second-level cache to work means that entities or ResultSets can be stored in the &#8230; <a href="http://blog.upcom.eu/2009/01/19/improving-hibernate-performance-using-second-level-cache/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There is a trick that pays off when there are ResultSets or entities in a web application that are not updated so often: second-level caching. Getting second-level cache to work means that entities or<br />
ResultSets can be stored in the cache and not retrieved from the database in future calls.</p>
<p>There are many cache providers, among them is EhCache which we will be using in this example. In order to get second-level cache to work, first we have to tell hibernate about it. Add this in the hibernate configuration file (hibernate.cfg.xml):</p>
<pre>&lt;property name="cache.provider_class"&gt;org.hibernate.cache.EhCacheProvider&lt;/property&gt;
&lt;property name="cache.use_query_cache"&gt;true&lt;/property&gt;
&lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;</pre>
<div id=":6a" class="ArwC7c ckChnd">These properties tell hibernate that we will be using EhCache for entity and query caching. Then, create a file named ehcache.xml (the default name of the EhCache configuration file) and put it in the same location with hibernate.cfg.xml, typically in the classpath root. A sample configuration for ehcache.xml is the following:</p>
<pre>&lt;ehcache&gt;
&lt;diskStore path="java.io.tmpdir"/&gt;

&lt;defaultCache
maxElementsInMemory="20000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="300"
overflowToDisk="true"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="300"
memoryStoreEvictionPolicy="LRU" /&gt;

&lt;cache name="com.app.entities.City"
maxElementsInMemory="15000"
eternal="true"
overflowToDisk="false" /&gt;
...
&lt;/ehcache&gt;</pre>
<p>In short, this tells EhCache to use the java temp folder and to store a maximum of 20000 entities in the cache (cities for instance). The configuration for each entity overrides the global configuration in the ehcache.xml file. In this example, the global setting defines a TimeToLiveSeconds value which is overriden for the City entities, causing them to be stored eternally in the cache. The same holds for the cache location: global configuration allows the usage of the hard disk but for the entities cached, only the memory will be used (overflowToDisk=false).</p>
<p>But, what happens when an entity changes? There is no problem as long as the entity is configured through hibernate:</p>
<pre>@Entity
<strong>@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)</strong>
public class City {
private Long id;
private String name;
....
}</pre>
<p>The @Cache annotation in this example uses a READ_WRITE strategy, which tells hibernate to update the cache when the entity is updated. If the entity is not so probable to be changed, a read-only strategy will suffice (CacheConcurrencyStrategy.READ_ONLY).</p>
<p>The good part is that ResultSets can be stored as well. Suppose you have a query that returns the most popular cities by country. Define it as cacheable and it will be evaluated against the database only once:</p>
<pre>public List&lt;City&gt; findPopularCitiesByCountryId(Long countryId) {
List&lt;City&gt; cities = session.createQuery("FROM City AS c WHERE
c.country.id=? ORDER BY c.popularity DESC")
<strong>.setCacheable(true)</strong>
.setLong(0, countryId)
.setMaxResults(20)
.list();
return cities;
}</pre>
<p>The trick is the setCacheable property of the query. Running the application in debug mode, you will see in the output for the first time</p>
<pre>[net.sf.ehcache.Cache]-[DEBUG] org.hibernate.cache.StandardQueryCache cache - <strong>Miss</strong>
[org.hibernate.cache.StandardQueryCache]-[DEBUG] query results were not found in cache

[org.hibernate.cache.ReadWriteCache]-[DEBUG] Cache miss: com.app.entities.City#1412
[org.hibernate.event.def.DefaultLoadEventListener]-[DEBUG] object not resolved in any cache</pre>
<p>&#8230;but in subsequent calls you will be happy to see, that even if the query cache fails:</p>
<pre>[net.sf.ehcache.Cache]-[DEBUG] org.hibernate.cache.UpdateTimestampsCache cache - Miss
[org.hibernate.cache.EhCache]-[DEBUG] Element for cities is null</pre>
<p>the entities will be retrieved from the cache:</p>
<pre>[org.hibernate.cache.ReadWriteCache]-[DEBUG] Cache lookup: com.app.entities.City#1412
[org.hibernate.cache.ReadWriteCache]-[DEBUG] <strong>Cache hit</strong>: com.app.entities.City#1412</pre>
<p>There you go, you just boosted your application&#8217;s performance. Take care though, common sense orders that you should only cache ResultSets or entities that are frequently accessed and rarely modified. You can find more info at the official hibernate manual:<br />
<a href="http://www.hibernate.org/hib_docs/v3/reference/en/html/performance.html" target="_blank">http://www.hibernate.org/hib_docs/v3/reference/en/html/performance.html</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.upcom.eu/2009/01/19/improving-hibernate-performance-using-second-level-cache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

