<?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/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Autofac</title>
	<atom:link href="http://autofac.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://autofac.wordpress.com</link>
	<description>tangled in .NET</description>
	<lastBuildDate>Sun, 11 Nov 2007 02:39:14 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='autofac.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/69b1cba4c559bda2012e2f67c24db183?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Autofac</title>
		<link>http://autofac.wordpress.com</link>
	</image>
			<item>
		<title>Autofac .NET IoC Container Released</title>
		<link>http://autofac.wordpress.com/2007/11/11/autofac-net-ioc-container-released/</link>
		<comments>http://autofac.wordpress.com/2007/11/11/autofac-net-ioc-container-released/#comments</comments>
		<pubDate>Sun, 11 Nov 2007 02:39:14 +0000</pubDate>
		<dc:creator>autofac</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://autofac.wordpress.com/2007/11/11/autofac-net-ioc-container-released/</guid>
		<description><![CDATA[If you&#8217;re looking for the Autofac .NET IoC container, head on over to the project site.
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autofac.wordpress.com&blog=945275&post=20&subd=autofac&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>If you&#8217;re looking for the Autofac .NET IoC container, head on over to <a href="http://autofac.googlecode.com">the project site</a>.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/autofac.wordpress.com/20/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/autofac.wordpress.com/20/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/autofac.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/autofac.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/autofac.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/autofac.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/autofac.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/autofac.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/autofac.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/autofac.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/autofac.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/autofac.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autofac.wordpress.com&blog=945275&post=20&subd=autofac&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://autofac.wordpress.com/2007/11/11/autofac-net-ioc-container-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9cd28d4fa0a481cf6408ed7677755650?s=96&#38;d=identicon" medium="image">
			<media:title type="html">autofac</media:title>
		</media:content>
	</item>
		<item>
		<title>Autofac has moved!</title>
		<link>http://autofac.wordpress.com/2007/07/17/autofac-has-moved/</link>
		<comments>http://autofac.wordpress.com/2007/07/17/autofac-has-moved/#comments</comments>
		<pubDate>Tue, 17 Jul 2007 10:48:19 +0000</pubDate>
		<dc:creator>autofac</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://autofac.wordpress.com/2007/07/17/autofac-has-moved/</guid>
		<description><![CDATA[With the launch of the new Ubik Systems website only days away, I&#8217;ve started adding new posts directly to that site. Come on over and take a look! Nick.
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autofac.wordpress.com&blog=945275&post=19&subd=autofac&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>With the launch of the new <a href="http://ubik.com.au">Ubik Systems</a> website only days away, I&#8217;ve started adding new posts directly to that site. Come on over and take a look! Nick.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/autofac.wordpress.com/19/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/autofac.wordpress.com/19/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/autofac.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/autofac.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/autofac.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/autofac.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/autofac.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/autofac.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/autofac.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/autofac.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/autofac.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/autofac.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autofac.wordpress.com&blog=945275&post=19&subd=autofac&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://autofac.wordpress.com/2007/07/17/autofac-has-moved/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9cd28d4fa0a481cf6408ed7677755650?s=96&#38;d=identicon" medium="image">
			<media:title type="html">autofac</media:title>
		</media:content>
	</item>
		<item>
		<title>Service Locator vs. Dependency Injection</title>
		<link>http://autofac.wordpress.com/2007/07/08/service-locator-vs-dependency-injection/</link>
		<comments>http://autofac.wordpress.com/2007/07/08/service-locator-vs-dependency-injection/#comments</comments>
		<pubDate>Sun, 08 Jul 2007 01:50:03 +0000</pubDate>
		<dc:creator>autofac</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://autofac.wordpress.com/2007/07/08/service-locator-vs-dependency-injection/</guid>
		<description><![CDATA[Something I have come back to a few times when explaining the benefits of Dependency Injection is how the pattern relates to Service Locator. Martin Fowler thinks  Service Locator is a better choice when you&#8217;re building a single application, while Dependency Injection can be more appropriate otherwise.
You can get a good idea of how [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autofac.wordpress.com&blog=945275&post=17&subd=autofac&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Something I have come back to a few times when explaining the benefits of <em>Dependency Injection</em> is how the pattern relates to <em>Service Locator</em>. <a href="http://www.martinfowler.com/articles/injection.html">Martin Fowler thinks </a> Service Locator is a better choice when you&#8217;re building a single application, while Dependency Injection can be more appropriate otherwise.</p>
<p>You can get a good idea of how the two patterns work by reading his article. I don&#8217;t agree with his conclusion, in part because when setting out to build an application you often end up building a small suite of related apps: the main front-end you always intended to write, perhaps some administrative tools, perhaps some data import tools, perhaps some back-end services that run on a schedule. Once this happens, Dependency Injection beats Service Locator hands-down.</p>
<p>The oft-quoted drawback of Service Locator is that all the components depend on the locator. To me this isn&#8217;t a big deal. The problem dependency that Service Locator introduces is a much larger-scale one &#8211; the components, through the keys that they use to locate associated services, create an implied system architecture that is hard to change from outside the components themselves.</p>
<p>For a simple example, let&#8217;s say the Authenticator component and the Auditor component both look up the service &#8220;logger&#8221;. By using the simple key &#8220;logger&#8221; in both cases, these components implicitly depend on the same object. In a different environment, we may require the the Auditor logs to the database, and the Authenticator logs by sending email to an administrator. Using a service locator we have a couple of choices:</p>
<ol>
<li>Use a different scheme for the keys, e.g. &#8220;logger/authenticator&#8221; and &#8220;logger/auditor&#8221; &#8211; now our &#8217;simple&#8217; service locator is getting more complex and we have to sort out in advance how our service naming scheme works.</li>
<li>Build the flexibility into the logger &#8211; use different log sinks for different sources. This isn&#8217;t a bad option, but is essentially a case of moving general functionality out of our architecture into specific functionality within the components, thus adding more complexity to the system.</li>
<li>Change the Authenticator and Auditor so that they can be initialised with a specific logger when the application starts up.</li>
</ol>
<p>To me, option number 3 is the common-sense choice: after all, it makes use of the most basic features of the programming language we&#8217;re working in and saves us from creating our own more complex structures on top of the language.</p>
<p>Coincidentally <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  option number 3 is Dependency Injection. By having all of our components accept their dependencies as constructor or property arguments, they can be wired up in arbitrary ways without any need for code changes.</p>
<p>That&#8217;s really as far as you have to take dependency injection &#8211; and while the application is small, your startup code can just create and wire up components as needed. Beats Service Locator for the simple fact that you&#8217;re sticking to the built-in dependency mechanisms of your programming language, and later on, if you want to use a dependency injection framework to simplify the configuration code, you can do so without changing your components.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/autofac.wordpress.com/17/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/autofac.wordpress.com/17/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/autofac.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/autofac.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/autofac.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/autofac.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/autofac.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/autofac.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/autofac.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/autofac.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/autofac.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/autofac.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autofac.wordpress.com&blog=945275&post=17&subd=autofac&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://autofac.wordpress.com/2007/07/08/service-locator-vs-dependency-injection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9cd28d4fa0a481cf6408ed7677755650?s=96&#38;d=identicon" medium="image">
			<media:title type="html">autofac</media:title>
		</media:content>
	</item>
		<item>
		<title>When all you&#8217;ve got is a hammer&#8230;</title>
		<link>http://autofac.wordpress.com/2007/05/26/when-all-youve-got-is-a-hammer/</link>
		<comments>http://autofac.wordpress.com/2007/05/26/when-all-youve-got-is-a-hammer/#comments</comments>
		<pubDate>Sat, 26 May 2007 00:43:18 +0000</pubDate>
		<dc:creator>autofac</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://autofac.wordpress.com/2007/05/26/when-all-youve-got-is-a-hammer/</guid>
		<description><![CDATA[Platform and language monoculture is a big issue in established software companies today. Perhaps a lack of it is one of the defining factors identifying the new &#8216;agile&#8217; development outfits that have popped up so far this decade.
The Java and Microsoft &#8217;shops&#8217; are the best examples &#8211; companies that are willing, through principles of economy, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autofac.wordpress.com&blog=945275&post=10&subd=autofac&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Platform and language monoculture is a big issue in established software companies today. Perhaps a lack of it is one of the defining factors identifying the new &#8216;agile&#8217; development outfits that have popped up so far this decade.</p>
<p>The Java and Microsoft &#8217;shops&#8217; are the best examples &#8211; companies that are willing, through principles of economy, to put all of their eggs in the one technological basket.</p>
<p>I recently overheard: &#8220;we can&#8217;t adopt application X because that would require training someone in Java.&#8221; Perhaps that is the reason that training is so often only given lip service and is considered to be of little real value? Training in a new facet of a platform you already know doesn&#8217;t really take you anywhere new. Significant insights most often come to me when I step back from my own work and see how other people are tackling the same problems.</p>
<p>Familiarity with multiple platforms and tools can give you a lead over the competition. NUnit, CruiseControl.NET and NHibernate have been being used effectively for quite a while now, <em>by the .NET developers who looked over the fence and saw the advantages being enjoyed in Java-land.</em> Microsoft have finally come to the party with Team Foundation Server and Linq to Entities &#8211; but now the competitive advantage is gone and a new set of not-so-secret weapons is needed to stay ahead.</p>
<p>The rationale for keeping the set of technologies in use in any one development team small is a sound one, but I think that taking this wisdom without a healthy grain of salt can lead to mediocre systems built using sub-optimal tools.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/autofac.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/autofac.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/autofac.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/autofac.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/autofac.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/autofac.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/autofac.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/autofac.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/autofac.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/autofac.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/autofac.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/autofac.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autofac.wordpress.com&blog=945275&post=10&subd=autofac&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://autofac.wordpress.com/2007/05/26/when-all-youve-got-is-a-hammer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9cd28d4fa0a481cf6408ed7677755650?s=96&#38;d=identicon" medium="image">
			<media:title type="html">autofac</media:title>
		</media:content>
	</item>
		<item>
		<title>John says I&#8217;d better explain&#8230;</title>
		<link>http://autofac.wordpress.com/2007/05/10/john-says-id-better-explain/</link>
		<comments>http://autofac.wordpress.com/2007/05/10/john-says-id-better-explain/#comments</comments>
		<pubDate>Thu, 10 May 2007 12:34:31 +0000</pubDate>
		<dc:creator>autofac</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://autofac.wordpress.com/2007/05/10/john-says-id-better-explain/</guid>
		<description><![CDATA[&#8230;what an &#8216;FBox&#8217; is&#8230;
The FBox source code is the implementation behind this article. Why not elaborate a bit more&#8230;
The &#8216;Factory&#8217; patterns (Factory Method, Abstract Factory&#8230;) can be really useful. For every class or hierarchy of classes that you&#8217;ll be creating from different pieces of code, you define another class (the factory) that is responsible for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autofac.wordpress.com&blog=945275&post=7&subd=autofac&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>&#8230;what an &#8216;FBox&#8217; is&#8230;</p>
<p>The FBox source code is the implementation behind <a href="http://autofac.wordpress.com/2007/04/03/function-containers-a-cheap-hack/">this article</a>. Why not elaborate a bit more&#8230;</p>
<p>The &#8216;Factory&#8217; patterns (Factory Method, Abstract Factory&#8230;) can be really useful. For every class or hierarchy of classes that you&#8217;ll be creating from different pieces of code, you define another class (the <em>factory</em>) that is responsible for instantiating and initialising the <em>product</em>s. Then, if the creation requirements of the product change, there is only one piece of code that needs to be updated. E.g.:<br />
<code><br />
// The Person class is the product.<br />
class Person<br />
{<br />
&nbsp;&nbsp;public Person(string name) { ... }<br />
}</p>
<p>// PersonFactory has one responsibility - to create People<br />
class PersonFactory<br />
{<br />
&nbsp;&nbsp;public Person Create(string name)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;return new Person(name);<br />
&nbsp;&nbsp;}<br />
}</p>
<p>// Later...<br />
PersonFactory factory = new PersonFactory();<br />
Person john = factory.Create("John");<br />
</code><br />
OK so despite the obvious need for a biology lesson, what&#8217;s going on here is really simple. If we ever need to add steps to the creation process, it is easy to change the Create() method without affecting the pieces of code that use it:<br />
<code><br />
public Person Create(string name)<br />
{<br />
&nbsp;&nbsp;Person result = new Person(name);<br />
&nbsp;&nbsp;Logger.Log("Created new person named: " + name);<br />
&nbsp;&nbsp;return result;<br />
}<br />
</code><br />
Or even more interesting:<br />
<code><br />
class FreakyPerson : Person { ... }<br />
...<br />
public Person Create(string name)<br />
{<br />
&nbsp;&nbsp;if (name == "John")<br />
&nbsp;&nbsp;&nbsp;&nbsp;return new FreakyPerson(...);<br />
&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;return new Person(name);<br />
}<br />
</code><br />
In the second example, we introduced a whole new class &#8211; a subclass of person &#8211; that we&#8217;ll create under certain conditions but which the original users of the factory don&#8217;t need to know exists at all! With a lot of pieces of code potentially creating Person objects, this could be very inconvenient to do had we not used the factory.</p>
<p>Generally you&#8217;d only bother with a factory if you knew or suspected that you would need to vary the actual concrete implementation in this way. Unfortunately you can&#8217;t always foresee the kinds of changes that could be elegantly made with such facilities in place.</p>
<p>Anyway &#8211; the downside to using a factory, of course, is that it introduces quite a bit more code that in 99% of cases won&#8217;t do anything interesting. The example factory above is extremely oversimplified: most of the time, this kind of factory (a Factory Method) would be implemented using several classes and interfaces, with the associated plumbing to put it all together. With the appropriate using declarations, namespacing, etc, that could be 50 lines of code. You could just create one giant Factory class, with a method for every kind of product (CreatePerson(), CreateCat(), CreateMouse()) but that is going to create a large amount of coupling &#8211; everything dependent on the factory &#8211; and won&#8217;t be much fun in modular systems where Cat and Mouse aren&#8217;t even defined in the same assemblies&#8230;</p>
<p>&#8230;which is why you don&#8217;t see Factory being used extensively in real applications except those big fat overblown &#8216;enterprisey&#8217; monstrosities that we all want to steer clear of.</p>
<p>I think that&#8217;s a shame, because the benefits in terms of flexibility and elimination of repetition can be great. Isn&#8217;t DRY (Don&#8217;t Repeat Yourself) something of a mantra within the agile movement? <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>FBox is pretty simple but might solve this dilemma. You need to create an FBox for every family of related products you&#8217;re going to create (I should mention at this point &#8211; the class that implements FBox is called &#8216;FunctionContainer&#8217;):<br />
<code><br />
FunctionContainer animalFactory = new FunctionContainer();<br />
</code><br />
You might create one FBox for domain objects like animals, one for GUI widgets, etc. &#8211; these could be static properties on a particular class &#8211; whatever.</p>
<p>The next step (we&#8217;re creating factories for Person, Cat and Mouse) is to declare a delegate that takes the place of the &#8216;Create&#8217; method in a traditional factory:<br />
<code><br />
delegate Person CreatePerson(string name);<br />
delegate Cat CreateCat(string name, Color color);<br />
delegate Mouse CreateMouse(int whiskers);<br />
</code><br />
You then implement these &#8216;factories&#8217; by registering a simple lambda expression implementing each delegate:<br />
<code><br />
animalFactory.RegisterFunction&lt;CreatePerson&gt;(<br />
&nbsp;&nbsp;name =&gt; new Person(name));<br />
animalFactory.RegisterFunction&lt;CreateCat&gt;(<br />
&nbsp;&nbsp;(name, color)=&gt;new Cat(name, color));<br />
...<br />
</code><br />
So each factory has cost us two lines of code. To use the factory, we just get it out of the FBox and call it:<br />
<code><br />
Cat tiger = animalFactory.Func&lt;CreateCat&gt;().Call("Tiger", Color.Gray);<br />
</code><br />
(My Tiger is of a non-standard hue&#8230;)</p>
<p>The great thing about this implementation over other &#8216;generic&#8217; factory approaches is that the Call(&#8230;) statement above is strongly typed. It requires a string and a Color parameter &#8211; if these are not provided, you&#8217;ll get an error at compile time rather than runtime.</p>
<p>To break it down:</p>
<p>1. animalFactory.Func&lt;CreateCat&gt;() looks up the expression that we registered: (name, color) =&gt; new Cat(name, color). It gets returned wrapped up in an object that exposes it through a property called &#8216;Call&#8217;.</p>
<p>2. Call(&#8220;Tiger&#8221;, Color.Gray) retrieves our expression from the Call property, and invokes it with the parameters we&#8217;ve given.</p>
<p>The actual code that creates the cat is the expression we registered using animalFactory.RegisterFunction().</p>
<p>Two lines of code probably isn&#8217;t too much to ask in return for a lot of flexibility. Let&#8217;s say we need to do more than just create an instance of the Cat class. The solution is simple &#8211; create a fully-blown function to do the work:<br />
<code><br />
class CatFactory<br />
{<br />
&nbsp;&nbsp;public static Cat CreateCat(string name, Color color)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;// Do whatever needs to be done to create a cat...<br />
&nbsp;&nbsp;}<br />
}<br />
</code><br />
&#8230;and register it instead of the original expression:<br />
<code><br />
animalFactory.RegisterFunction&lt;CreateCat&gt;(<br />
&nbsp;&nbsp;new CreateCat(CatFactory.CreateCat));<br />
</code><br />
The old code that we used to create our tiger will now use the new CatFactory.CreateCat function instead of the simple expression. Voila! You can even vary the actual function used at runtime&#8230;</p>
<p>I&#8217;ve never used this in an app, and never seen it done elsewhere (tell me if you do!) so I can&#8217;t say I&#8217;ve explored the possibilities or the drawbacks.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/autofac.wordpress.com/7/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/autofac.wordpress.com/7/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/autofac.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/autofac.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/autofac.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/autofac.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/autofac.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/autofac.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/autofac.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/autofac.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/autofac.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/autofac.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autofac.wordpress.com&blog=945275&post=7&subd=autofac&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://autofac.wordpress.com/2007/05/10/john-says-id-better-explain/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9cd28d4fa0a481cf6408ed7677755650?s=96&#38;d=identicon" medium="image">
			<media:title type="html">autofac</media:title>
		</media:content>
	</item>
		<item>
		<title>FBox source code online</title>
		<link>http://autofac.wordpress.com/2007/05/07/fbox-source-code-online/</link>
		<comments>http://autofac.wordpress.com/2007/05/07/fbox-source-code-online/#comments</comments>
		<pubDate>Mon, 07 May 2007 00:12:42 +0000</pubDate>
		<dc:creator>autofac</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://autofac.wordpress.com/2007/05/07/fbox-source-code-online/</guid>
		<description><![CDATA[Just for the morbidly curious   the source code for the FBox function container can be downloaded here. It is built using the Orcas March CTP but the library itself could be compiled under VS2005.
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autofac.wordpress.com&blog=945275&post=6&subd=autofac&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Just for the morbidly curious <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  the source code for the FBox function container can be downloaded <a href="http://www.ubiksystems.com/download/fbox.zip">here</a>. It is built using the Orcas March CTP but the library itself could be compiled under VS2005.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/autofac.wordpress.com/6/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/autofac.wordpress.com/6/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/autofac.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/autofac.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/autofac.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/autofac.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/autofac.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/autofac.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/autofac.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/autofac.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/autofac.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/autofac.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autofac.wordpress.com&blog=945275&post=6&subd=autofac&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://autofac.wordpress.com/2007/05/07/fbox-source-code-online/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9cd28d4fa0a481cf6408ed7677755650?s=96&#38;d=identicon" medium="image">
			<media:title type="html">autofac</media:title>
		</media:content>
	</item>
		<item>
		<title>Dependency injection is about components&#8230;</title>
		<link>http://autofac.wordpress.com/2007/04/09/dependency-injection-is-about-components/</link>
		<comments>http://autofac.wordpress.com/2007/04/09/dependency-injection-is-about-components/#comments</comments>
		<pubDate>Mon, 09 Apr 2007 06:01:38 +0000</pubDate>
		<dc:creator>autofac</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://autofac.wordpress.com/2007/04/09/dependency-injection-is-about-components/</guid>
		<description><![CDATA[&#8230;as opposed to classes. DI works best at a level of abstraction higher than that of individual classes.
Many of the dependency injection examples you&#8217;ll find in a typical web search or documentation-trawl neglect to mention this key fact. The biggest benefit of dependency injection is loose coupling. Loose coupling is very important between the large-scale [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autofac.wordpress.com&blog=945275&post=5&subd=autofac&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>&#8230;as opposed to classes. DI works best at a level of abstraction higher than that of individual classes.</p>
<p>Many of the dependency injection examples you&#8217;ll find in a typical web search or documentation-trawl neglect to mention this key fact. The biggest benefit of dependency injection is <em>loose coupling</em>. Loose coupling is very important between the large-scale components of a system, but can be an anti-goal at the class level where <em>high cohesion</em> is a valid quality to pursue. The creation of objects in a loose coupling scenario should be delegated to a builder, such as an IoC container, but in a high-cohesion scenario you&#8217;re really looking more towards a closely-related class to do the creation and configuration of an object.</p>
<p>The &#8216;factory&#8217; lifecycle model options supported by many containers could very easily encourage a proliferation of &#8216;inside out&#8217; applications where the IoC container has responsibility for creation of far too many classes of objects. (The example I just saw described &#8216;Button&#8217; as an example of a class that would use a factory lifecycle.)</p>
<p>The responsibilities of the container should be restricted to wiring together the bigger pieces, such as network interfaces or data layers, that can feasibly be used independently of each other. Putting the responsibilities associated with creating other, tightly-integrated lower-level classes into the container as well gives the container &#8216;responsibility bloat&#8217; in my opinion. I doubt the authors of the existing dependency injection tutorials intended any different, but I guess it is hard to come up with examples of valid <em>components</em> with factory-style lifecycles.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/autofac.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/autofac.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/autofac.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/autofac.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/autofac.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/autofac.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/autofac.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/autofac.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/autofac.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/autofac.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/autofac.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/autofac.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autofac.wordpress.com&blog=945275&post=5&subd=autofac&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://autofac.wordpress.com/2007/04/09/dependency-injection-is-about-components/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9cd28d4fa0a481cf6408ed7677755650?s=96&#38;d=identicon" medium="image">
			<media:title type="html">autofac</media:title>
		</media:content>
	</item>
		<item>
		<title>Dependency injection containers for smaller applications</title>
		<link>http://autofac.wordpress.com/2007/04/08/dependency-injection-containers-for-smaller-applications/</link>
		<comments>http://autofac.wordpress.com/2007/04/08/dependency-injection-containers-for-smaller-applications/#comments</comments>
		<pubDate>Sun, 08 Apr 2007 04:12:30 +0000</pubDate>
		<dc:creator>autofac</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://autofac.wordpress.com/2007/04/08/dependency-injection-containers-for-smaller-applications/</guid>
		<description><![CDATA[I don&#8217;t know if it is just me suffering a bit of &#8216;not invented here&#8217; syndrome, but the available dependency injection containers for .NET seem fairly awkward when building smaller systems. I think DI containers keep architectures nice and clean, and the drawbacks they suffer in small applications are generally related to the configuration overhead.
Only [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autofac.wordpress.com&blog=945275&post=4&subd=autofac&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I don&#8217;t know if it is just me suffering a bit of &#8216;not invented here&#8217; syndrome, but the available dependency injection containers for .NET seem fairly awkward when building smaller systems. I think DI containers keep architectures nice and clean, and the drawbacks they suffer in small applications are generally related to the configuration overhead.</p>
<p>Only a few popular containers have popped up in .NET land, and only time will tell whether any will become a de-facto standard. <a href="http://castleproject.org">Castle Windsor</a> has treated me fairly well, but it limits each component to providing a single service, something I&#8217;ve attempted to address myself but which runs quite deep into the architecture and won&#8217;t be fixed prior to the next official release.</p>
<p>Ruby is graced with a nice clean container called <a href="http://needle.rubyforge.org/">Needle</a> &#8211; the feature that got me looking at Needle is one which allows components to be registered using Ruby &#8216;blocks&#8217; &#8211; essentially, anonymous delegates or lambda expressions in C#/.NET land:</p>
<p><code><br />
container.Register&lt;ILogger&gt;(<br />
    c =&gt; new FileLogger("foo.log"));<br />
</code></p>
<p>Here, the container gets an anonymous delegate that it can use to create an implementation of the ILogger service. The parameter &#8216;c&#8217; passed to the registration delegate is a reference back to the container itself. Because the delegates are evaluated lazily, when components are requested, there is no need for registrations to be in order:</p>
<p><code><br />
container.Register&lt;IDatabase&gt;(<br />
    c =&gt; new SqlDatabase(c.Resolve&lt;ILogger&gt;()));<br />
container.Register&lt;ILogger&gt;(<br />
    c =&gt; new FileLogger("foo.log"));<br />
</code></p>
<p>This style of configuration appeals quite a bit to me for wiring up simple applications that don&#8217;t need much in the way of dynamic configuration but where the dependency injection pattern is still a useful structuring methodology.</p>
<p>Something lost in C# however, that Ruby gains from being an interpreted language, is the ability to make tweaks and changes post-deployment. For this perhaps the typical XML-based configuration is still the best way to go, however it would be a better approach in my mind to use the XML config as an override, rather than a complete description of the system.</p>
<p>The new ObjectBuilder in Enterprise Library 3.0 seems pretty nifty too, but puts me right off XML as a configuration syntax. It is just so hard to see the basic configuration information amongst all of that markup&#8230;</p>
<p>Perhaps there is room in the tower of Babel for a very, very small configuration DSL? Interested to hear whether anyone has come across something like this.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/autofac.wordpress.com/4/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/autofac.wordpress.com/4/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/autofac.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/autofac.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/autofac.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/autofac.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/autofac.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/autofac.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/autofac.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/autofac.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/autofac.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/autofac.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autofac.wordpress.com&blog=945275&post=4&subd=autofac&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://autofac.wordpress.com/2007/04/08/dependency-injection-containers-for-smaller-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9cd28d4fa0a481cf6408ed7677755650?s=96&#38;d=identicon" medium="image">
			<media:title type="html">autofac</media:title>
		</media:content>
	</item>
		<item>
		<title>Function containers &#8211; amusing and possibly useless.</title>
		<link>http://autofac.wordpress.com/2007/04/03/function-containers-a-cheap-hack/</link>
		<comments>http://autofac.wordpress.com/2007/04/03/function-containers-a-cheap-hack/#comments</comments>
		<pubDate>Tue, 03 Apr 2007 12:45:19 +0000</pubDate>
		<dc:creator>autofac</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://autofac.wordpress.com/2007/04/03/function-containers-a-cheap-hack/</guid>
		<description><![CDATA[A few nights ago I was playing with the implementation of lambda expressions in C#3, and started to wonder how they could be used to lighten up some of the GoF patterns&#8230; An interesting, but probably useless outcome of the process was this was the &#8216;function container,&#8217; which can be used to &#8216;cheaply&#8217; implement factories.
Each [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autofac.wordpress.com&blog=945275&post=3&subd=autofac&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>A few nights ago I was playing with the implementation of lambda expressions in C#3, and started to wonder how they could be used to lighten up some of the GoF patterns&#8230; An interesting, but probably useless outcome of the process was this was the &#8216;function container,&#8217; which can be used to &#8216;cheaply&#8217; implement factories.<br />
Each factory gets its own creation delegate, a function signature that produces the product of the factory from some initialisation arguments:<br />
<code><br />
// Person is a POCO<br />
delegate Person PersonFactory(string name);<br />
</code><br />
This delegate can be implemented using a lambda expression, method or anonymous delegate, e.g.:<br />
<code><br />
name =&gt; new Person(name)<br />
</code><br />
In this simple form it is a snap to add factories external to each of the domain object types, but the opportunity to inject more complex creation logic is maintained. To tie together the resulting proliferation of delegate expressions, a typed container is used:<br />
<code><br />
FunctionContainer factories = new FunctionContainer();<br />
factories.RegisterFunction&lt;PersonFactory&gt;(name =&gt; new Person(name));<br />
</code><br />
Later the factories can be retrieved from the container and called:<br />
<code><br />
Person newPerson = factories.Func&lt;PersonFactory&gt;().Call("Henry");<br />
</code><br />
The &#8216;Call&#8217; syntax is a bit of hacky generic magic that makes me think back to C++ days past&#8230; <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  The return type of the FunctionContainer.Func() method is not the registered delegate itself, but a wrapper exposing the delegate through a property named Call:<br />
<code><br />
// ICallable&lt;TDelegate&gt; exposes a TDelegate through a property called Call<br />
ICallable&lt;TDelegate&gt; Func&lt;TDelegate&gt;();<br />
</code><br />
I can&#8217;t see myself putting this to use in a real application, but the (often fairly inconvenient) fact that delegates in .NET get their own type regardless of their signature can obviously be put to some kind of use. More to come I guess!<br />
By the way, the &#8216;automatic factory&#8217; just coincidentally gave its name to this blog by reminding me of a neat story of the same title by Philip K. Dick!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/autofac.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/autofac.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/autofac.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/autofac.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/autofac.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/autofac.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/autofac.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/autofac.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/autofac.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/autofac.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/autofac.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/autofac.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=autofac.wordpress.com&blog=945275&post=3&subd=autofac&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://autofac.wordpress.com/2007/04/03/function-containers-a-cheap-hack/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9cd28d4fa0a481cf6408ed7677755650?s=96&#38;d=identicon" medium="image">
			<media:title type="html">autofac</media:title>
		</media:content>
	</item>
	</channel>
</rss>