<?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>Udi Dahan - The Software Simplist &#187; Dependency Injection</title>
	<atom:link href="http://www.udidahan.com/category/dependency-injection/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.udidahan.com</link>
	<description>Enterprise Development Expert &#38; SOA Specialist</description>
	<lastBuildDate>Fri, 10 Feb 2012 21:01:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Evolving Loosely-Coupled Frameworks &amp; Apps</title>
		<link>http://www.udidahan.com/2010/07/14/evolving-loosely-coupled-frameworks-and-apps/</link>
		<comments>http://www.udidahan.com/2010/07/14/evolving-loosely-coupled-frameworks-and-apps/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 13:10:18 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[NServiceBus]]></category>
		<category><![CDATA[OO]]></category>
		<category><![CDATA[Simplicity]]></category>

		<guid isPermaLink="false">http://www.udidahan.com/?p=1312</guid>
		<description><![CDATA[This post will be less of a big-concept type posts I usually do, and more of a tip for people building and maintaining infrastructure and frameworks either open-source or internally for their companies. I&#8217;m going to illustrate this with NServiceBus as it is a large enough code base to have significant complexity and open so [...]]]></description>
			<content:encoded><![CDATA[<p>This post will be less of a big-concept type posts I usually do, and more of a tip for people building and maintaining infrastructure and frameworks either open-source or internally for their companies. I&#8217;m going to illustrate this with NServiceBus as it is a large enough code base to have significant complexity and open so that you can go and take a look yourself. Trying to include some example in here would be just too small to be useful or for the point to come across.</p>
<h3>Some background</h3>
<p>As a cohesive framework, NServiceBus makes it quite easy for developers to pick and choose which settings they want turned on and off. Being built as a loosely-coupled set of components that don&#8217;t know about each other has always kept the internal complexity low. But as the NServiceBus API has been evolving over the years, and the functionality offered has increased, some interesting challenges have popped up as the codebase has been refactored. </p>
<h3>The challenge</h3>
<p>The UnicastBus class has grown too large and it&#8217;s time to refactor something out. Coincidentally, users have been asking for a better &#8220;header&#8221; story for messages &#8211; the ability to specify static headers that will be appended to all messages being sent (useful for things like security tokens), as well as per message headers. So, we want to refactor all the header management out to its own component independent of the UnicastBus class.</p>
<p>So, here&#8217;s the issue. So far, users have specified &#8220;.UnicastBus()&#8221; as a part of the fluent code-configuration, and shouldn&#8217;t have to change that &#8211; they shouldn&#8217;t need to know that header management is now a separate component. But then how can the new component bootstrap itself into the startup, such that it gets all the dependency injection facilities of the rest of the framework? Remember that the component doesn&#8217;t know which container technology is being used (since the user can swap it out) or when the container has been set.</p>
<h3>The solution</h3>
<p>The only part of the framework that knows about when all DI configuration is set is the configuration component, thus it will have to be the one that invokes the new component (without knowing about it). Introduce an interface (say INeedInitialization) and scan all the types loaded looking for classes which implement that type, register them into the container, and invoke them. Have the new component implement that interface, and in its initialization have it hook into the events and/or pipelines of other parts of the system.</p>
<h3>Other uses</h3>
<p>One historically problematic area in NServiceBus has been people forgetting to call &#8220;.LoadMessageHandlers()&#8221;. This can now be wired in automatically by a class in the UnicastBus component via the same mechanism.</p>
<p>A new feature coming in the next version is the &#8220;data bus&#8221;, a component which will allow sending large quantities of data through the bus without going through the messaging pipelines. This will help people get around the 4MB limit of MSMQ and, even more importantly, the much smaller 8KB limit of Azure. We will be able to introduce the functionality transparently with the same mechanism.</p>
<p>As an extension point, developers can now enrich the NServiceBus framework with their own capabilities and make those available via the contrib project to the community at large. This is better than the IWantToRunAtStartup interface that was only available for those using the generic host (which excluded web apps) and gives a consistent extensibility story for all uses.</p>
<h3>Summary</h3>
<p>Extensibility has always been a challenge when writing object-oriented code and dependency injection techniques have helped, but sometimes you need a bit more to take things to the next level while maintaining a backwards-compatible API.</p>
<p>Like I said, not a ground-shaking topic but something quite necessary in creating loosely-coupled frameworks and applications. Once you know it&#8217;s there, it isn&#8217;t really a big deal. If you didn&#8217;t know to do it, you may have been contorting your codebase in all kinds of ways to try to achieve similar things.</p>
<p>If you want to take a look at the code, you can find the SVN repository here: https://nservicebus.svn.sourceforge.net/svnroot/nservicebus/trunk/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2010/07/14/evolving-loosely-coupled-frameworks-and-apps/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>External Value Configuration with IoC</title>
		<link>http://www.udidahan.com/2008/06/13/external-value-configuration-with-ioc/</link>
		<comments>http://www.udidahan.com/2008/06/13/external-value-configuration-with-ioc/#comments</comments>
		<pubDate>Fri, 13 Jun 2008 16:32:11 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Simplicity]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2008/06/13/external-value-configuration-with-ioc/</guid>
		<description><![CDATA[One of the things I haven&#8217;t like about using IoC containers, AKA dependency injection frameworks, was the string-based configuration model they exposed. In order to set these values, developers had 2 options: either use XML config (usually without the benefit of intellisense or refactoring support), or use code (still quoting property names &#8211; again, no [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things I haven&#8217;t like about using IoC containers, AKA dependency injection frameworks, was the string-based configuration model they exposed. In order to set these values, developers had 2 options: either use XML config (usually without the benefit of intellisense or refactoring support), or use code (still quoting property names &#8211; again, no intellisense or refactoring support).
<p>In short, there seemed to be a hole in the development model.
<p>Here&#8217;s an example from how nServiceBus used to do this:<br />
<blockquote>
<p>builder.ConfigureComponent(typeof(<b><font color="#800000">HttpTransport</font></b>), <b><font color="#800000">ComponentCallModelEnum</font></b>.Singleton)<br />&nbsp; .ConfigureProperty(&#8221;DefaultNumberOfWorkerThreads&#8221;, 10)<br />&nbsp; .ConfigureProperty(&#8221;DefaultNumberOfSenderThreads&#8221;, 10);</p>
</blockquote>
<p>The problem was that if a developer got the case of the property wrong, misspelled it in some way, or somebody later refactored/renamed that property, the system would break. It would also be very difficult to figure out why.
<p>Then, a couple of weeks ago, it dawned on me.
<p>This was the same problem we used to have with testing using mock objects &#8211; before we had today&#8217;s more advanced frameworks. So, the solution must be to use the same techniques. The container should give the developer an object that looks just like their class, but that would intercept all calls. Then, that interceptor could turn those into the config calls shown above. Here&#8217;s what the new config model looks like:&nbsp;<br />
<blockquote>
<p><b><font color="#800000">HttpTransport</font></b> transport = builder.ConfigureComponent&lt;<b><font color="#800000">HttpTransport</font></b>&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (<b><font color="#800000">ComponentCallModelEnum</font></b>.Singleton);</p>
<p>transport.DefaultNumberOfSenderThreads = 10; <br />transport.DefaultNumberOfWorkerThreads = 10;&nbsp; </p>
</blockquote>
<p>Granted, you&#8217;re not going to have tons of code like this. However, for all those parameters which are factory-configured and that customers/integrators shouldn&#8217;t tinker with, it makes a difference. The biggest difference is during that time of development where you&#8217;ve gotten into preliminary integration tests but the systems components are still being &#8220;polished&#8221;.</p>
<blockquote><p><strong>Aside</strong>: On the current project that has adopted this model, we&#8217;ve probably saved (conservatively) about 3 months of effort with this tiny (?) thing, and this isn&#8217;t a huge project. If that&#8217;s more than you would&#8217;ve thought, well, I was surprised myself. First, understand that in the old config model, everything still compiles and unit tests pass, even though its broken.</p>
<p>Just consider what happens in the lab when this occurs. You have N testers that can&#8217;t test the new version, waiting. You have the person who installed the version, trying to figure out what&#8217;s wrong. They then call in one of the developers where most of the new development occurred since the previous version. They fiddle around with it, looking at exception traces and whatnot. In the best case, we&#8217;re talking about 2 hours from noticing its broken until a new version comes out fixed. Multiply that by N+3 people. Then multiply by the number of versions you do integration tests on in the lab.</p>
</blockquote>
<p><strong>Caveat:</strong> In the current version, properties must be virtual in order for this to work.</p>
<p>For those of you who want just this feature without nServiceBus, I&#8217;ve put up all the binaries <a href="http://cid-c8ad44874742a74d.skydrive.live.com/self.aspx/Blog/Builder.zip">here</a>. For the source, you&#8217;ll need to go to <a href="http://nservicebus.svn.sourceforge.net/viewvc/nservicebus/src/impl/ObjectBuilder.SpringFramework/">here</a>.</p>
<p>Let me know what you think &#8211; especially if you can take the implementation to the point where it won&#8217;t need virtual properties to work <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2008/06/13/external-value-configuration-with-ioc/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Eureka! AOP is the final piece of the multi-threaded smart client puzzle</title>
		<link>http://www.udidahan.com/2007/12/07/eureka-aop-is-the-final-piece-of-the-multi-threaded-smart-client-puzzle/</link>
		<comments>http://www.udidahan.com/2007/12/07/eureka-aop-is-the-final-piece-of-the-multi-threaded-smart-client-puzzle/#comments</comments>
		<pubDate>Fri, 07 Dec 2007 23:01:50 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[AOP]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[NServiceBus]]></category>
		<category><![CDATA[Smart Client]]></category>
		<category><![CDATA[Threading]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/12/07/eureka-aop-is-the-final-piece-of-the-multi-threaded-smart-client-puzzle/</guid>
		<description><![CDATA[If you&#8217;ve read my recent post on the threading issues I&#8217;ve been dealing with in Smart Client Applications, then you&#8217;re probably beginning to get the picture that its fairly complex. To tell you the truth, it is. And up until this point I haven&#8217;t been able to find anything that&#8217;ll help &#8211; and that includes [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve read my recent post on the <a href="http://udidahan.weblogs.us/2007/12/06/object-builder-the-place-to-fix-system-wide-threading-bugs/">threading issues I&#8217;ve been dealing with in Smart Client Applications</a>, then you&#8217;re probably beginning to get the picture that its fairly complex. To tell you the truth, it is. And up until this point I haven&#8217;t been able to find anything that&#8217;ll help &#8211; and that includes the CAB/SCSF. But yesterday I had my epiphany. The answer was in AOP.</p>
<p>You see, the main problem that I hadn&#8217;t been able to solve was that in order for the code to be thread-safe, you had to make sure that no code in the views would/could change entity data. One solution is not to use data-binding, which sucks, but isn&#8217;t enough to be sure. Another solution is to have all supervising-controllers clone an entity before they give it to a view. Even if you could possibly code review every line of those classes, the new guy (or old guy who forgot) will, by accident, write one new line of code that could pass an entity to a view without cloning it first. That&#8217;s not a very sustainable solution.</p>
<p>This thing has been bothering me for a couple of months now and I hadn&#8217;t found a way around it. Until yesterday, like I said. I was talking to somebody about threading stuff, and somehow my unconscience lobbed me this thought about AOP. Now I&#8217;m not the sharpest pencil in the pack, but I know to listen when my unconscience &#8220;speaks&#8221;.</p>
<p>So I set about going over what I knew about AOP &#8211; interceptors, advisors, advice, introductions, etc, etc. And then it dawned on me. I could intercept all calls to any object that implemented IView, check the parameters of those calls, and if they implemented IEntity, to clone them before passing them through.</p>
<p>&lt;Homer-style WOOHOO /&gt;</p>
<p>The great thing is that developers don&#8217;t need to remember to clone entities &#8211; it happens automatically. The even greater thing is that this will lead developers to writing the correct kind of interaction between their views and supervising controllers.</p>
<p>Together with <a href="http://www.nServiceBus.com">nServiceBus</a>, this is going to make the extremely difficult problem of writing thread-safe smart clients possible. </p>
<p>I&#8217;ve never made use of AOP in a framework before so I&#8217;d like to get the broader community&#8217;s feedback on this before incorporating this in production. I&#8217;ve spoken with some serious AOP folks who have allayed most of my uncertainties, but I&#8217;d like to hear more. Anyway, here&#8217;s the <a href="http://udidahan.weblogs.us/wp-content/uploads/aoptest.zip">proof of concept</a> (that makes use of <a href="http://www.springframework.net">Spring</a>). </p>
<p>If this turns out to be a viable solution, I think we&#8217;ll have a solid environment for building a software factory on top of. That is something that I&#8217;m really excited about. In this multi-core future (present) that is upon us, multi-threading on the client is pretty much a necessity. We need a way to get things safe and stable by default without requiring a member of the CLR team to hold our hand.</p>
<p>Anybody who&#8217;s interested in helping, drop a comment below.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/12/07/eureka-aop-is-the-final-piece-of-the-multi-threaded-smart-client-puzzle/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>ObjectBuilder synchronization features needed for pub/sub-ing Smart Clients</title>
		<link>http://www.udidahan.com/2007/09/28/objectbuilder-synchronization-features-needed-for-pubsub-ing-smart-clients/</link>
		<comments>http://www.udidahan.com/2007/09/28/objectbuilder-synchronization-features-needed-for-pubsub-ing-smart-clients/#comments</comments>
		<pubDate>Fri, 28 Sep 2007 21:36:58 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Pub/Sub]]></category>
		<category><![CDATA[Smart Client]]></category>
		<category><![CDATA[Threading]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/09/28/objectbuilder-synchronization-features-needed-for-pubsub-ing-smart-clients/</guid>
		<description><![CDATA[I&#8217;ve been getting some questions from the Dependency Injection folks out there as to why I have my own Object Builder wrapping the framework. There are two very good reasons why I do this:
The first is to insulate the framework and application code that I write from the choice of one dependency injection technology or [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been getting some questions from the Dependency Injection folks out there as to why I have my own Object Builder wrapping the framework. There are two very good reasons why I do this:</p>
<p>The first is to insulate the framework and application code that I write from the choice of one dependency injection technology or another. I want the ability to switch easily from one to the other &#8211; not so much that projects go back and forth. Updating those config files is definitely <i>not</i> easy. However, it allows me to have &#8220;portable&#8221; framework code that is applicable to all the projects I consult on, regardless of their choice of technology.</p>
<p>The second has to do with <a href="http://udidahan.weblogs.us/category/nservicebus/">NServiceBus</a> specifically. In order to make use of duplex communication on smart clients, you need a background thread. That thread will be updating the same (model) objects as the UI thread. That means we need synchronization. I prefer to use .NET&#8217;s built-in synchronization domains in order to solve this rather thorny problem.</p>
<p>The only thing is that message handlers need to be in the synchronization domain so that they can easily update those objects. However, the Bus object must not be in the synchronization domain so that if we&#8217;ve received a large update from the server, we won&#8217;t be locking out the UI thread from interacting with data on the client. </p>
<p>Since the bus makes use of a dependency injection framework to create message handlers, this was the best place to put the code which causes message handlers to run within the synchronization domain.</p>
<p>Be aware that in order to enjoy this feature, you need to split up those large server updates into multiple, logical objects (that implement IMessage), but you can still publish them all in one go using the method: </p>
<p>void Publish(params IMessage[] messages);</p>
<p>And, of course, you need to set the JoinSynchronizationDomain property of the Object Builder.</p>
<p>I&#8217;ll have a podcast coming out on this topic soon.</p>
<p>You can get the code here:</p>
<p><a href='http://udidahan.weblogs.us/wp-content/uploads/objectbuilder.zip' title='Object Builder.zip'>Object Builder.zip</a></p>
<p>But you&#8217;ll have to get the Spring Framework code from the <a href="http://springframework.net/">official site</a>. Make sure you download <a href="http://sourceforge.net/project/showfiles.php?group_id=106751">RC 1.1</a>. Then, take the binaries and copy them to the &#8220;BIN&#8221; folder of the Object Builder solution. If you&#8217;re looking to save on some &#8220;weight&#8221;, you only need &#8220;Spring.Core.dll&#8221;, &#8220;Common.Logging.dll&#8221; and &#8220;antlr.runtime.dll&#8221; for the solution to compile. You will need one of the logging implementations DLLs to get anything written to a log, obviously.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/09/28/objectbuilder-synchronization-features-needed-for-pubsub-ing-smart-clients/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Fetching Strategy NHibernate Implementation Available</title>
		<link>http://www.udidahan.com/2007/09/16/fetching-strategy-nhibernate-implementation-available/</link>
		<comments>http://www.udidahan.com/2007/09/16/fetching-strategy-nhibernate-implementation-available/#comments</comments>
		<pubDate>Mon, 17 Sep 2007 00:54:02 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[Caching]]></category>
		<category><![CDATA[Data Access]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Threading]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/09/16/fetching-strategy-nhibernate-implementation-available/</guid>
		<description><![CDATA[A couple of months ago I put out a post discussing one way to implement custom fetching strategies. Anyway, I finally got around to putting my money where my mouth was&#8230;
So, I&#8217;ve implemented the pattern in NHibernate, adding the following method to ISession:
T Create&#60;T&#62;();
As well as adding the following interface to the NHibernate package:

  [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of months ago I put out a <a href="http://udidahan.weblogs.us/2007/04/23/fetching-strategy-design/">post discussing one way to implement custom fetching strategies</a>. Anyway, I finally got around to putting my money where my mouth was&#8230;</p>
<p>So, I&#8217;ve implemented the pattern in NHibernate, adding the following method to ISession:</p>
<div style="border: solid black 1px; background-color:beige; padding: 0em 1em; overflow:auto; width:550; font-family:courier">T Create&lt;T&gt;();</div>
<p>As well as adding the following interface to the NHibernate package:</p>
<div style="border: solid black 1px; background-color:beige; padding: 0em 1em; overflow:auto; width:550; font-family:courier">
    public interface IFetchingStrategy&lt;T&gt;<br />
    {<br />
        ICriteria AddFetchJoinTo(ICriteria criteria);<br />
    }
</div>
<p>All this enables you to have a stronger separation between your service layer classes and your domain model class, as well as for you to express each service-level use case as a domain concept &#8211; an interface.</p>
<p>Once you have such an interface, you can create a fetching strategy for that use case and define exactly how deep of an object graph you want to load so that you only hit the DB once for that use case.</p>
<p>The nice thing is that its all configured with Spring. In other words, if you the entry for your fetching strategy class exists, you get the improved performance, if it doesn&#8217;t, you don&#8217;t. All without touching your service layer classes.</p>
<p>Just as an example, when I&#8217;m in the use case modeled by &#8220;ICustomer&#8221;, I want to get all the customer&#8217;s orders, and their orderlines. This would be done by having a class like this:</p>
<div style="border: solid black 1px; background-color:beige; padding: 0em 1em; overflow:auto; width:550; font-family:courier">
    public class CustomerFetchingStrategy : IFetchingStrategy&lt;ICustomer&gt;<br />
    {<br />
        public ICriteria AddFetchJoinTo(ICriteria criteria)<br />
        {<br />
            criteria.SetFetchMode(&#8221;orders&#8221;, FetchMode.Eager).<br />
                SetFetchMode(&#8221;orders.orderLines&#8221;, FetchMode.Eager);</p>
<p>            return criteria;<br />
        }<br />
    }
</p></div>
<p>And the configuration would look like this (as a part of the regular spring template):</p>
<div style="border: solid black 1px; background-color:beige; padding: 0em 1em; overflow:auto; width:550; font-family:courier">
      &lt;object id=&#8221;CustomerFetchingStrategy&#8221; type=&#8221;Domain.Persistence.CustomerFetchingStrategy, Domain.Persistence&#8221; /&gt;
</div>
<p>If you want to take a look at the full solution, you can find it here. For some reason, the combined file was too big for the upload on my blog so it&#8217;s split into two. Unzip both packages into the same directory. You&#8217;ll find a file called &#8220;db_scripts.sql&#8221; which contains the schema for the DB. Don&#8217;t forget to update your connection string in the &#8220;hibernate.cfg.xml&#8221;. If you&#8217;re looking for the changes I made to the NHibernate source, you can find it in the &#8220;Updated NHibernate Files&#8221; directory. The only real change is to the &#8220;SessionImpl.cs&#8221; file.</p>
<p><a href='http://udidahan.weblogs.us/wp-content/uploads/libraries.zip' title='libraries.zip'>Relevant NHibernate and Spring binaries</a>.</p>
<p><a href='http://udidahan.weblogs.us/wp-content/uploads/objectrelationalmappingdemo4.zip' title='objectrelationalmappingdemo.zip'>Source code of example</a>.</p>
<p>BTW, there is some intelligent thread-safe caching going on in SessionImpl now so that you get a much smaller performance hit (in terms of code that uses reflection) on subsequent usages of the same interfaces.</p>
<p>Let me know what you think.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/09/16/fetching-strategy-nhibernate-implementation-available/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>NServiceBus Distributed Topology Q&amp;A</title>
		<link>http://www.udidahan.com/2007/08/25/nservicebus-distributed-topology-qa/</link>
		<comments>http://www.udidahan.com/2007/08/25/nservicebus-distributed-topology-qa/#comments</comments>
		<pubDate>Sat, 25 Aug 2007 08:37:26 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[BizTalk]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[ESB]]></category>
		<category><![CDATA[MSMQ]]></category>
		<category><![CDATA[NServiceBus]]></category>
		<category><![CDATA[Pub/Sub]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/08/25/nservicebus-distributed-topology-qa/</guid>
		<description><![CDATA[I&#8217;ve been receiving more and more questions about how NServiceBus fits in distributed systems and wanted to share them:

My question is about distributed topology.
The EAI-hub-and-spoke model is all about the central server.   It’s useful sometimes, but there are a lot of reasons why I’m not gung-ho on using a hub as the center [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been receiving more and more questions about how NServiceBus fits in distributed systems and wanted to share them:</p>
<blockquote><p>
My question is about distributed topology.</p>
<p>The EAI-hub-and-spoke model is all about the central server.   It’s useful sometimes, but there are a lot of reasons why I’m not gung-ho on using a hub as the center of the integration universe.  </p>
<p>The ESB distributed model puts code on the endpoints.  That code solves some of the messaging problems that apps face, so that apps don’t have to face them. It also solves some of the messaging problems that enterprises face, so that enterprises don’t have to face them.  (I need both).</p>
<p>Those problems include simple coding and deployment model, pub-sub routing, reliable transport, simple transformation, and orchestration.  I wonder which of these you can do in your tool, and which you are planning to do.  </p>
<p>I’m also interested in management.  How do you insure that the endpoints are correctly configured?  Do you have a central configuration store?  How do you propagate changes from the center to the messaging endpoints?
</p></blockquote>
<p>And here&#8217;s my response:</p>
<p>The important parts of NServiceBus that are independent of the distributed topology are the API and the connection to long-running workflow. This code is indeed on the endpoint. However, if you wanted to you could easily connect to something like BizTalk and do whatever you wanted there. This general idea though is to support the ESB distributed model since <a href="udidahan.weblogs.us/2007/06/30/no-such-thing-as-a-centralized-esb/">there&#8217;s no such things as a centralized ESB</a>.</p>
<p>In terms of the capabilities you’ve mentioned, I’ve seen developers pick up the coding model in a day or two. The deployment model is just a bunch of DLLs you deploy with each endpoint. Dependency Injection is supported by www.SpringFramework.net but you can replace that with something else easily as another implementation of the ObjectBuilder interfaces. </p>
<p>Currently pub/sub routing is supported over regular point-to-point transports in a transport agnostic way. You also have the ability to have subscriptions be persisted so that even if a server restarts (and clients don’t, and can’t know about that) all the subscriptions will be remembered. </p>
<p>The reliable transport that is currently supported is MSMQ, with the option of defining per-message type if you want durable messaging (using the [Recoverable] attribute). </p>
<p>In terms of orchestration you get a nice model for long-running workflow that gets kicked off by messages decorated with the [StartsWorkflow] attribute, and messages that implement the IWorkflowMessage interface get automatically routed to the persistent workflow instance. You have the ability to change the storage of workflow instances easily as well. Workflows are simple classes which are easily unit-testable in that they expose a “void Handle(T message);” method for every message type (T) that is involved in the workflow.</p>
<p>I haven’t done anything in terms of simple transformation yet but am currently looking for the right place in the message processing pipeline to put it. I also haven’t done anything yet in terms of management. </p>
<p>What is currently being done management-wise on the projects that use it are the commercial options for managing configuration files in distributed environments coupled with the regular ability to restart windows services and IIS applications. I haven’t seen anything lacking in that solution yet.</p>
<hr size="1" />
<p>If you have any questions, please don&#8217;t hesitate to send them my way &#8211; <a href="mailto:NServiceBus@UdiDahan.com">NServiceBus@UdiDahan.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/08/25/nservicebus-distributed-topology-qa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Are fewer assemblies really better?</title>
		<link>http://www.udidahan.com/2007/06/19/are-fewer-assemblies-really-better/</link>
		<comments>http://www.udidahan.com/2007/06/19/are-fewer-assemblies-really-better/#comments</comments>
		<pubDate>Tue, 19 Jun 2007 20:59:52 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/19/are-fewer-assemblies-really-better/</guid>
		<description><![CDATA[If you&#8217;ve read Scott Hanselman&#8217;s great post Some guiding principles for Software Development, you&#8217;ve probably seen his point about &#8220;Fewer assemblies is better&#8221;, and might be thinking that you&#8217;ve seen me write about this before. If so, you&#8217;re absolutely right.
Here are some choice quotes:

In the end, you should see bunches of projects/dlls which go together, [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve read Scott Hanselman&#8217;s great post <a href="http://www.hanselman.com/blog/SomeGuidingPrinciplesForSoftwareDevelopment.aspx">Some guiding principles for Software Development</a>, you&#8217;ve probably seen his point about &#8220;Fewer assemblies is better&#8221;, and might be thinking that you&#8217;ve seen me write about this before. If so, you&#8217;re absolutely right.</p>
<p>Here are some choice quotes:</p>
<blockquote><p>
In the end, you should see bunches of projects/dlls which go together, while between the bunches there is almost no dependence whatsoever. The boundaries between bunches will almost always be an interface project/dll.</p>
<p>This will have the pleasant side-effect of enabling concurrent development of bunches with developers hardly ever stepping on each other’s toes. Actually, the number of projects in a given developer’s solution will probably decrease, since they no longer have to deal with all parts of the system.
</p></blockquote>
<p>Taken from <a href="http://udidahan.weblogs.us/2005/11/27/so-many-dlls-so-little-time/">So many Dlls, so little time</a>.</p>
<p>And from a more recent post, <a href="http://udidahan.weblogs.us/2006/06/24/one-wrong-dll-3-months-gone/">One wrong DLL = 3 months gone</a>:</p>
<blockquote><p>
Obviously, if there is less source to go through, the programmer will, on average, find the origin of the defect faster. And, as we all know, it usually takes longer to find the bug than to actually fix it.</p>
<p>So, by splitting up different classes and interfaces into different DLLs, we can manage dependencies in the system so that less source needs to be examined.
</p></blockquote>
<p>However, if you did want to roll up all these DLLs into fewer physical files, you could do just that using the tool <a href="http://research.microsoft.com/~mbarnett/ILMerge.aspx">ILMerge</a>. This might make sense as a part of getting your software ready for installation. Also, access to client computers that are having problems might make you consider this.</p>
<h3>Bottom Line</h3>
<p>I&#8217;d say <b>more</b> assemblies is generally better, and merge when necessary &#8211; but don&#8217;t change your design on that account.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/06/19/are-fewer-assemblies-really-better/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Performant and Explicit Domain Models</title>
		<link>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/</link>
		<comments>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/#comments</comments>
		<pubDate>Mon, 04 Jun 2007 20:31:34 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Business Rules]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Data Access]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[OO]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Simplicity]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Threading]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/04/performant-and-explicit-domain-models/</guid>
		<description><![CDATA[Some Technical Difficulties

Ayende and I had an email conversation that started with me asking what would happen if I added an Order to a Customer’s &#8220;Orders&#8221; collection, when that collection was lazy loaded. My question was whether the addition of an element would result in NHibernate hitting the database to fill that collection. His answer [...]]]></description>
			<content:encoded><![CDATA[<h4>Some Technical Difficulties</h4>
<p style="padding: 0em 1em;">
Ayende and I had an email conversation that started with me asking what would happen if I added an Order to a Customer’s &#8220;Orders&#8221; collection, when that collection was lazy loaded. My question was whether the addition of an element would result in NHibernate hitting the database to fill that collection. His answer was a simple &#8220;yes&#8221;. In the case where a customer can have many (millions) of Orders, that’s just not a feasible solution. The technical solution was simple – just define the Orders collection on the Customer as &#8220;inverse=true&#8221;, and then to save a new Order, just write:
</p>
<div style="border: solid black 1px; padding: 0em 1em; background-color:beige; font-family:courier; ">session.Save( new Order(myCustomer) );</div>
<p style="padding: 0em 1em;">
Although it works, it’s not &#8220;DDD compliant&#8221; <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
</p>
<p style="padding: 0em 1em;">
In Ayende’s post <a href="http://ayende.com/Blog/archive/2007/05/29/Architecting-for-Performance.aspx">Architecting for Performance</a> he quoted a part of our email conversation.  The conclusion I reached was that in order to design performant domain models, you need to know the kinds of data volumes you’re dealing with. It affects both internals and the API of the model – when can you assume cascade, and when not. It’s important to make these kinds of things explicit in the Domain Model’s API.
</p>
<h4>How do you make &#8220;transparent persistence&#8221; explicit?</h4>
<p style="padding: 0em 1em;">
The problem occurs around &#8220;transparent persistence&#8221;. If we were to assume that the Customer object added the Order object to its Orders collection, then we wouldn’t have to explicitly save orders it creates, so we would write service layer code like this:
</p>
<div style="border: solid black 1px; background-color:beige; padding: 0em 1em; overflow:auto; width:600; font-family:courier">
using (IDBScope scope = this.DbServices.GetScope(TransactionOption.On))<br />
{<br />
	IOrderCreatingCustomer c = this.DbServices.Get&lt;IOrderCreatingCustomer&gt;(msg.CustomerId);<br />
	c.CreateOrder(message.OrderAmount);</p>
<p>	scope.Complete();<br />
}
</p></div>
<p style="padding: 0em 1em;">
On the other hand, if we designed our Domain Model around the million orders constraint, we would need to explicitly save the order, so we would write service layer code like this:
</p>
<div style="border: solid black 1px; background-color:beige; padding: 0em 1em; overflow:auto; width:600; font-family:courier">
using (IDBScope scope = this.DbServices.GetScope(TransactionOption.On))<br />
{<br />
	IOrderCreatingCustomer c = this.DbServices.Get&lt;IOrderCreatingCustomer&gt;(msg.CustomerId);<br />
	IOrder o = c.CreateOrder(message.OrderAmount);<br />
	this.DbServices.Save(o);</p>
<p>	scope.Complete();<br />
}
</p></div>
<p style="padding: 0em 1em;">
But the question remains, how do we communicate these guidelines to service layer developers from the Domain Model? There are a number of ways, but it’s important to decide on one and use it consistently. Performance and correctness require it.
</p>
<h4>Solution 1: Explicitness via Return Type</h4>
<p style="padding: 0em 1em;">
The first way is a little subtle, but you can do it with the return type of the &#8220;CreateOrder&#8221; method call. In the case where the Domain Model wishes to communicate that it handles transparent persistence by itself, have the method return &#8220;void&#8221;. Where the Domain Model wishes to communicate that it will not handle transparent persistence, have the method return the Order object created.
</p>
<p style="padding: 0em 1em;">
Another way to communicate the fact that an Order has been created that needs to be saved is with events. There are two sub-ways to do so:
</p>
<h4>Solution 2: Explicitness via Events on Domain Objects</h4>
<p style="padding: 0em 1em;">
The first is to just define the event on the customer object and have the service layer subscribe to it. It’s pretty clear that when the service layer receives a &#8220;OrderCreatedThatRequiresSaving&#8221; event, it should save the order passed in the event arguments.
</p>
<p style="padding: 0em 1em;">
The second realizes that the call to the customer object may come from some other domain object and that the service layer doesn’t necessarily know what can happen as the result of calling some method on the aggregate root. The change of state as the result of that method call may permeate the entire object graph. If each object in the graph raises its own events, its calling object will have to propagate that event to its parent – resulting in defining the same events  in multiple places, and each object being aware of all things possible with its great-grandchild objects. That is clearly bad.
</p>
<h4>What [ThreadStatic] is for</h4>
<p style="padding: 0em 1em;">
So, the solution is to use thread-static events.
</p>
<p style="padding: 0em 1em;">
[Sidebar] Thread-static events are just static events defined on a static class, where each event has the ThreadStaticAttribute applied to it. This attribute is important for server-side scenarios where multiple threads will be running through the Domain Model at the same time. The easiest thread-safe way to use static data is to apply the ThreadStaticAttribute.
</p>
<h4>Solution 3: Explicitness via Static Events</h4>
<p style="padding: 0em 1em;">
Each object raises the appropriate static event according to its logic. In our example, Customer would call:
</p>
<div style="border: solid black 1px; background-color:beige; padding: 0em 1em; font-family:courier">
DomainModelEvents.RaiseOrderCreatedThatRequiresSavingEvent(newOrder);
</div>
<p style="padding: 0em 1em;">And the service layer would write:</p>
<div style="border: solid black 1px; background-color:beige; padding: 0em 1em; font-family:courier">
DomainModelEvents.OrderCreatedThatRequiresSaving +=<br />
	delegate(object sender, OrderEventArgs e) { this.DbServices.Save(e.Order); };
</div>
<p style="padding: 0em 1em;">
The advantage of this solution is that it requires minimal knowledge of the Domain Model for the Service Layer to correctly work with it. It also communicates that anything that doesn’t raise an event will be persisted transparently behind the appropriate root object.
</p>
<h4>Statics and Testability</h4>
<p style="padding: 0em 1em;">
I know that many of you are wondering if I am really advocating the use of statics. The problem with most static classes is that they hurt testability because they are difficult to mock out. Often statics are used as Facades to hide some technological implementation detail. In this case, the static class is an inherent part of the Domain Model and does not serve as a Facade for anything.
</p>
<p style="padding: 0em 1em;">
When it comes to testing the Domain Model, we don’t have to mock anything out since the Domain Model is independent of all other concerns. This leaves us with unit testing at the single Domain Class level, which is pretty useless unless we’re TDD-ing the design of the Domain Model, in which case we’ll still be fiddling around with a bunch of classes at a time. Domain Models are best tested using State-Based Testing; get the objects into a given state, call a method on one of them, assert the resulting state. The static events don’t impede that kind of testing at all.
</p>
<h4>What if we used Injection instead of Statics?</h4>
<p style="padding: 0em 1em;">
Also, you’ll find that each Service Layer class will need to subscribe to all the Domain Model’s events, something that is easily handled by a base class. I will state that I have tried doing this without a static class, and injecting that singleton object into the Service Layer classes, and in that setter having them subscribe to its events. This was also pulled into a base class. The main difference was that the Dependency Injection solution required injecting that object into Domain Objects as well. Personally, I’m against injection for domain objects. So all in all, the static solution comes with less overhead than that based on injection.
</p>
<h4>Summary</h4>
<p style="padding: 0em 1em;">
In summary, beyond the &#8220;technical basics&#8221; of being aware of your data volumes and designing your Domain Model to handle each use case performantly, I’ve found these techniques useful for designing its API as well as communicating my intent around persistence transparency. So give it a try. I’d be grateful to hear your thoughts on the matter as well as what else you’ve found that works.
</p>
<p><u style="padding: 0em 1em;">Related posts:</u></p>
<ul style="padding: 0em 1em;">
<li>
<a href="http://udidahan.weblogs.us/2007/04/23/fetching-strategy-design/">Fetching Strategy Design</a> &#8211; showing how to separate the concern of eager loading from both your Domain Model and your Service Layer.
</li>
<li>
<a href="http://udidahan.weblogs.us/2007/03/06/better-domain-driven-design-implementation/">Better Domain-Driven Design Implementation</a> &#8211; showing the basics of how valuable interfaces between your Domain Model and the Service Layer can be.
</li>
<li>
<a href="http://udidahan.weblogs.us/2007/04/15/lazy-loading-and-how-messaging-fixes-everything-again/">Lazy Loading, and how messaging fixes everything again</a> &#8211; describing the advantage of O/R mapping your message classes as well.
</li>
<li>
<a href="http://udidahan.weblogs.us/2007/03/28/query-objects-vs-methods-on-a-repository/">Query Objects vs Methods on a Repository</a> &#8211; discussing the scalability (in terms of number of developers and queries) of Query Objects.
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Interfaces solve visibility and testing issues</title>
		<link>http://www.udidahan.com/2007/06/04/interfaces-solve-visibility-and-testing-issues/</link>
		<comments>http://www.udidahan.com/2007/06/04/interfaces-solve-visibility-and-testing-issues/#comments</comments>
		<pubDate>Mon, 04 Jun 2007 09:09:07 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[OO]]></category>
		<category><![CDATA[Simplicity]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/04/interfaces-solve-visibility-and-testing-issues/</guid>
		<description><![CDATA[Jimmy&#8217;s recent post called out some of the insights on the advantages of Ruby from Niclas&#8217; keynote at DevSummit 2007. Jimmy writes:

In Ruby it&#8217;s easy to redefine the visibility of a method from private to public for testing purposes. This was just one small detail in his talk of course, but I started to think [...]]]></description>
			<content:encoded><![CDATA[<p>Jimmy&#8217;s <a href="http://jimmynilsson.com/blog/posts/Devsummit2007b.htm">recent post</a> called out some of the insights on the advantages of Ruby from <a href="http://niclasnilsson.se/">Niclas&#8217; keynote at DevSummit 2007</a>. Jimmy writes:</p>
<blockquote><p>
In Ruby it&#8217;s easy to redefine the visibility of a method from private to public for testing purposes. This was just one small detail in his talk of course, but I started to think about how much pain I quite often go through regarding this in legacy code.
</p></blockquote>
<p>Let me just start out by saying that dealing with legacy code is far from easy. However, when writing new code, or as a part of refactoring that legacy, adding interfaces to your design can help you get around those visibility and testing issues.</p>
<p>For instance, if you only let &#8220;client&#8221; code access the interface, and not the implementation (probably using some kind of <a href="http://udidahan.weblogs.us/category/dependency-injection/">dependency injection</a>), then you could leave all sorts of methods public on your concrete class without worry that the client will call them since the interface doesn&#8217;t expose them. Now that the methods on the concrete class are public, you can easily test that class.</p>
<p>The way to package your code to make sure this occurs follows a <a href="http://udidahan.weblogs.us/2007/05/12/first-principle-of-design-refined/">very simple design principle</a>. This is much easier to put in practice on new development, but you&#8217;ll find that it isn&#8217;t that hard for legacy either. Since legacy code often doesn&#8217;t make use of interfaces, and the implementation is already packaged, and your new client code will already be separately packaged, you&#8217;re 90% there!</p>
<p>If you can change the legacy code, you&#8217;re actually 95% there. Just create a new package for the interface that the client code will use. Then change the legacy code to implement that interface &#8211; since the methods will be pretty much the same, it&#8217;s not that much work.</p>
<p>If you can&#8217;t change the legacy code, create a &#8220;wrapper&#8221; class that implements the interface and delegates the calls to the legacy code.</p>
<p>Finally, let me sum up by saying that I think Ruby is great. However, I think that often many advantages are attributed to anything new that may have already been possible/easy with what we already have today. Sometimes, the new stuff helps raise awareness on important issues &#8211; and then we can have great discussions on how to solve those issues with today&#8217;s (yesterday&#8217;s ?) technology <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/06/04/interfaces-solve-visibility-and-testing-issues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Frictionless Design</title>
		<link>http://www.udidahan.com/2007/05/14/frictionless-design/</link>
		<comments>http://www.udidahan.com/2007/05/14/frictionless-design/#comments</comments>
		<pubDate>Mon, 14 May 2007 07:21:32 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[OO]]></category>
		<category><![CDATA[Simplicity]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/05/14/frictionless-design/</guid>
		<description><![CDATA[From Ryan&#8217;s post on scaling Rails with multiple databases, he raises a point near and dear to my heart around the use of well designed frameworks (apparently sourced by Joe):

When referring to framework and tooling, &#8220;friction&#8221; is a (subjective) measure of how much the tooling gets in your way when trying to solve a specific-case [...]]]></description>
			<content:encoded><![CDATA[<p>From Ryan&#8217;s post on scaling Rails with multiple databases, he raises a point near and dear to my heart around the use of <a href="http://tomayko.com/weblog/2007/04/13/rails-multiple-connections">well designed frameworks</a> (apparently sourced by <a href="http://bitworking.org/news/160/Scaling-Matters-Twitter">Joe</a>):</p>
<blockquote><p>
When referring to framework and tooling, &#8220;friction&#8221; is a (subjective) measure of how much the tooling gets in your way when trying to solve a specific-case problem. I&#8217;ve come to evaluate frameworks based on two rough metrics: how far the framework goes in solving the general case problem out of the box and how little friction the framework creates when you have to solve the specific-case problem yourself. When a framework finds a balance between these two areas, we call it &#8220;well designed.&#8221;
</p></blockquote>
<p>It has been my experience that when I follow my <a href="http://udidahan.weblogs.us/2007/05/12/first-principle-of-design-refined/">first principle of design</a>, a good separation of logical packages occurs. These packages enable an appropriate level of flexibility by interacting via interfaces and supporting <a href="http://udidahan.weblogs.us/category/dependency-injection/">Dependency Injection</a>. Of course, a fierce focus on assigning responsibility correctly probably makes quite a difference too. I suppose this is why I shoot for multiple smaller frameworks, than one large one. Beyond being easier to <a href="http://udidahan.weblogs.us/2006/06/24/one-wrong-dll-3-months-gone/">manage in terms of version control</a> and supporting across multiple projects and products, they&#8217;re also quite a bit easier to develop.</p>
<p>Finally, consider that the code you&#8217;re writing is someone else&#8217;s framework/API. For people looking for more advanced API design techniques, check out <a href="http://www.martinfowler.com/bliki/FluentInterface.html">fluent interfaces</a> as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/05/14/frictionless-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First principle of design refined</title>
		<link>http://www.udidahan.com/2007/05/12/first-principle-of-design-refined/</link>
		<comments>http://www.udidahan.com/2007/05/12/first-principle-of-design-refined/#comments</comments>
		<pubDate>Sat, 12 May 2007 16:10:17 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Simplicity]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/05/12/first-principle-of-design-refined/</guid>
		<description><![CDATA[I&#8217;ve been trying over time to distill core principles that when followed lead to high quality designs. So far, I&#8217;ve only got one that I&#8217;ve been polishing. Here&#8217;s a reminder:

For any classes A and B in a system, A should interact with B through an interface.
The interface which separates two concrete classes should be packaged [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been trying over time to distill core principles that when followed lead to high quality designs. So far, I&#8217;ve only <a href="http://udidahan.weblogs.us/2006/01/29/udis-first-principle-of-design/">got one</a> that <a href="http://udidahan.weblogs.us/2006/02/07/revisiting-udis-first-principle-of-design/">I&#8217;ve been polishing</a>. Here&#8217;s a reminder:</p>
<blockquote><p>
For any classes A and B in a system, A should interact with B through an interface.</p>
<p>The interface which separates two concrete classes should be packaged separately from either of those classes.
</p></blockquote>
<p>OK, so where do I go around these principles?</p>
<p>Well, concrete MessageHandler classes directly use concrete message classes. I don&#8217;t think of this as a problem because message classes are really just Data Transfer Objects &#8211; classes with no behavior.</p>
<p>So here&#8217;s the refined principle:</p>
<blockquote><p>
For any classes A and B in a system where both A and B have behavior, A should interact with B through an interface.</p>
<p>The interface which separates two concrete classes should be packaged separately from either of those classes.
</p></blockquote>
<p>That feels better. It holds for Views interacting with Controllers, MessageHandlers with Messages, even <a href="http://udidahan.weblogs.us/2007/04/23/fetching-strategy-design/">interactions with Domain Classes</a>.</p>
<p>What do you think? Does this hold for the way you design your systems? Are there scenarios where you think this principle is too general? Let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/05/12/first-principle-of-design-refined/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Generic Validation</title>
		<link>http://www.udidahan.com/2007/04/30/generic-validation/</link>
		<comments>http://www.udidahan.com/2007/04/30/generic-validation/#comments</comments>
		<pubDate>Mon, 30 Apr 2007 21:54:26 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[OO]]></category>
		<category><![CDATA[Simplicity]]></category>
		<category><![CDATA[Smart Client]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/04/30/generic-validation/</guid>
		<description><![CDATA[Ayende brought up the topic of Input &#038; Business Rule Validation and I wanted to post how I solve this issue.
On kind of input validation is something you do as close to the user as possible for performance reasons. This includes all sorts of smart stuff you can do with JavaScript in Web scenarios. When [...]]]></description>
			<content:encoded><![CDATA[<p>Ayende brought up the topic of <a href="http://ayende.com/Blog/archive/2007/04/02/Input-Validation-vs.Business-Rules-Validation.aspx">Input &#038; Business Rule Validation</a> and I wanted to post how I solve this issue.</p>
<p>On kind of input validation is something you do as close to the user as possible for performance reasons. This includes all sorts of smart stuff you can do with JavaScript in Web scenarios. When in a <a href="http://udidahan.weblogs.us/category/smart-client/">Smart Client</a> environment, you usually have greater capabilities.</p>
<p>When I look at the issue of validation, I see that it centers around the entity. Sometimes, it is also affected by other things, like what process are we in (as described in the comments on Ayende&#8217;s post).</p>
<p>So, we can model the thing that validates an entity with an interface, say, IValidator&lt;T&gt; where T : IEntity. This interface will have one main method: bool IsValid(T entity); and one main property: string ErrorDescription { get; }</p>
<p>What this allows us to do is to separate out different validation concerns into different classes, yet have all of them implement the same interface.</p>
<p>The next thing we&#8217;ll need is to be able to get an instance for each of the classes that is a validator for a specific kind of entity. For instance, when the NewCustomerView raises an event proclaiming that it has a Customer object ready to be saved, the Controller will want to find all classes that implement IValidator&lt;Customer&gt; so that it can run all the validation rules.</p>
<p>Luckily, the <a href="http://udidahan.weblogs.us/2007/04/09/advanced-object-creation-with-dependency-injection/">generics patch</a> I put out for the <a href="http://www.springframework.net">Spring.Net Framework</a> allows us to do this in one simple line of code:</p>
<pre>
IList&lt;IValidator&lt;Customer&gt;&gt; validators = spring.GetObjectsOfType(typeof(IValidator&lt;Customer&gt;));
</pre>
<p>and quite simply perform the validation as follows:</p>
<pre>
foreach(IValidator&lt;Customer&gt; v in validators)
&nbsp;&nbsp;if (!v.IsValid(myCustomer))
&nbsp;&nbsp;&nbsp;&nbsp;// notify user with v.ErrorDescription, write to log, whatever
</pre>
<p>Now, when using this in Smart Client scenarios, you will often have views that allow the user to enter in a single entity which you will then want to validate. If you have those views implement a generic interface like: IEntityView&lt;T&gt; where T : IEntity, then you could have a single base class implement a &#8220;Validate&#8221; method, which would perform the work above generically like so:</p>
<pre>
foreach(IValidator&lt;T&gt; v in spring.GetObjectsOfType(typeof(IValidator&lt;T&gt;)))
&nbsp;&nbsp;if (!v.IsValid(this.Entity))
&nbsp;&nbsp;&nbsp;&nbsp;// notify user with v.ErrorDescription
</pre>
<p>and just have your specific view call that method on the button click.</p>
<p>This enables all entity views to activate all the relevant custom validation logic without being tied to it. It also enables you to extend your system by adding new classes implementing the IValidator&lt;T&gt; interface, and have them automatically run without even changing a config file. How&#8217;s that for loose coupling?</p>
<p>Finally, on the issue of tying validation rules to specific processes, this can be done by extending the interface to: IValidator&lt;T, P&gt; where T : IEntity, P : IProcess; You then model each process with a marker interface. You then have your specific validation classes implement the above generic interface for each specific process interface. For instance, say we have a validation rule that needs to run for processes P1 (marked by IP1), and P2 (marked by IP2), but not P3 (marked by IP3), which validates entities of type E. This would be done by defining the class like so:</p>
<pre>
public class MyValidator : IValidator&lt;E, IP1&gt;, IValidator&lt;E, IP2&gt; {}
</pre>
<p>and the Controller class that would request validators for process 2 would just call:</p>
<pre>
spring.GetObjectsOfType(typeof(IValidator&lt;T, IP2&gt;));
</pre>
<p>That&#8217;s it. The basic principles are simple, but, as you can see, can create very powerful structures. I&#8217;ve got to say that this exemplifies one of the reasons why I love generics so much. When used with <a href="http://udidahan.weblogs.us/category/dependency-injection/">Dependency Injection</a>, and/or Delegates, and/or Anonymous Methods, you get such a power of expression just by defining an interface. This is one of things that make coding fun for me. Or maybe I&#8217;m just wierd that way <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/04/30/generic-validation/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Advanced Object Creation with Dependency Injection</title>
		<link>http://www.udidahan.com/2007/04/09/advanced-object-creation-with-dependency-injection/</link>
		<comments>http://www.udidahan.com/2007/04/09/advanced-object-creation-with-dependency-injection/#comments</comments>
		<pubDate>Mon, 09 Apr 2007 21:25:11 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/04/09/advanced-object-creation-with-dependency-injection/</guid>
		<description><![CDATA[This is something that I’ve been running into more and more and have gotten tired of working around. Here’s an example scenario:
I have an interface like ICustomer, which inherits from IEntity, another interface, and a third interface IValidator&#60;T&#62; where T : IEntity. I also have a class CustomerValidator which inherits from IValidator&#60;ICustomer&#62; and a class [...]]]></description>
			<content:encoded><![CDATA[<p><P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT face=Calibri>This is something that I’ve been running into more and more and have gotten tired of working around. Here’s an example scenario:<o:p></o:p></FONT></SPAN></P><br />
<P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT face=Calibri>I have an interface like ICustomer, which inherits from IEntity, another interface, and a third interface IValidator&lt;T&gt; where T : IEntity. I also have a class CustomerValidator which inherits from IValidator&lt;ICustomer&gt; and a class GenericValidator which inherits from IValidator&lt;IEntity&gt;.<o:p></o:p></FONT></SPAN></P><br />
<P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT face=Calibri>When I ask the dependency injection framework for objects like this:<o:p></o:p></FONT></SPAN></P><br />
<P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT face=Calibri>diFramework.GetObjectsOfType(typeof(IValidator&lt;ICustomer&gt;));<o:p></o:p></FONT></SPAN></P><br />
<P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT face=Calibri>I only get back an instance of CustomerValidator, where I want to also get back an instance of GenericValidator.<o:p></o:p></FONT></SPAN></P><br />
<P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT face=Calibri>The reason is that most DI frameworks use the basic “IsAssignableFrom” method to check for supporting types. This check isn’t broad enough to handle the above generics.<o:p></o:p></FONT></SPAN></P><br />
<P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT face=Calibri>I’ve passed </FONT><A href="http://udidahan.weblogs.us/wp-content/uploads/2007/04/generics_supported.zip"><FONT face=Calibri>the code that does this check</FONT></A><FONT face=Calibri> along to the guys at </FONT><A href="http://www.springframework.net/"><FONT face=Calibri>www.SpringFramework.net</FONT></A><FONT face=Calibri> so that they can incorporate it into their next release. Please feel free to forward this code on to any of the other DI frameworks out there. Code is licensed under the 2-clause BSD License:<o:p></o:p></FONT></SPAN></P><br />
<DIV style="BORDER-RIGHT: #2f6fab 1pt dashed; PADDING-RIGHT: 12pt; BORDER-TOP: #2f6fab 1pt dashed; PADDING-LEFT: 12pt; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 12pt; BORDER-LEFT: #2f6fab 1pt dashed; PADDING-TOP: 12pt; BORDER-BOTTOM: #2f6fab 1pt dashed; mso-element: para-border-div; mso-border-alt: dashed #2F6FAB .5pt"><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">* Copyright (c) 2007, Udi Dahan<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">* All rights reserved.<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">*<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">* Redistribution and use in source and binary forms, with or without<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">* modification, are permitted provided that the following conditions are met:<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">*<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>* Redistributions of source code must retain the above copyright<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">*<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>notice, this list of conditions and the following disclaimer.<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">*<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>* Redistributions in binary form must reproduce the above copyright<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">*<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>notice, this list of conditions and the following disclaimer in the<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">*<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>documentation and/or other materials provided with the distribution.<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">*<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>* Neither the name of&nbsp;UdiDahan.com nor the<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">*<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>names of its contributors may be used to endorse or promote products<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">*<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>derived from this software without specific prior written permission.<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">*<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">* THIS SOFTWARE IS PROVIDED BY Udi Dahan “AS IS” AND ANY<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">* DISCLAIMED. IN NO EVENT SHALL Udi Dahan BE LIABLE FOR ANY<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 0pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS<o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; BACKGROUND: #f9f9f9; PADDING-BOTTOM: 0cm; MARGIN: 0cm 0cm 7.2pt; BORDER-LEFT: medium none; LINE-HEIGHT: 13.2pt; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: dashed #2F6FAB .5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; mso-padding-alt: 12.0pt 12.0pt 12.0pt 12.0pt"><SPAN lang=EN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB">* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<o:p></o:p></SPAN></P></DIV><br />
<P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN style="mso-ansi-language: EN"><o:p><FONT face=Calibri>&nbsp;</FONT></o:p></SPAN></P></p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/04/09/advanced-object-creation-with-dependency-injection/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Careful how you inject those dependencies</title>
		<link>http://www.udidahan.com/2006/05/21/careful-how-you-inject-those-dependencies/</link>
		<comments>http://www.udidahan.com/2006/05/21/careful-how-you-inject-those-dependencies/#comments</comments>
		<pubDate>Mon, 22 May 2006 04:56:29 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/286</guid>
		<description><![CDATA[When using dependency injection, you often find two different kinds of scenarios that are common - singleton and single-call, which match the lifetime of the objects being injected. If the object you're currently working on needs a reference to a repository, the main form, or something like that, you'll probably expose either a setter, or accept the reference in a constructor argument. This is the primary area where DI shines enabling lower levels of coupling between classes than before.
<br/><br/>
However, when your object needs to instantiate a new object at runtime the story changes slightly. For instance, you wouldn't want your UI controller to have a reference to a concrete form so that you could better test it. However, there must be some other way to inject that dependency - neither a setter or a constructor argument.
<br/><br/>
In my opinion, this is no longer DI, but rather something of a deferred object construction. Instead of your code "newing" up the concrete class, you defer that to something else, the DI framework. Indeed, all the frameworks I'm aware of support this.
<br/><br/>
One of the most common ways this construction is done is for your code to ask for the object by name. Since the DI framework needs a way to identify objects/classes for wiring purposes, every object gets a name in the config file. So, in order to get a new instance of the customer form you would write code like this:
<br/><br/>
ICustomerForm f = springContext.GetObject("CustomerForm") as ICustomerForm;
<br/><br/>
Where, in the config file, CustomerForm is defined to be a single-call object, meaning that a new instance is created every time "GetObject" is called for it.
<br/><br/>
And this works great. So you go and implement all your UI controllers similarly. In fact, any place you need to create an object, you do the same - all your programmers do. And you all pat yourselves on the back what a fantastically loosely-coupled system you've created.
<br/><br/>
Until, one day, that very same code blows up...]]></description>
			<content:encoded><![CDATA[<p>When using dependency injection, you often find two different kinds of scenarios that are common &#8211; singleton and single-call, which match the lifetime of the objects being injected. If the object you&#8217;re currently working on needs a reference to a repository, the main form, or something like that, you&#8217;ll probably expose either a setter, or accept the reference in a constructor argument. This is the primary area where DI shines enabling lower levels of coupling between classes than before.</p>
<p>However, when your object needs to instantiate a new object at runtime the story changes slightly. For instance, you wouldn&#8217;t want your UI controller to have a reference to a concrete form so that you could better test it. However, there must be some other way to inject that dependency &#8211; neither a setter or a constructor argument.</p>
<p>In my opinion, this is no longer DI, but rather something of a deferred object construction. Instead of your code &#8220;newing&#8221; up the concrete class, you defer that to something else, the DI framework. Indeed, all the frameworks I&#8217;m aware of support this.</p>
<p>One of the most common ways this construction is done is for your code to ask for the object by name. Since the DI framework needs a way to identify objects/classes for wiring purposes, every object gets a name in the config file. So, in order to get a new instance of the customer form you would write code like this:</p>
<p>ICustomerForm f = springContext.GetObject(&#8221;CustomerForm&#8221;) as ICustomerForm;</p>
<p>Where, in the config file, CustomerForm is defined to be a single-call object, meaning that a new instance is created every time &#8220;GetObject&#8221; is called for it.</p>
<p>And this works great. So you go and implement all your UI controllers similarly. In fact, any place you need to create an object, you do the same &#8211; all your programmers do. And you all pat yourselves on the back what a fantastically loosely-coupled system you&#8217;ve created.</p>
<p>Until, one day, that very same code blows up. The call to GetObject returns null. You check the config file, the entry is there. You check that class file that it references, the Dlls are there. You check constructor parameters, and everything&#8217;s fine. You go and check it on a different machine and it works. Go back to the first machine, it doesn&#8217;t.</p>
<p>AAAAAARRRRRRRGGGGGGGHHHHHH!!!!</p>
<p>Hours later, somebody (maybe a tester) walks by and sees you peering at the config file looking for salvation. He comments &#8220;I thought the &#8216;f&#8217; in Customerform was supposed to be uppercase&#8221;. You shout, and then cry, and laugh, some more crying, make the fix, and go home.</p>
<p>Hopefully, you reach the same conclusion that I did. Those strings are evil. The compiler does not check them. Neither do the unit tests. Chances are the acceptance tests don&#8217;t either. You must never embed a string in your source code which must be identical to some other string outside the source for the system to work. Alas, the string passed to &#8220;GetObject&#8221; is just such a string.</p>
<p>The solution is simple, once you&#8217;ve returned to the problem. Since the UI controller only knows about ICustomerForm, it must ask the DI framework to give it the object that implements ICustomerForm. That code knows nothing else, so it cannot ask for anything else. Since, by design, in a given deployment you will only have one object that fulfills the role of ICustomerForm, you&#8217;re all set.</p>
<p>Ay, there&#8217;s the rub.</p>
<p>In your design, the interfaces whose implementations you will need to be able to create in a single-call fashion must be such that they do not get used in different, single-call scenarios. Otherwise, when asking for the object who implements ICustomerForm, you could get several, but only one of them is correct (not that you can know at runtime which one). Therein is the constraint on the solution to the correct problem.</p>
<p>The code for spring.net, wrapped in IObjectBuilder, looks like this:</p>
<pre>
    public class Builder : IBuilder
    {
        #region IBuilder Members

        public object Build(Type interfaceType)
        {
            Spring.Context.IApplicationContext ctx = Spring.Context.Support.ContextRegistry.GetContext();

            System.Collections.IDictionary dict = ctx.GetObjectsOfType(interfaceType, true, false);

            System.Diagnostics.Debug.Assert(dict.Count == 1,
                "Should only be one type that implements " + interfaceType.FullName,
                "Types found: " + this.GetTypeNames(dict.Values));

            System.Collections.IDictionaryEnumerator de = dict.GetEnumerator();
            return (de.MoveNext() ? de.Value : null);
        }

        public InterfaceType Build&lt;InterfaceType&gt;() where InterfaceType : class
        {
            return this.Build(typeof(InterfaceType)) as InterfaceType;
        }

        #endregion

        private string GetTypeNames(System.Collections.ICollection iCollection)
        {
            StringBuilder sb = new StringBuilder();

            foreach (Type t in iCollection)
            { sb.Append(t.FullName); sb.Append(", "); }

            return sb.ToString();
        }
    }</pre>
<p>Anyway, like the title says, careful with those injections. You wouldn&#8217;t want to introduce other, hidden (string-based) dependencies as a result of removing todays (class-based) ones.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2006/05/21/careful-how-you-inject-those-dependencies/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>So many Dlls, so little time</title>
		<link>http://www.udidahan.com/2005/11/27/so-many-dlls-so-little-time/</link>
		<comments>http://www.udidahan.com/2005/11/27/so-many-dlls-so-little-time/#comments</comments>
		<pubDate>Mon, 28 Nov 2005 03:37:41 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/233</guid>
		<description><![CDATA[The other day, one of the leads on a project I'm architecting asked me why I insisted on "so many" dlls. In his opinion, increasing the number of "moving parts" would just make things more complicated. It wasn't the first time I was asked this question, so I thought I'd think it over a bit more this time.
<BR/><BR/>
I think that it's a reasonable and expected response. What's wrong with what we're doing now? How is dividing it up more going to make it better?
<BR/><BR/>
Before I get into the reasoning, the end result needs to be examined.
<BR/><BR/>
Have you ever had a case where you used a dll (let's call it A) which depended on B, which in turn depended on C. In your project/dll you also use C directly. I'd be willing to bet that almost everyone has run into this scenario. This is the path to dll hell, more appropriately named versioning hell. It is at the root of many an integration gone bad. Reminds me of the commercials "when you sleep with your friend, your also sleeping with all your friend's friends, and their friends..." and so on.
<BR/><BR/>
The hell above is the result of sloppiness. Sloppiness with dependencies. If two classes are independent of each other, and do not provide different implementations of the same interface, think twice about putting them in the same project/dll. Minimizing dependencies is the bread and butter of loose coupling. Break dependence on implementations by introducing interfaces in a separate project/dll.
<BR/><BR/>
Do it over, and over, and over again.
<BR/><BR/>
* You don't necessarily have to code, in order to refactor your design.
<BR/><BR/>
In the end, you should see bunches of projects/dlls which go together, while between the bunches there is almost no dependence whatsoever. The boundaries between bunches will almost always be an interface project/dll.
<BR/><BR/>
This will have the pleasant side-effect of enabling concurrent development of bunches with developers hardly ever stepping on each other's toes. Actually, the number of projects in a given developer's solution will probably decrease, since they no longer have to deal with all parts of the system.
<BR/><BR/>
Bottom line: design is about managing dependencies between classes and dlls.]]></description>
			<content:encoded><![CDATA[<p>The other day, one of the leads on a project I&#8217;m architecting asked me why I insisted on &#8220;so many&#8221; dlls. In his opinion, increasing the number of &#8220;moving parts&#8221; would just make things more complicated. It wasn&#8217;t the first time I was asked this question, so I thought I&#8217;d think it over a bit more this time.</p>
<p>I think that it&#8217;s a reasonable and expected response. What&#8217;s wrong with what we&#8217;re doing now? How is dividing it up more going to make it better?</p>
<p>Before I get into the reasoning, the end result needs to be examined.</p>
<p>Have you ever had a case where you used a dll (let&#8217;s call it A) which depended on B, which in turn depended on C. In your project/dll you also use C directly. I&#8217;d be willing to bet that almost everyone has run into this scenario. This is the path to dll hell, more appropriately named versioning hell. It is at the root of many an integration gone bad. Reminds me of the commercials &#8220;when you sleep with your friend, your also sleeping with all your friend&#8217;s friends, and their friends&#8230;&#8221; and so on.</p>
<p>The hell above is the result of sloppiness. Sloppiness with dependencies. If two classes are independent of each other, and do not provide different implementations of the same interface, think twice about putting them in the same project/dll. Minimizing dependencies is the bread and butter of loose coupling. Break dependence on implementations by introducing interfaces in a separate project/dll.</p>
<p>Do it over, and over, and over again.</p>
<p>* You don&#8217;t necessarily have to code, in order to refactor your design.</p>
<p>In the end, you should see bunches of projects/dlls which go together, while between the bunches there is almost no dependence whatsoever. The boundaries between bunches will almost always be an interface project/dll.</p>
<p>This will have the pleasant side-effect of enabling concurrent development of bunches with developers hardly ever stepping on each other&#8217;s toes. Actually, the number of projects in a given developer&#8217;s solution will probably decrease, since they no longer have to deal with all parts of the system.</p>
<p>Bottom line: design is about managing dependencies between classes and dlls.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2005/11/27/so-many-dlls-so-little-time/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Don, Spring, OR mapping, Lazy Loading, in a short post</title>
		<link>http://www.udidahan.com/2004/11/23/don-spring-or-mapping-lazy-loading-in-a-short-post/</link>
		<comments>http://www.udidahan.com/2004/11/23/don-spring-or-mapping-lazy-loading-in-a-short-post/#comments</comments>
		<pubDate>Wed, 24 Nov 2004 00:47:54 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Data Access]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[OO]]></category>
		<category><![CDATA[Simplicity]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/130</guid>
		<description><![CDATA[After listening to the DNR episode with Don, Ted, and Mark I got to thinking about the issue of lazy loading in OR mappers. This was unanimously(?) described as being one of the imperfections inherent in the O/R mapping world. What I wondered was if that TransparentProxy could be used somehow to work around it. [...]]]></description>
			<content:encoded><![CDATA[<p>After listening to the DNR episode with <a href="http://pluralsight.com/blogs/dbox/">Don</a>, <a href="http://www.neward.net/ted/weblog/index.jsp">Ted</a>, and Mark I got to thinking about the issue of <a href="http://udidahan.weblogs.us/2007/04/15/lazy-loading-and-how-messaging-fixes-everything-again/">lazy loading</a> in OR mappers. This was unanimously(?) described as being one of the imperfections inherent in the <a href="http://udidahan.weblogs.us/category/nhibernate/">O/R mapping</a> world. What I wondered was if that TransparentProxy could be used somehow to work around it. I submit this to the ObjectSpaces gods as an open question &#8211; how are you guys going about it?</p>
<p>There is a different, more <a href="http://udidahan.weblogs.us/category/oo/">OO</a> way of handling this. By separating out the interface of the class you want to be lazy loaded &#8211; make an IPerson interface &#8211; and have the client code be tied to that. In that way, your <a href="http://udidahan.weblogs.us/category/dependency-injection/">dependency injection container</a> (<a href="http://www.springFramework.net">Spring</a>, for example) could instantiate an implementation that handles lazy loading without the client having to know about it. This implementation is absolutely something that could be handled by an OR mapping tool.</p>
<p>So, I suppose that even some of the more difficult problems of OR mapping could be handled. All that is needed is not to add more to the tool itself, but rather to more formally structure how to work with it. My opinion, anyway.</p>
<p><B><U>Update</U></B></p>
<p>The next part around the discussion about lazy loading and <a href="http://udidahan.weblogs.us/2007/03/06/better-domain-driven-design-implementation/">fetching strategies</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2004/11/23/don-spring-or-mapping-lazy-loading-in-a-short-post/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

