<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://devlicio.us/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Derik Whittaker : Ninject, Agile</title><link>http://devlicio.us/blogs/derik_whittaker/archive/tags/Ninject/Agile/default.aspx</link><description>Tags: Ninject, Agile</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>Convention Binding to Ninject 3 -- Resolving ‘Value Cannot be Null’ Exception</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2012/08/12/convention-binding-to-ninject-3-resolving-value-cannot-be-null-exception.aspx</link><pubDate>Sun, 12 Aug 2012 12:26:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:70273</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=70273</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=70273</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2012/08/12/convention-binding-to-ninject-3-resolving-value-cannot-be-null-exception.aspx#comments</comments><description>&lt;p&gt;Recently I was creating a new &lt;a href="http://www.asp.net/mvc/mvc4"&gt;MVC4&lt;/a&gt;&amp;nbsp; application and of course I wanted to use &lt;a href="http://devlicio.us/controlpanel/blogs/posteditor.aspx/www.ninject.org"&gt;Ninject&lt;/a&gt; as my IoC container.&amp;nbsp; The first thing I did was to download and install the following NuGet packages:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://nuget.org/packages/Ninject.MVC3"&gt;Ninject.MVC3&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://nuget.org/packages/ninject.extensions.conventions"&gt;Ninject.Extensions.Conventions&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://nuget.org/packages/CommonServiceLocator.NinjectAdapter"&gt;CommongServiceLocator.NinjectAdapter&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;After I got these setup I opened up the NinjectWebCommon.cs class and started to add code to the RegisterServices method.&amp;nbsp; The first thing i did was to add the code below;&lt;/p&gt;
&lt;pre name="code" class="c#"&gt;            kernel.Bind(scanner =&amp;gt;
            {
                try
                {
                    scanner.FromAssemblyContaining()
                    .SelectAllClasses()
                    .BindDefaultInterface();

                    scanner.FromAssemblyContaining()
                        .SelectAllClasses()
                        .BindDefaultInterface();

                    scanner.FromAssemblyContaining()
                        .SelectAllClasses()
                        .BindDefaultInterface();
                }
                catch (Exception e) // added to try to get the exception message
                {
                    Debug.WriteLine(e);
                    throw;
                }
            });&lt;/pre&gt;
&lt;p&gt;The above code would step over the first scanner call w/ no issues, in fact if that was the ONLY statement it all worked as expected, however when it stepped onto the second scanner. call I would get the following error.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;System.ArgumentNullException: Value cannot be null. Parameter name: first&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Because I knew everything worked fine with only one scanner. call i decided to give it a go w/&amp;nbsp; creating a unique kernal.Bind for each assembly i wanted scanned as below:&lt;/p&gt;
&lt;pre name="code" class="c#"&gt;            kernel.Bind(scanner =&amp;gt; scanner.FromAssemblyContaining()
                                       .SelectAllClasses()
                                       .BindDefaultInterface());

            kernel.Bind(scanner =&amp;gt; scanner.FromAssemblyContaining()
                                       .SelectAllClasses()
                                       .BindDefaultInterface());

            kernel.Bind(scanner =&amp;gt; scanner.FromAssemblyContaining()
                                       .SelectAllClasses()
                                       .BindDefaultInterface());&lt;/pre&gt;
&lt;p&gt;This did the trick, I could now setup the bindings for multiple assemblies with no issues.&amp;nbsp; So it appears that with this version of the Extensions class for ninject you need to do each action as a unique .Bind method.&lt;/p&gt;
&lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=70273" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Agile/default.aspx">Agile</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/ASP.Net+MVC/default.aspx">ASP.Net MVC</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Ninject/default.aspx">Ninject</category></item></channel></rss>