<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>IoC</title>
        <link>http://blogs.imeta.co.uk/HHariri/category/111.aspx</link>
        <description>IoC</description>
        <language>en-GB</language>
        <copyright>Hadi Hariri </copyright>
        <generator>Subtext Version 2.1.1.1</generator>
        <item>
            <title>It&amp;rsquo;s all about the delivery</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2009/10/29/itrsquos-all-about-the-delivery.aspx</link>
            <description>&lt;p&gt;   &lt;br /&gt;
The Dependency Inversion Principle states:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;dl&gt;&lt;dd&gt;&lt;dl&gt;&lt;dd&gt;&lt;em&gt;A. High-level modules should not depend on low-level modules. Both should depend on abstractions.&lt;/em&gt;&lt;/dd&gt;&lt;dd&gt;&lt;em&gt;B. Abstractions should not depend upon details. Details should depend upon abstractions.&lt;/em&gt;&lt;/dd&gt;&lt;/dl&gt;&lt;/dd&gt;&lt;/dl&gt;  &lt;br /&gt;
(Source WikiPedia).
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.codinghorror.com/blog/archives/001225.html"&gt;Throw that at a terrible programmer&lt;/a&gt;, and all you’ll get is a terrible programmer that is annoyed and hates you. So true!&lt;/p&gt;
&lt;p&gt;Take the following method:&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; PrintHelloMessage()&lt;/pre&gt;
&lt;pre&gt;        {&lt;/pre&gt;
&lt;pre class="alt"&gt;            Console.WriteLine(&lt;span class="str"&gt;"Hello"&lt;/span&gt;);&lt;/pre&gt;
&lt;pre&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;p /&gt;&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;  
&lt;p&gt;Now ask a developer to add a new method to print the message ‘Goodbye’. Do you think he would do:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; PrintGoodbyeMessage()&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine(&lt;span class="str"&gt;"Goodbye"&lt;/span&gt;);&lt;br /&gt;        }&lt;/pre&gt;
&lt;p&gt;   &lt;br /&gt;
or:&lt;/p&gt;
&lt;p /&gt;&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;  
&lt;pre class="csharpcode"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; PrintMessage(&lt;span class="kwrd"&gt;string&lt;/span&gt; message)&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine(message);&lt;br /&gt;        }&lt;/pre&gt;
&lt;p /&gt;&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;  
&lt;p&gt;Most likely, he’d do the latter. Why? Because he realizes he’s gaining a benefit by passing a parameter to a method. He knows that if tomorrow you ask him for a “Good Afternoon” message, he won’t have to write a new method. &lt;/p&gt;
&lt;p&gt;What is Dependency Injection? It’s one way of complying with the Dependency Inversion Principle. However, when you think about it, what does it boil down to? Passing a parameter to a method, which happens to be a constructor. It seems simple enough doesn’t it? Yet, it’s hard for people to understand it. Why? because they don’t see the value in it. &lt;/p&gt;
&lt;p&gt;Explaining a principle to someone without them understanding the benefits and values they get out of it is useless, and that is why concepts such as Dependency Injection or Inversion of Control seem overly complex to the vast majority of developers (believe it or not, those of us that use these things are still a very big minority). It’s complex because they haven’t been explained the values of it. They’ve just been thrown some definition and they are expected to understand that it’s bad for one class to create an instance of another class it uses. &lt;/p&gt;
&lt;p&gt;Present a developer with the following code:&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; AuthServices&lt;/pre&gt;
&lt;pre&gt;    {&lt;/pre&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AuthUser(&lt;span class="kwrd"&gt;string&lt;/span&gt; username, &lt;span class="kwrd"&gt;string&lt;/span&gt; password)&lt;/pre&gt;
&lt;pre&gt;        {&lt;/pre&gt;
&lt;pre class="alt"&gt;            var authDAL = &lt;span class="kwrd"&gt;new&lt;/span&gt; AuthDAL();&lt;/pre&gt;
&lt;pre&gt; &lt;/pre&gt;
&lt;pre class="alt"&gt;            var user = authDAL.GetUserByUsername(username);&lt;/pre&gt;
&lt;pre&gt; &lt;/pre&gt;
&lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (user != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre&gt;            {&lt;/pre&gt;
&lt;pre class="alt"&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; ...&lt;/pre&gt;
&lt;pre&gt;            }&lt;/pre&gt;
&lt;pre class="alt"&gt; &lt;/pre&gt;
&lt;pre&gt;        }&lt;/pre&gt;
&lt;pre class="alt"&gt;    }&lt;/pre&gt;
&lt;/div&gt;
&lt;p /&gt;&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;  
&lt;p&gt;and ask them how they’d go about testing this code without having access to a database. Ask them how they’d go about changing AuthDAL for some fake DAL that doesn’t really connect to a database. &lt;/p&gt;
&lt;p&gt;They’ll probably come up with the solution of passing the AuthDAL class in as a parameter, and eventually realizing that multiple methods will use the same class, they’ll pass it in via the constructor and set it as an instance field. As long as their AuthDAL has virtual methods, they can create any fake DAL that overrides those methods and returns some dummy value. They might argue that they don’t want virtual methods. And that’s fine. Tell them to define the parameter as an interface. In fact, they probably have already heard of a principle that says that you should program to an interface and not a class. They’ll eventually end up with this code:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; AuthServices&lt;br /&gt;    {&lt;br /&gt;        IAuthDAL authDAL;&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; AuthServices(IAuthDAL authDAL)&lt;br /&gt;        {&lt;br /&gt;            _authDAL = authDAL;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AuthUser(&lt;span class="kwrd"&gt;string&lt;/span&gt; username, &lt;span class="kwrd"&gt;string&lt;/span&gt; password)&lt;br /&gt;        {&lt;br /&gt;            var user = _authDAL.GetUserByUsername(username);&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (user != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;br /&gt;            {&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; ...&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;    }&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;And voila! You have Dependency Injection via Constructor. &lt;/p&gt;
&lt;p&gt;Once they *get* that, then explain to them other benefits, you know the real benefits they get from doing this: decoupled code, easy maintenance, promotion of SRP, etc.  and then throw the principle in their face:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;dl&gt;&lt;dd&gt;&lt;dl&gt;&lt;dd&gt;&lt;em&gt;A. High-level modules should not depend on low-level modules. Both should depend on abstractions.&lt;/em&gt; &lt;/dd&gt;&lt;dd&gt;&lt;em&gt;B. Abstractions should not depend upon details. Details should depend upon abstractions.&lt;/em&gt;&lt;/dd&gt;&lt;/dl&gt;&lt;/dd&gt;&lt;/dl&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;And they’ll see how it all makes sense. &lt;/p&gt;
&lt;p&gt;It’s not about throwing or not throwing books. It’s about showing people how something can help them, how they get value of it. &lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/800.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2009/10/29/itrsquos-all-about-the-delivery.aspx</guid>
            <pubDate>Thu, 29 Oct 2009 20:32:37 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2009/10/29/itrsquos-all-about-the-delivery.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/800.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/800.aspx</trackback:ping>
        </item>
        <item>
            <title>StructureMap System.InvalidProgramException</title>
            <link>http://blogs.imeta.co.uk/HHariri/archive/2008/12/07/structuremap-system.invalidprogramexception.aspx</link>
            <description>&lt;p&gt;I just upgraded to the latest release of StructureMap (2.5) and spent a good portion of time trying to figure out a bug I was having in a complex dependency graph. The original exception is a StructureMap exception, with code 207, which per documentation, you need to look at the inner exception. The problem is that the inner exception isn't awfully helpful:&lt;/p&gt;
&lt;p&gt;&lt;strong /&gt;&lt;/p&gt;
&lt;strong&gt;&lt;strong&gt;  &lt;/strong&gt;&lt;/strong&gt;&lt;blockquote&gt;&lt;strong&gt;&lt;strong&gt;   &lt;/strong&gt; &lt;/strong&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;strong&gt;System.InvalidProgramException : JIT Compiler encountered an internal limitation.       &lt;br /&gt;
&lt;/strong&gt;&lt;/strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;strong&gt;&lt;strong&gt; &lt;/strong&gt;&lt;/strong&gt;&lt;/blockquote&gt;&lt;strong&gt;&lt;strong&gt;  &lt;/strong&gt; &lt;/strong&gt;
&lt;p&gt;Initially I thought it was related to the &lt;em&gt;WithCtorArg&lt;/em&gt; method that allows you to pass in parameters to the constructor, but after stripping everything down to try and come up with a test case, it seems that the issue occurs when you have a class that the container resolves which has a public static property, like so:&lt;/p&gt;
&lt;strong&gt;&lt;strong&gt;  &lt;/strong&gt; &lt;/strong&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.66%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; height: 248px; background-color: rgb(244, 244, 244);"&gt;&lt;strong&gt;&lt;strong&gt;   &lt;/strong&gt; &lt;/strong&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;strong&gt;&lt;strong&gt;     &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;   1:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;interface&lt;/span&gt; ISomeClass&lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;   2:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt; {&lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;   3:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; SomeMethod();&lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;   4:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt; }&lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;   5:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt;  &lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;   6:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; SomeClass : ISomeClass&lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;   7:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt; {&lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;   8:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt;  &lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;   9:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; SomeProperty { get; set; }    &lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;  10:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt;  &lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;  11:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; SomeMethod()&lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;  12:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt;     {&lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;  13:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt;     }&lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;  14:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt;  &lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;  15:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt;  &lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;  16:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt; }&lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;  &lt;/strong&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt; &lt;/strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Here's the StructureMap configuration test:&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;strong&gt; &lt;strong&gt;  &lt;/strong&gt; &lt;/strong&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;strong&gt; &lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;   1:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt; [Fact]&lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;   2:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; TestStructureMap()&lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;   3:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt; {&lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;   4:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt;     ObjectFactory.Initialize( x =&amp;gt; x.ForRequestedType&amp;lt;ISomeClass&amp;gt;().TheDefault.Is.OfConcreteType&amp;lt;SomeClass&amp;gt;());&lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;   5:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt;  &lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;   6:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt;     ObjectFactory.GetInstance&amp;lt;ISomeClass&amp;gt;();&lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;    &lt;/strong&gt; &lt;/strong&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;&lt;strong&gt;&lt;strong&gt;   7:&lt;/strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;strong&gt; }&lt;/strong&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;strong&gt;  &lt;/strong&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt; &lt;/strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;As soon as you make the property private or make it an instance property, the container resolves fine. I tested the same thing with Unity and there doesn't seem to be an issue. &lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;I tested the same code with 2.4.9 and it seems to work. &lt;br /&gt;
&lt;/p&gt;&lt;img src="http://blogs.imeta.co.uk/HHariri/aggbug/532.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Hadi Hariri </dc:creator>
            <guid>http://blogs.imeta.co.uk/HHariri/archive/2008/12/07/structuremap-system.invalidprogramexception.aspx</guid>
            <pubDate>Sun, 07 Dec 2008 16:24:21 GMT</pubDate>
            <comments>http://blogs.imeta.co.uk/HHariri/archive/2008/12/07/structuremap-system.invalidprogramexception.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.imeta.co.uk/HHariri/comments/commentRss/532.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.imeta.co.uk/HHariri/services/trackbacks/532.aspx</trackback:ping>
        </item>
    </channel>
</rss>