<?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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Ben Ellis's Blog</title>
	<atom:link href="http://benellis.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://benellis.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Tue, 05 May 2009 07:48:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='benellis.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Ben Ellis's Blog</title>
		<link>http://benellis.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://benellis.wordpress.com/osd.xml" title="Ben Ellis&#039;s Blog" />
	<atom:link rel='hub' href='http://benellis.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Customizing Ninject 2.0 Behaviour to use the Default Constructor on InjectAttribute-less classes.</title>
		<link>http://benellis.wordpress.com/2009/05/05/customizing-ninject-20-behaviour-to-use-the-default-constructor-on-injectattribute-less-classes/</link>
		<comments>http://benellis.wordpress.com/2009/05/05/customizing-ninject-20-behaviour-to-use-the-default-constructor-on-injectattribute-less-classes/#comments</comments>
		<pubDate>Tue, 05 May 2009 07:48:55 +0000</pubDate>
		<dc:creator>dragonwolf</dc:creator>
				<category><![CDATA[Ninject]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[DoI]]></category>

		<guid isPermaLink="false">http://benellis.wordpress.com/?p=3</guid>
		<description><![CDATA[I&#8217;ve converted one of my old libraries from Ninject 1.0 to Ninject 2.0 and noticed that it has a different behaviour when instantiating a class that does not use the InjectAttribute on any of the constructors or properties. And, as Nate says in his post about Ninject 2.0, the behaviour has changed so that when [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benellis.wordpress.com&amp;blog=7578577&amp;post=3&amp;subd=benellis&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve converted one of my old libraries from Ninject 1.0 to Ninject 2.0 and noticed that it has a different behaviour when instantiating a class that does not use the InjectAttribute on any of the constructors or properties.</p>
<p>And, as <a href="http://kohari.org/2009/02/25/ninject-2-reaches-beta/">Nate says in his post about Ninject 2.0</a>, the behaviour has changed so that when it does not have the InjectAttribute applied to any constructors or properties, it selects the Constructor with the largest number of parameters.</p>
<p>This seems flawed to me, since each implementation of an interface may have different constructors which would break any application-module using this binding. As in my case with the System.Data.IDbCommand and System.Data.SqlCommand.</p>
<p>To get around this problem, I discovered how easy it is to change the behaviour of Ninject after a quick look at the source code.</p>
<p>I created the following class,</p>
<p><code><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<div class="csharpcode">
<pre class="alt">    <span class="kwrd">using</span> System;</pre>
<pre>    <span class="kwrd">using</span> System.Reflection;</pre>
<pre class="alt">    <span class="kwrd">using</span> Ninject.Components;</pre>
<pre>    <span class="kwrd">using</span> Ninject.Selection.Heuristics;</pre>
<pre class="alt">&nbsp;</pre>
<pre>    <span class="kwrd">public</span> <span class="kwrd">class</span> UseNinject1ConstructorScorer : NinjectComponent, IConstructorScorer</pre>
<pre class="alt">    {</pre>
<pre>        <span class="kwrd">public</span> <span class="kwrd">int</span> Score(ConstructorInfo constructor)</pre>
<pre class="alt">        {</pre>
<pre>            <span class="kwrd">if</span> (constructor == <span class="kwrd">null</span>) <span class="kwrd">throw</span> <span class="kwrd">new</span> ArgumentNullException(<span class="str">"constructor"</span>, <span class="str">"Cannot be null"</span>);</pre>
<pre class="alt">            <span class="kwrd">return</span> constructor.IsDefined(<span class="kwrd">this</span>.Settings.InjectAttribute, <span class="kwrd">true</span>) ? Int32.MaxValue : -constructor.GetParameters().Length;</pre>
<pre>        }</pre>
<pre class="alt">    }</pre>
</div>
<p></code></p>
<p>And then overrode the IConstructorScorer component with my new ConstructorScorer.</p>
<p><code><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<div class="csharpcode">
<pre class="alt">    <span class="kwrd">class</span> Program</pre>
<pre>    {</pre>
<pre class="alt">        <span class="kwrd">static</span> <span class="kwrd">void</span> Main(<span class="kwrd">string</span>[] args)</pre>
<pre>        {</pre>
<pre class="alt">            IKernel kernel = <span class="kwrd">new</span> StandardKernel();</pre>
<pre>            kernel.Components.RemoveAll(<span class="kwrd">typeof</span> (IConstructorScorer));</pre>
<pre class="alt">            kernel.Components.Add();</pre>
<pre>&nbsp;</pre>
<pre class="alt">            <span class="rem">// Add Bindings</span></pre>
<pre>&nbsp;</pre>
<pre class="alt">            <span class="rem">// Inject Objects</span></pre>
<pre>        }</pre>
<pre class="alt">    }</pre>
</div>
<p></code></p>
<br />Posted in Ninject, Software Development Tagged: C#, DoI, Ninject <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benellis.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benellis.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benellis.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benellis.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/benellis.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/benellis.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/benellis.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/benellis.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benellis.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benellis.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benellis.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benellis.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benellis.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benellis.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benellis.wordpress.com&amp;blog=7578577&amp;post=3&amp;subd=benellis&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://benellis.wordpress.com/2009/05/05/customizing-ninject-20-behaviour-to-use-the-default-constructor-on-injectattribute-less-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8f641516386be3c42f04a50483fb33fd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dragonwolf</media:title>
		</media:content>
	</item>
		<item>
		<title>Hello world!</title>
		<link>http://benellis.wordpress.com/2009/05/01/hello-world/</link>
		<comments>http://benellis.wordpress.com/2009/05/01/hello-world/#comments</comments>
		<pubDate>Fri, 01 May 2009 14:03:31 +0000</pubDate>
		<dc:creator>dragonwolf</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging! Posted in Uncategorized<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benellis.wordpress.com&amp;blog=7578577&amp;post=1&amp;subd=benellis&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Welcome to <a href="http://wordpress.com/">WordPress.com</a>. This is your first post. Edit or delete it and start blogging!</p>
<br />Posted in Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benellis.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benellis.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benellis.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benellis.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/benellis.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/benellis.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/benellis.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/benellis.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benellis.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benellis.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benellis.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benellis.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benellis.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benellis.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benellis.wordpress.com&amp;blog=7578577&amp;post=1&amp;subd=benellis&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://benellis.wordpress.com/2009/05/01/hello-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8f641516386be3c42f04a50483fb33fd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dragonwolf</media:title>
		</media:content>
	</item>
	</channel>
</rss>
