|
From: <jer...@us...> - 2009-01-02 23:58:21
|
Revision: 213
http://structuremap.svn.sourceforge.net/structuremap/?rev=213&view=rev
Author: jeremydmiller
Date: 2009-01-02 23:58:17 +0000 (Fri, 02 Jan 2009)
Log Message:
-----------
documentation
Modified Paths:
--------------
trunk/Source/HTML/AttributeNormalized.htm
trunk/Source/HTML/ConfiguringStructureMap.htm
trunk/Source/HTML/ConstructorAndSetterInjection.htm
trunk/Source/HTML/Default.htm
trunk/Source/HTML/Diagnostics.htm
trunk/Source/HTML/ExtendingStructureMap.htm
trunk/Source/HTML/Generics.htm
trunk/Source/HTML/Glossary.htm
trunk/Source/HTML/HTML.csproj
trunk/Source/HTML/InstanceExpression.htm
trunk/Source/HTML/Interception.htm
trunk/Source/HTML/QuickStart.htm
trunk/Source/HTML/RegistryDSL.htm
trunk/Source/HTML/RetrievingServices.htm
trunk/Source/HTML/ScanningAssemblies.htm
Added Paths:
-----------
trunk/Source/HTML/AutoMocker.htm
trunk/Source/HTML/AutoWiring.htm
trunk/Source/HTML/ChangingConfigurationAtRuntime.htm
trunk/Source/HTML/Concepts.htm
trunk/Source/HTML/FeatureList.htm
trunk/Source/HTML/HowDoesStructureMapWork.htm
trunk/Source/HTML/Menu.htm
trunk/Source/HTML/ModularConfiguration.htm
trunk/Source/HTML/Profiles.htm
trunk/Source/HTML/Scoping.htm
trunk/Source/HTML/SmartInstance.htm
trunk/Source/HTML/UsingAttributes.htm
trunk/Source/HTML/UsingSessionContext.htm
trunk/Source/HTML/UsingTheContainerOutsideOfObjectFactory.htm
trunk/Source/HTML/XmlReference.htm
trunk/Source/HTML/jquery-1.2.6.js
trunk/Source/HTML/structuremap.js
trunk/Source/HTML/style.css
Removed Paths:
-------------
trunk/Source/HTML/ExplicitArguments.htm
trunk/Source/HTML/InjectingServicesAtRuntime.htm
Modified: trunk/Source/HTML/AttributeNormalized.htm
===================================================================
--- trunk/Source/HTML/AttributeNormalized.htm 2008-12-22 14:57:59 UTC (rev 212)
+++ trunk/Source/HTML/AttributeNormalized.htm 2009-01-02 23:58:17 UTC (rev 213)
@@ -1,25 +1,18 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
- <title>Title</title>
- <link rel="stylesheet" type="text/css" href="style.css">
- <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
- <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
- <style type="text/css">
- .style1
- {
- font-weight: bold;
- }
- </style>
+ <title>Attribute Normalized Instances</title>
+ <link rel="stylesheet" type="text/css" href="style.css" />
+ <script type="text/javascript" src="jquery-1.2.6.js"></script>
+ <script type="text/javascript" src="structuremap.js"></script>
</head>
- <body>
- <h1>Attribute Normalized Xml Instances</h1>
+ <body class="code">
<p>This style is a more terse configuration format that was
added in version 1.0. My recommendaton is to always use attribute normalized
Xml configuration by marking the <StructureMap> node with the
MementoStyle="Attribute" attribute by default anytime you are using Xml
configuration. </p>
- <h4>Instance Root Node</h4>
+ <h2>Instance Root Node</h2>
<p>An Instance is defined in Xml starting from a root node. The actual name of
the root node varies depending upon the context that an Instance is being
configured. For example, the AddInstance, DefaultInstance,
@@ -31,7 +24,8 @@
<!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red163\green21\blue21;\red0\green0\blue255;}??\fs20 [\cf3 Pluggable\cf0 (\cf4 "Color"\cf0 )]\par ?? \cf5 public\cf0 \cf5 class\cf0 \cf3 ColorRule\cf0 : \cf3 Rule\par ??\cf0 \{\par ?? \cf5 private\cf0 \cf5 string\cf0 _Color;\par ?? \cf5 public\cf0 \cf5 string\cf0 ID = \cf3 Guid\cf0 .NewGuid().ToString();\par ??\par ?? \cf5 public\cf0 ColorRule(\cf5 string\cf0 Color)\par ?? \{\par ?? _Color = Color;\par ?? \}\par ??\par ??\par ?? \cf5 public\cf0 \cf5 string\cf0 Color\par ?? \{\par ?? \cf5 get\cf0 \{ \cf5 return\cf0 _Color; \}\par ?? \}\par ?? \}}
-->
- <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
+ <div class="code-sample"
+ style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;">
[<span style="color: #2b91af;">Pluggable</span>(<span
style="color: #a31515;">"Color"</span>)]</p>
@@ -82,7 +76,7 @@
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs20 \cf1 <\cf3 Instance\cf1 \cf4 Key\cf1 =\cf0 "\cf1 Red\cf0 "\cf1 \cf4 Type\cf1 =\cf0 "\cf1 Color\cf0 "\cf1 \cf4 Color\cf1 =\cf0 "\cf1 Red\cf0 "\cf1 />}
-->
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
- <p style="margin: 0px;">
+ <p style="margin: 0px;" class="code-sample">
<span style="color: blue;"> <</span><span
style="color: #a31515;">Instance</span><span style="color: blue;"> </span>
<span style="color: red;">Key</span><span style="color: blue;">=</span>"<span
@@ -102,7 +96,7 @@
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs20 \cf1 <\cf3 Instance\cf1 \cf4 Key\cf1 =\cf0 "\cf1 Red\cf0 "\cf1 \cf4 PluggedType\cf1 =\cf0 "\cf1 StructureMap.Testing.Widget.Color, StructureMap.Testing.Widget\cf0 "\cf1 \cf4 Color\cf1 =\cf0 "\cf1 Red\cf0 "\cf1 />}
-->
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
- <p style="margin: 0px;">
+ <p style="margin: 0px;" class="code-sample">
<span style="color: blue;"> <</span><span
style="color: #a31515;">Instance</span><span style="color: blue;"> </span>
<span style="color: red;">Key</span><span style="color: blue;">=</span>"<span
@@ -114,26 +108,30 @@
style="color: blue;">Red</span>"<span style="color: blue;"> /></span></p>
</div>
<!--EndFragment-->
-<p> </p>
- <h4>Primitive Properties (Strings and basic value types)</h4>
- <p>Primitive constructor or setter arguments are defined by
- adding an attribute @propertyName="propertyValue" to the
- instance node.="font-family: Courier New; font-size: 10pt; color: black; background: white; border-top: windowtext 1pt solid; padding-top: 0pt; border-left: windowtext 1pt solid; padding-left: 0pt; border-right: windowtext 1pt solid; padding-right: 0pt; border-bottom: windowtext 1pt solid; padding-bottom: 0pt;">
-<pre style="margin: 0px;"> [Pluggable("Color", "Only for testing")]</pre>
-<pre style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> ColorWidget : IWidget</pre>
+<hr />
+ <h2>Primitive Properties (Strings and basic value types)</h2>
+ <p>Primitive constructor or setter arguments are defined by adding an attribute
+ @propertyName="propertyValue" to the instance node. A class with
+ a string argument to the constructor,</p>
+<div class="code-sample>
+ <pre style="margin: 0px;"> [Pluggable("Color", "Only for testing")]<pre style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> ColorWidget : IWidget</pre>
<pre style="margin: 0px;"> {</pre>
<pre style="margin: 0px;"> <span style="color: blue;">public</span> ColorWidget(<span style="color: blue;">string</span> Color)</pre>
<pre style="margin: 0px;"> {</pre>
<pre style="margin: 0px;"> _Color = Color;</pre>
<pre style="margin: 0px;"> }</pre>
<pre style="margin: 0px;"> }</pre>
+ <pre style="margin: 0px;"> </pre>
+ <p style="margin: 0px;">would be configured like this in the Xml:</p>
+
</div>
<br>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border-top: windowtext 1pt solid; padding-top: 0pt; border-left: windowtext 1pt solid; padding-left: 0pt; border-right: windowtext 1pt solid; padding-right: 0pt; border-bottom: windowtext 1pt solid; padding-bottom: 0pt;">
-<pre style="margin: 0px;"> <span style="color: blue;"><</span><span style="color: maroon;">Widget</span><span style="color: fuchsia;"> </span><span style="color: red;">Type</span><span style="color: blue;">="Color"</span><span style="color: fuchsia;"> </span><span style="color: red;">Key</span><span style="color: blue;">="Red"</span><span style="color: fuchsia;"> </span><span style="color: #FF0000">Color</span><span style="color: blue;">="Red" /></span></pre>
+<pre style="margin: 0px;" class="code-sample"> <span style="color: blue;"><</span><span style="color: maroon;">Widget</span><span style="color: fuchsia;"> </span><span style="color: red;">Type</span><span style="color: blue;">="Color"</span><span style="color: fuchsia;"> </span><span style="color: red;">Key</span><span style="color: blue;">="Red"</span><span style="color: fuchsia;"> </span><span style="color: #FF0000">Color</span><span style="color: blue;">="Red" /></span></pre>
</div>
-<h4>Long Strings</h4>
+ <hr />
+ <h2>Long Strings</h2>
<p>There is an optional mode to define a property value
inside a CDATA tag for very long strings like sql statements
or Javascript templates. </p>
@@ -150,7 +148,8 @@
<pre style="margin: 0px;"> <span style="color: blue;"></</span><span style="color: maroon;">Property</span><span style="color: blue;">></span></pre>
</div>
- <h4>Enumeration Properties</h4>
+ <hr />
+ <h2>Enumeration Properties</h2>
<p>Enumeration arguments are defined the same way as
primitive properties. Use the string names of the
enumeration for the values.</p>
@@ -181,7 +180,8 @@
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border-top: windowtext 1pt solid; padding-top: 0pt; border-left: windowtext 1pt solid; padding-left: 0pt; border-right: windowtext 1pt solid; padding-right: 0pt; border-bottom: windowtext 1pt solid; padding-bottom: 0pt;">
<pre style="margin: 0px;"> <span style="color: blue;"><</span><span style="color: #800000">Instance</span><span style="color: fuchsia;"> </span><span style="color: red;">Type</span><span style="color: blue;">="Cow"</span><span style="color: fuchsia;"> </span><span style="color: red;">Key</span><span style="color: blue;">="Maggie" </span><span style="color: #FF0000">Breed</span><span style="color: blue;">="Angus" /></span></pre>
</div>
- <h4>Child Properties</h4>
+ <hr />
+ <h2>Child Properties</h2>
<p>Child properties of non-primitive types are defined as
embedded memento nodes. Child properties can be either
defined inline or use a reference to a named instance of the
@@ -229,7 +229,8 @@
<pre style="margin: 0px;"> <span style="color: blue;"><</span><span style="color: maroon;">MyGrandChild</span><span style="color: fuchsia;"> </span><span style="color: red;">Key</span><span style="color: blue;">="Tommy"/></span></pre>
<pre style="margin: 0px;"> <span style="color: blue;"></</span><span style="color: maroon;">StructureMap.Testing.Widget.Child</span><span style="color: blue;">></span> </pre>
</div>
-<h3>Non Primitive Array Property</h3>
+ <hr />
+ <h2>Non Primitive Array Property</h2>
<p>If a property or constructor argument is an array of a non-primitive type, create
a child node to the top level instance node with the name of the property.
Simply add new InstanceMemento nodes with the name <Child> under the property
@@ -258,8 +259,10 @@
<pre style="margin: 0px;"> <span style="color: blue;"><</span><span style="color: #800000">Child</span><span style="color: fuchsia;"> </span><span style="color: red;">Type</span><span style="color: blue;">="Random" </span><span style="color: #FF0000">seed</span><span style="color: blue;">="0.034"/></span></pre>
<pre style="margin: 0px;"> <span style="color: blue;"></</span><span style="color: maroon;">innerStrategies</span><span style="color: blue;">></span></pre>
<pre style="margin: 0px;"> <span style="color: blue;"></</span><span style="color: maroon;">Instance</span><span style="color: blue;">></span></pre>
+ <p style="margin: 0px;"> </p>
+ <hr />
</div>
-<h3>Primitive Arrays</h3>
+<h2>Primitive Arrays</h2>
<p>Primitive arrays like string[] or int[] can be defined in Xml. For a class
with arguments like:</p>
<!--
@@ -284,7 +287,8 @@
<!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs20 \cf1 <\cf3 DefaultInstance\par ??\cf1 \cf4 PluginType\cf1 =\cf0 "\cf1 StructureMap.Testing.Configuration.ClassWithStringAndIntArray, StructureMap.Testing\cf0 "\par ??\cf1 \cf4 PluggedType\cf1 =\cf0 "\cf1 StructureMap.Testing.Configuration.ClassWithStringAndIntArray, StructureMap.Testing\cf0 "\cf1 >\par ??\par ?? <\cf3 numbers\cf1 \cf4 Values\cf1 =\cf0 "\cf1 1,2,3\cf0 "\cf1 />\par ?? <\cf3 strings\cf1 \cf4 Values\cf1 =\cf0 "\cf1 1,2,3\cf0 "\cf1 />\par ?? </\cf3 DefaultInstance\cf1 >}
-->
- <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
+ <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"
+ class="code-sample">
<p style="margin: 0px;">
<span style="color: blue;"> <</span><span style="color: #a31515;">DefaultInstance</span></p>
<p style="margin: 0px;">
@@ -321,7 +325,8 @@
<!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs20 \cf1 <\cf3 DefaultInstance\par ??\cf1 \cf4 PluginType\cf1 =\cf0 "\cf1 StructureMap.Testing.Configuration.ClassWithStringAndIntArray, StructureMap.Testing\cf0 "\par ??\cf1 \cf4 PluggedType\cf1 =\cf0 "\cf1 StructureMap.Testing.Configuration.ClassWithStringAndIntArray, StructureMap.Testing\cf0 "\cf1 >\par ??\par ?? <\cf3 numbers\cf1 \cf4 Values\cf1 =\cf0 "\cf1 1;2;3\cf0 "\cf1 \cf4 Delimiter\cf1 =\cf0 "\cf1 ;\cf0 "\cf1 />\par ?? <\cf3 strings\cf1 \cf4 Values\cf1 =\cf0 "\cf1 1,2,3\cf0 "\cf1 />\par ?? </\cf3 DefaultInstance\cf1 >}
-->
-<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
+<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"
+ class="code-sample">
<p style="margin: 0px;">
<span style="color: blue;"> <</span><span style="color: #a31515;">DefaultInstance</span></p>
<p style="margin: 0px;">
@@ -352,14 +357,16 @@
style="color: blue;">></span></p>
</div>
<!--EndFragment-->
-<h3>Dictionaries and NameValueCollection</h3>
+<hr />
+ <h2>Dictionaries and NameValueCollection</h2>
<p>Any form of IDictionary<Key, Value> or a NameValueCollection can be configured in
Xml by the following syntax. Say you have a class that needs a Dictionary
of properties:</p>
<!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 ClassWithDictionary\par ??\cf0 \{\par ?? \cf3 private\cf0 \cf3 readonly\cf0 \cf4 IDictionary\cf0 <\cf3 string\cf0 , \cf3 string\cf0 > _dictionary;\par ??\par ?? \cf3 public\cf0 ClassWithDictionary(\cf4 IDictionary\cf0 <\cf3 string\cf0 , \cf3 string\cf0 > dictionary)\par ?? \{\par ?? _dictionary = dictionary;\par ?? \}\par ??\par ?? \cf3 public\cf0 \cf4 IDictionary\cf0 <\cf3 string\cf0 , \cf3 string\cf0 > Dictionary\par ?? \{\par ?? \cf3 get\cf0 \{ \cf3 return\cf0 _dictionary; \}\par ?? \}\par ?? \}}
-->
-<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
+<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"
+ class="code-sample">
<p style="margin: 0px;">
<span style="color: blue;">public</span> <span style="color: blue;">
class</span> <span style="color: #2b91af;">ClassWithDictionary</span></p>
@@ -410,7 +417,8 @@
<!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs20 \cf1 <\cf3 DefaultInstance\par ??\cf1 \cf4 PluginType\cf1 =\cf0 "\cf1 StructureMap.Testing.Configuration.ClassWithDictionary, StructureMap.Testing\cf0 "\par ??\cf1 \cf4 PluggedType\cf1 =\cf0 "\cf1 StructureMap.Testing.Configuration.ClassWithDictionary, StructureMap.Testing\cf0 "\cf1 >\par ?? <\cf3 dictionary\cf1 >\par ?? <\cf3 Pair\cf1 \cf4 Key\cf1 =\cf0 '\cf1 color\cf0 '\cf1 \cf4 Value\cf1 =\cf0 '\cf1 red\cf0 '\cf1 />\par ?? <\cf3 Pair\cf1 \cf4 Key\cf1 =\cf0 '\cf1 state\cf0 '\cf1 \cf4 Value\cf1 =\cf0 '\cf1 texas\cf0 '\cf1 />\par ?? <\cf3 Pair\cf1 \cf4 Key\cf1 =\cf0 '\cf1 direction\cf0 '\cf1 \cf4 Value\cf1 =\cf0 '\cf1 north\cf0 '\cf1 />\par ?? </\cf3 dictionary\cf1 >\par ?? </\cf3 DefaultInstance\cf1 >}
-->
- <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
+ <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"
+ class="code-sample">
<p style="margin: 0px;">
<span style="color: blue;"> <</span><span style="color: #a31515;">DefaultInstance</span></p>
<p style="margin: 0px;">
@@ -456,7 +464,7 @@
<p>Just create a new node for the IDictionary property called <[propertyName]> under
the main instance node. Then add a <Pair Key="key" Value="value"/> node
for each name/value pair in the IDictionary. </p>
-<p> </p>
+ <hr />
</body>
</html>
Added: trunk/Source/HTML/AutoMocker.htm
===================================================================
--- trunk/Source/HTML/AutoMocker.htm (rev 0)
+++ trunk/Source/HTML/AutoMocker.htm 2009-01-02 23:58:17 UTC (rev 213)
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+ <head>
+ <title></title>
+ </head>
+ <body>
+
+ </body>
+</html>
\ No newline at end of file
Added: trunk/Source/HTML/AutoWiring.htm
===================================================================
--- trunk/Source/HTML/AutoWiring.htm (rev 0)
+++ trunk/Source/HTML/AutoWiring.htm 2009-01-02 23:58:17 UTC (rev 213)
@@ -0,0 +1,461 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+ <head>
+ <title>Auto Wiring</title>
+ <link rel="stylesheet" type="text/css" href="style.css" />
+ <script type="text/javascript" src="jquery-1.2.6.js"></script>
+ <script type="text/javascript" src="structuremap.js"></script>
+ </head>
+ <body>
+ <p>
+ The best way to use an IoC container is to allow "Auto Wiring" to do most of the
+ work for you. IoC Containers like StructureMap are an infrastructure
+ concern, and as such, should be isolated from as much of your code as possible.
+ Before examining Auto Wiring in depth, let's look at a common anti pattern of
+ IoC usage:</p>
+ <h2>
+ IoC Container Anti-Pattern</h2>
+ <p>
+ One of the worst, but sadly most common, usages of an IoC container is
+ shown below:</p>
+<!--
+{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green128\blue0;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 // This is the way to write a Constructor Function with an IoC tool\par ??\cf0 \cf3 // Let the IoC container "inject" services from outside, and keep\par ??\cf0 \cf3 // ShippingScreenPresenter ignorant of the IoC infrastructure\par ??\cf0 \cf4 public\cf0 ShippingScreenPresenter(\cf5 IShippingService\cf0 service, \cf5 IRepository\cf0 repository)\par ?? \{\par ?? _service = service;\par ?? _repository = repository;\par ?? \}\par ??\par ?? \cf3 // FAIL!\par ??\cf0 \cf3 // This is the wrong way to use an IoC container. Do NOT invoke the container from\par ??\cf0 \cf3 // the constructor function. This tightly couples the ShippingScreenPresenter to\par ??\cf0 \cf3 // the IoC container in a harmful way. This class cannot be used in either\par ??\cf0 \cf3 // production or testing without a valid IoC configuration. Plus, you're writing more\par ??\cf0 \cf3 // code\par ??\cf0 \cf4 public\cf0 ShippingScreenPresenter()\par ?? \{\par ?? _service = \cf5 ObjectFactory\cf0 .GetInstance<\cf5 IShippingService\cf0 >();\par ?? _repository = \cf5 ObjectFactory\cf0 .GetInstance<\cf5 IRepository\cf0 >();\par ?? \}}
+-->
+ <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;">
+ <p style="margin: 0px;">
+ <span style="color: green;">// This is the way to
+ write a Constructor Function with an IoC tool</span></p>
+ <p style="margin: 0px;">
+ <span style="color: green;">// Let the IoC container
+ "inject" services from outside, and keep</span></p>
+ <p style="margin: 0px;">
+ <span style="color: green;">//
+ ShippingScreenPresenter ignorant of the IoC infrastructure</span></p>
+ <p style="margin: 0px;">
+ <span style="color: blue;">public</span>
+ ShippingScreenPresenter(<span style="color: #2b91af;">IShippingService</span>
+ service, <span style="color: #2b91af;">IRepository</span> repository)</p>
+ <p style="margin: 0px;">
+ {</p>
+ <p style="margin: 0px;">
+ _service = service;</p>
+ <p style="margin: 0px;">
+ _repository = repository;</p>
+ <p style="margin: 0px;">
+ }</p>
+ <p style="margin: 0px;">
+ </p>
+ <p style="margin: 0px;">
+ <span style="color: green;">// FAIL!</span></p>
+ <p style="margin: 0px;">
+ <span style="color: green;">// This is the wrong way
+ to use an IoC container. Do NOT invoke the container from</span></p>
+ <p style="margin: 0px;">
+ <span style="color: green;">// the constructor
+ function. This tightly couples the ShippingScreenPresenter to</span></p>
+ <p style="margin: 0px;">
+ <span style="color: green;">// the IoC container in a
+ harmful way. This class cannot be used in either</span></p>
+ <p style="margin: 0px;">
+ <span style="color: green;">// production or testing
+ without a valid IoC configuration. Plus, you're writing more</span></p>
+ <p style="margin: 0px;">
+ <span style="color: green;">// code</span></p>
+ <p style="margin: 0px;">
+ <span style="color: blue;">public</span>
+ ShippingScreenPresenter()</p>
+ <p style="margin: 0px;">
+ {</p>
+ <p style="margin: 0px;">
+ _service =
+ <span style="color: #2b91af;">ObjectFactory</span>.GetInstance<<span
+ style="color: #2b91af;">IShippingService</span>>();</p>
+ <p style="margin: 0px;">
+ _repository =
+ <span style="color: #2b91af;">ObjectFactory</span>.GetInstance<<span
+ style="color: #2b91af;">IRepository</span>>();</p>
+ <p style="margin: 0px;">
+ }</p>
+ </div>
+<!--EndFragment-->
+<hr />
+ <h2>
+ Example</h2>
+ <p>
+ Typically, you’ll try to
+ minimize the number of service locator[LINK] usages in your system to a bare minimum
+ (I found 8 in my current system, but I think I’ll find a way to prune half of
+ those later). Most of the value of an IoC tool is in automatically doing
+ Dependency Injection. I’m working with the new MVC framework at the
+ moment, so it’s a handy sample. Let’s say that we have a Controller class
+ for a typical CRUD screen. That Controller class will generally need to
+ interact with both validation services and the data access functionality of the
+ Repository. Here’s a representative Controller class:-RIGHT: black thin solid; BORDER-TOP: black thin solid; FONT-SIZE: 10pt; BACKGROUND: white; OVERFLOW: scroll; BORDER-LEFT: black thin solid; COLOR: black; BORDER-BOTTOM: black thin solid; FONT-FAMILY: courier new">
+ <p style="MARGIN: 0px">
+ <span style="COLOR: blue">public</span> <span style="COLOR: blue">class</span>
+ <span style="COLOR: #2b91af">SomeScreenController</span> :
+ <span style="COLOR: #2b91af">IController</span></p>
+ <p style="MARGIN: 0px">
+ {</p>
+ <p style="MARGIN: 0px">
+ <span style="COLOR: blue">private</span>
+ <span style="COLOR: blue">readonly</span> <span style="COLOR: #2b91af">
+ IRepository</span> _repository;</p>
+ <p style="MARGIN: 0px">
+ <span style="COLOR: blue">private</span>
+ <span style="COLOR: blue">readonly</span> <span style="COLOR: #2b91af">
+ IValidator</span> _validator;</p>
+ <p style="MARGIN: 0px">
+ </p>
+ <p style="MARGIN: 0px">
+ <span style="COLOR: green">// SomeScreenController
+ depends on both IRepository and IValidator</span></p>
+ <p style="MARGIN: 0px">
+ <span style="COLOR: blue">public</span>
+ SomeScreenController(<span style="COLOR: #2b91af">IRepository</span> repository,
+ <span style="COLOR: #2b91af">IValidator</span> validator)</p>
+ <p style="MARGIN: 0px">
+ {</p>
+ <p style="MARGIN: 0px">
+ _repository = repository;</p>
+ <p style="MARGIN: 0px">
+ _validator = validator;</p>
+ <p style="MARGIN: 0px">
+ }</p>
+ <p style="MARGIN: 0px">
+ </p>
+ <p style="MARGIN: 0px">
+ }</p>
+ </div>
+ <p>
+ So let’s get StructureMap set up for this SomeScreenController class:</p>
+ <div style="BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; FONT-SIZE: 10pt; BACKGROUND: white; OVERFLOW: scroll; BORDER-LEFT: black thin solid; COLOR: black; BORDER-BOTTOM: black thin solid; FONT-FAMILY: courier new">
+ <p style="MARGIN: 0px">
+ <span style="COLOR: #2b91af">
+ ObjectFactory</span>.Initialize(x =></p>
+ <p style="MARGIN: 0px">
+ {</p>
+ <p style="MARGIN: 0px">
+
+ <span style="COLOR: green">// Set up the IValidator</span></p>
+ <p style="MARGIN: 0px">
+
+ x.ForRequestedType<<span style="COLOR: #2b91af">IValidator</span>>().TheDefaultIsConcreteType<<span
+ style="COLOR: #2b91af">Validator</span>>();</p>
+ <p style="MARGIN: 0px">
+ </p>
+ <p style="MARGIN: 0px">
+
+ <span style="COLOR: green">// Set up the IRepository</span></p>
+ <p style="MARGIN: 0px">
+
+ x.ForRequestedType<<span style="COLOR: #2b91af">IRepository</span>>().TheDefault.Is.OfConcreteType<<span
+ style="COLOR: #2b91af">Repository</span>>()</p>
+ <p style="MARGIN: 0px">
+
+ .WithCtorArg(<span style="COLOR: #a31515">"connectionString"</span>).EqualToAppSetting(<span
+ style="COLOR: #a31515">"CONNECTION-STRING"</span>);</p>
+ <p style="MARGIN: 0px">
+ });</p>
+ </div>
+ <p>
+ You’ll notice that we didn’t make any explicit configuration for the
+ SomeScreenController class, but yet we could now call:</p>
+ <div style="BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; FONT-SIZE: 10pt; BACKGROUND: white; OVERFLOW: scroll; BORDER-LEFT: black thin solid; COLOR: black; BORDER-BOTTOM: black thin solid; FONT-FAMILY: courier new">
+ <p style="MARGIN: 0px">
+ <span style="COLOR: blue">var</span>
+ controller = <span style="COLOR: #2b91af">ObjectFactory</span>.GetInstance<<span
+ style="COLOR: #2b91af">SomeScreenController</span>>();</p>
+ </div>
+ <p>
+ and StructureMap will happily create a new instance of the SomeScreenController
+ class by invoking its constructor and passing in a new Validator object and a
+ new Repository object created with the connection string from the App.config
+ file. We didn’t need to tell StructureMap how to construct
+ SomeScreenController because:
+ </p>
+ <ul>
+ <li>StructureMap can look at the constructor function of SomeScreenController and
+ see that it depends on IValidator and IRepository </li>
+ <li>StructureMap “knows” about the default way to create and return an IValidator
+ and an IRepository </li>
+ </ul>
+ <p>
+ This feature is known as “auto wiring,” and all the mainstream IoC containers
+ support this feature to some extent or another.
+ </p>
+ <hr />
+ <h2>StructureMap's Policies for Auto Wiring</h2>
+ <p>By default, as long as an object is being created by invoking its constructor
+ function, StructureMap will try to create/resolve/find an object for each
+ non-primitive dependency in the requested concrete type. If StructureMap
+ doesn't "know" how to find a requested dependency, it will throw an exception.
+ By design, StructureMap cannot auto wire primitive arguments like strings and
+ numbers. The Auto Wiring can be overriden by explicit configuration (this
+ might actually be easier with Xml configuration):</p>
+<!--
+{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 registry.InstanceOf<\cf3 Rule\cf0 >()\par ?? .Is.OfConcreteType<\cf3 WidgetRule\cf0 >()\par ?? .WithName(\cf4 "TheWidgetRule"\cf0 )\par ?? .CtorDependency<\cf3 IWidget\cf0 >().Is(i => i.TheInstanceNamed(\cf4 "Yellow"\cf0 ));}
+-->
+ <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;">
+ <p style="margin: 0px;">
+
+ registry.InstanceOf<<span style="color: #2b91af;">Rule</span>>()</p>
+ <p style="margin: 0px;">
+
+ .Is.OfConcreteType<<span style="color: #2b91af;">WidgetRule</span>>()</p>
+ <p style="margin: 0px;">
+
+ .WithName(<span style="color: #a31515;">"TheWidgetRule"</span>)</p>
+ <p style="margin: 0px;">
+
+ .CtorDependency<<span style="color: #2b91af;">IWidget</span>>().Is(i =>
+ i.TheInstanceNamed(<span style="color: #a31515;">"Yellow"</span>));</p>
+ </div>
+<!--EndFragment-->
+<p>In the example above, the IWidget dependency of the WidgetRule class is
+ overriden.</p>
+ <hr />
+ <h4>Object Identity within a Single Request</h4>
+ <p>TODO</p>
+ <hr />
+ <h4>Injecting Arrays of Services</h4>
+ <p>TODO</p>
+<!--
+{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;\red0\green128\blue0;}??\fs20 \cf3 public\cf0 \cf3 interface\cf0 \cf4 IValidator\par ??\cf0 \{\par ?? \}\par ??\par ?? \cf3 public\cf0 \cf3 class\cf0 \cf4 Validator\cf0 : \cf4 IValidator\par ??\cf0 \{\par ?? \cf3 private\cf0 \cf3 readonly\cf0 \cf3 string\cf0 _name;\par ??\par ?? \cf3 public\cf0 Validator(\cf3 string\cf0 name)\par ?? \{\par ?? _name = name;\par ?? \}\par ??\par ?? \cf3 public\cf0 \cf3 override\cf0 \cf3 string\cf0 ToString()\par ?? \{\par ?? \cf3 return\cf0 \cf3 string\cf0 .Format(\cf5 "Name: \{0\}"\cf0 , _name);\par ?? \}\par ?? \}\par ??\par ?? \cf3 public\cf0 \cf3 class\cf0 \cf4 ClassThatUsesValidators\par ??\cf0 \{\par ?? \cf3 private\cf0 \cf3 readonly\cf0 \cf4 IValidator\cf0 [] _validators;\par ??\par ?? \cf3 public\cf0 ClassThatUsesValidators(\cf4 IValidator\cf0 [] validators)\par ?? \{\par ?? _validators = validators;\par ?? \}\par ??\par ?? \cf3 public\cf0 \cf3 void\cf0 Write()\par ?? \{\par ?? \cf3 foreach\cf0 (\cf4 IValidator\cf0 validator \cf3 in\cf0 _validators)\par ?? \{\par ?? \cf4 Debug\cf0 .WriteLine(validator);\par ?? \}\par ?? \}\par ?? \}\par ??\par ?? [\cf4 TestFixture\cf0 ]\par ?? \cf3 public\cf0 \cf3 class\cf0 \cf4 ValidatorExamples\par ??\cf0 \{\par ?? \cf3 private\cf0 \cf4 Container\cf0 container;\par ??\par ?? [\cf4 SetUp\cf0 ]\par ?? \cf3 public\cf0 \cf3 void\cf0 SetUp()\par ?? \{\par ?? container = \cf3 new\cf0 \cf4 Container\cf0 (x =>\par ?? \{\par ?? x.ForRequestedType<\cf4 IValidator\cf0 >().AddInstances(o =>\par ?? \{\par ?? o.OfConcreteType<\cf4 Validator\cf0 >().WithCtorArg(\cf5 "name"\cf0 ).EqualTo(\cf5 "Red"\cf0 ).WithName(\cf5 "Red"\cf0 );\par ?? o.OfConcreteType<\cf4 Validator\cf0 >().WithCtorArg(\cf5 "name"\cf0 ).EqualTo(\cf5 "Blue"\cf0 ).WithName(\cf5 "Blue"\cf0 );\par ?? o.OfConcreteType<\cf4 Validator\cf0 >().WithCtorArg(\cf5 "name"\cf0 ).EqualTo(\cf5 "Purple"\cf0 ).WithName(\cf5 "Purple"\cf0 );\par ?? o.OfConcreteType<\cf4 Validator\cf0 >().WithCtorArg(\cf5 "name"\cf0 ).EqualTo(\cf5 "Green"\cf0 ).WithName(\cf5 "Green"\cf0 );\par ?? \});\par ??\par ?? x.ForRequestedType<\cf4 ClassThatUsesValidators\cf0 >().AddInstances(o =>\par ?? \{\par ?? \cf6 // Define an Instance of ClassThatUsesValidators that depends on AutoWiring\par ??\cf0 o.OfConcreteType<\cf4 ClassThatUsesValidators\cf0 >().WithName(\cf5 "WithAutoWiring"\cf0 );\par ??\par ?? \cf6 // Define an Instance of ClassThatUsesValidators that overrides AutoWiring\par ??\cf0 o.OfConcreteType<\cf4 ClassThatUsesValidators\cf0 >().WithName(\cf5 "ExplicitArray"\cf0 )\par ?? .TheArrayOf<\cf4 IValidator\cf0 >().Contains(y =>\par ?? \{\par ?? y.TheInstanceNamed(\cf5 "Red"\cf0 );\par ?? y.TheInstanceNamed(\cf5 "Green"\cf0 );\par ?? \});\par ?? \});\par ?? \});\par ?? \}\par ??\par ?? [\cf4 Test\cf0 ]\par ?? \cf3 public\cf0 \cf3 void\cf0 what_are_the_validators()\par ?? \{\par ?? \cf4 Debug\cf0 .WriteLine(\cf5 "With Auto Wiring"\cf0 );\par ?? container.GetInstance<\cf4 ClassThatUsesValidators\cf0 >(\cf5 "WithAutoWiring"\cf0 ).Write();\par ?? \cf4 Debug\cf0 .WriteLine(\cf5 "================================="\cf0 );\par ?? \cf4 Debug\cf0 .WriteLine(\cf5 "With Explicit Configuration"\cf0 );\par ?? container.GetInstance<\cf4 ClassThatUsesValidators\cf0 >(\cf5 "ExplicitArray"\cf0 ).Write();\par ?? \}\par ?? \}}
+-->
+ <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;">
+ <p style="margin: 0px;">
+ <span style="color: blue;">public</span> <span style="color: blue;">interface</span>
+ <span style="color: #2b91af;">IValidator</span></p>
+ <p style="margin: 0px;">
+ {</p>
+ <p style="margin: 0px;">
+ }</p>
+ <p style="margin: 0px;">
+ </p>
+ <p style="margin: 0px;">
+ <span style="color: blue;">public</span> <span style="color: blue;">class</span>
+ <span style="color: #2b91af;">Validator</span> : <span style="color: #2b91af;">
+ IValidator</span></p>
+ <p style="margin: 0px;">
+ {</p>
+ <p style="margin: 0px;">
+ <span style="color: blue;">private</span>
+ <span style="color: blue;">readonly</span> <span style="color: blue;">string</span>
+ _name;</p>
+ <p style="margin: 0px;">
+ </p>
+ <p style="margin: 0px;">
+ <span style="color: blue;">public</span> Validator(<span
+ style="color: blue;">string</span> name)</p>
+ <p style="margin: 0px;">
+ {</p>
+ <p style="margin: 0px;">
+ _name = name;</p>
+ <p style="margin: 0px;">
+ }</p>
+ <p style="margin: 0px;">
+ </p>
+ <p style="margin: 0px;">
+ <span style="color: blue;">public</span>
+ <span style="color: blue;">override</span> <span style="color: blue;">string</span>
+ ToString()</p>
+ <p style="margin: 0px;">
+ {</p>
+ <p style="margin: 0px;">
+ <span style="color: blue;">
+ return</span> <span style="color: blue;">string</span>.Format(<span
+ style="color: #a31515;">"Name: {0}"</span>, _name);</p>
+ <p style="margin: 0px;">
+ }</p>
+ <p style="margin: 0px;">
+ }</p>
+ <p style="margin: 0px;">
+ </p>
+ <p style="margin: 0px;">
+ <span style="color: blue;">public</span> <span style="color: blue;">class</span>
+ <span style="color: #2b91af;">ClassThatUsesValidators</span></p>
+ <p style="margin: 0px;">
+ {</p>
+ <p style="margin: 0px;">
+ <span style="color: blue;">private</span>
+ <span style="color: blue;">readonly</span> <span style="color: #2b91af;">
+ IValidator</span>[] _validators;</p>
+ <p style="margin: 0px;">
+ </p>
+ <p style="margin: 0px;">
+ <span style="color: blue;">public</span>
+ ClassThatUsesValidators(<span style="color: #2b91af;">IValidator</span>[]
+ validators)</p>
+ <p style="margin: 0px;">
+ {</p>
+ <p style="margin: 0px;">
+ _validators = validators;</p>
+ <p style="margin: 0px;">
+ }</p>
+ <p style="margin: 0px;">
+ </p>
+ <p style="margin: 0px;">
+ <span style="color: blue;">public</span>
+ <span style="color: blue;">void</span> Write()</p>
+ <p style="margin: 0px;">
+ {</p>
+ <p style="margin: 0px;">
+ <span style="color: blue;">
+ foreach</span> (<span style="color: #2b91af;">IValidator</span> validator
+ <span style="color: blue;">in</span> _validators)</p>
+ <p style="margin: 0px;">
+ {</p>
+ <p style="margin: 0px;">
+
+ <span style="color: #2b91af;">Debug</span>.WriteLine(validator);</p>
+ <p style="margin: 0px;">
+ }</p>
+ <p style="margin: 0px;">
+ }</p>
+ <p style="margin: 0px;">
+ }</p>
+ <p style="margin: 0px;">
+ </p>
+ <p style="margin: 0px;">
+ [<span style="color: #2b91af;">TestFixture</span>]</p>
+ <p style="margin: 0px;">
+ <span style="color: blue;">public</span> <span style="color: blue;">class</span>
+ <span style="color: #2b91af;">ValidatorExamples</span></p>
+ <p style="margin: 0px;">
+ {</p>
+ <p style="margin: 0px;">
+ <span style="color: blue;">private</span>
+ <span style="color: #2b91af;">Container</span> container;</p>
+ <p style="margin: 0px;">
+ </p>
+ <p style="margin: 0px;">
+ [<span style="color: #2b91af;">SetUp</span>]</p>
+ <p style="margin: 0px;">
+ <span style="color: blue;">public</span>
+ <span style="color: blue;">void</span> SetUp()</p>
+ <p style="margin: 0px;">
+ {</p>
+ <p style="margin: 0px;">
+ container =
+ <span style="color: blue;">new</span> <span style="color: #2b91af;">Container</span>(x
+ =></p>
+ <p style="margin: 0px;">
+ {</p>
+ <p style="margin: 0px;">
+
+ x.ForRequestedType<<span style="color: #2b91af;">IValidator</span>>().AddInstances(o
+ =></p>
+ <p style="margin: 0px;">
+ {</p>
+ <p style="margin: 0px;">
+
+ o.OfConcreteType<<span style="color: #2b91af;">Validator</span>>().WithCtorArg(<span
+ style="color: #a31515;">"name"</span>).EqualTo(<span
+ style="color: #a31515;">"Red"</span>).WithName(<span
+ style="color: #a31515;">"Red"</span>);</p>
+ <p style="margin: 0px;">
+
+ o.OfConcreteType<<span style="color: #2b91af;">Validator</span>>().WithCtorArg(<span
+ style="color: #a31515;">"name"</span>).EqualTo(<span
+ style="color: #a31515;">"Blue"</span>).WithName(<span
+ style="color: #a31515;">"Blue"</span>);</p>
+ <p style="margin: 0px;">
+
+ o.OfConcreteType<<span style="color: #2b91af;">Validator</span>>().WithCtorArg(<span
+ style="color: #a31515;">"name"</span>).EqualTo(<span
+ style="color: #a31515;">"Purple"</span>).WithName(<span
+ style="color: #a31515;">"Purple"</span>);</p>
+ <p style="margin: 0px;">
+
+ o.OfConcreteType<<span style="color: #2b91af;">Validator</span>>().WithCtorArg(<span
+ style="color: #a31515;">"name"</span>).EqualTo(<span
+ style="color: #a31515;">"Green"</span>).WithName(<span
+ style="color: #a31515;">"Green"</span>);</p>
+ <p style="margin: 0px;">
+ });</p>
+ <p style="margin: 0px;">
+ </p>
+ <p style="margin: 0px;">
+
+ x.ForRequestedType<<span style="color: #2b91af;">ClassThatUsesValidators</span>>().AddInstances(o
+ =></p>
+ <p style="margin: 0px;">
+ {</p>
+ <p style="margin: 0px;">
+
+ <span style="color: green;">// Define an Instance of ClassThatUsesValidators
+ that depends on AutoWiring</span></p>
+ <p style="margin: 0px;">
+
+ o.OfConcreteType<<span style="color: #2b91af;">ClassThatUsesValidators</span>>().WithName(<span
+ style="color: #a31515;">"WithAutoWiring"</span>);</p>
+ <p style="margin: 0px;">
+ </p>
+ <p style="margin: 0px;">
+
+ <span style="color: green;">// Define an Instance of ClassThatUsesValidators
+ that overrides AutoWiring</span></p>
+ <p style="margin: 0px;">
+
+ o.OfConcreteType<<span style="color: #2b91af;">ClassThatUsesValidators</span>>().WithName(<span
+ style="color: #a31515;">"ExplicitArray"</span>)</p>
+ <p style="margin: 0px;">
+
+ .TheArrayOf<<span style="color: #2b91af;">IValidator</span>>().Contains(y =></p>
+ <p style="margin: 0px;">
+
+ {</p>
+ <p style="margin: 0px;">
+
+ y.TheInstanceNamed(<span style="color: #a31515;">"Red"</span>);</p>
+ <p style="margin: 0px;">
+
+ y.TheInstanceNamed(<span style="color: #a31515;">"Green"</span>);</p>
+ <p style="margin: 0px;">
+
+ });</p>
+ <p style="margin: 0px;">
+ });</p>
+ <p style="margin: 0px;">
+ });</p>
+ <p style="margin: 0px;">
+ }</p>
+ <p style="margin: 0px;">
+ </p>
+ <p style="margin: 0px;">
+ [<span style="color: #2b91af;">Test</span>]</p>
+ <p style="margin: 0px;">
+ <span style="color: blue;">public</span>
+ <span style="color: blue;">void</span> what_are_the_validators()</p>
+ <p style="margin: 0px;">
+ {</p>
+ <p style="margin: 0px;">
+ <span style="color: #2b91af;">
+ Debug</span>.WriteLine(<span style="color: #a31515;">"With Auto Wiring"</span>);</p>
+ <p style="margin: 0px;">
+ container.GetInstance<<span
+ style="color: #2b91af;">ClassThatUsesValidators</span>>(<span
+ style="color: #a31515;">"WithAutoWiring"</span>).Write();</p>
+ <p style="margin: 0px;">
+ <span style="color: #2b91af;">
+ Debug</span>.WriteLine(<span style="color: #a31515;">"================================="</span>);</p>
+ <p style="margin: 0px;">
+ <span style="color: #2b91af;">
+ Debug</span>.WriteLine(<span style="color: #a31515;">"With Explicit
+ Configuration"</span>);</p>
+ <p style="margin: 0px;">
+ container.GetInstance<<span
+ style="color: #2b91af;">ClassThatUsesValidators</span>>(<span
+ style="color: #a31515;">"ExplicitArray"</span>).Write();</p>
+ <p style="margin: 0px;">
+ }</p>
+ <p style="margin: 0px;">
+ }</p>
+ </div>
+<!--EndFragment-->
+<p> </p>
+ <p> </p>
+ <hr />
+ </body>
+</html>
\ No newline at end of file
Copied: trunk/Source/HTML/ChangingConfigurationAtRuntime.htm (from rev 204, trunk/Source/HTML/InjectingServicesAtRuntime.htm)
===================================================================
--- trunk/Source/HTML/ChangingConfigurationAtRuntime.htm (rev 0)
+++ trunk/Source/HTML/ChangingConfigurationAtRuntime.htm 2009-01-02 23:58:17 UTC (rev 213)
@@ -0,0 +1,405 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+ <head>
+ <title>Changing Configuration at Runtime</title>
+ <link rel="stylesheet" type="text/css" href="style.css" />
+ <script type="text/javascript" src="jquery-1.2.6.js"></script>
+ <script type="text/javascript" src="structuremap.js"></script>
+ </head>
+ <body>
+ <p>In the beginning (late 2003), there was attributes and there was a copious amount of Xml configuration, and I called it good.
+ Look Ma! I can radically change the behavior of the code without
+ recompiling, isn't that a marvelous thing?
+ Then we started to use StructureMap on a real project and quickly realized that
+ it would be very useful if we could override some services with mock objects in
+ our unit tests. In later projects I've run into scenarios where it would
+ be valuable to put an object into StructureMap after it was created. Other
+ users have asked for the ability to load assemblies or modules of their system
+ on demand so as to save memory. A major goal of the StructureMap 2.5
+ release has been to greatly extend its capabilities for service registration at
+ runtime. With a very few exceptions, you can now make any and all
+ configuration changes after the first call to ObjectFactory. My
+ recommendation is to use this behavior simply and with caution because it will
+ bypass many of the diagnostic abilities built into StructureMap (i.e.
+ StructureMapDoctor might miss configuration problems introduced outside of the
+ normal configuration).</p>
+<h2>
+ Adding Configuration to an Existing Container</h2>
+<p>
+ In contrast to Initialize(), the Configure() method allows you to add additional
+ configuration to an existing Container or ObjectFactory. Think of this
+ scenario. You're building a composite application that contains multiple
+ modules spread over several assemblies, but you might not want to load any of
+ the configuration or types for a particular module until it's requested by the
+ user. In that case, you can use the Configure() method like this:</p>
+<!--
+{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green128\blue0;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf3 // This code would add any configuration from\par ??\cf0 \cf3 // Registry classes found in the \par ??\cf0 \cf3 // assembly named 'MyApplication.Module1'\par ??\cf0 \cf4 ObjectFactory\cf0 .Configure(x =>\par ?? \{\par ?? x.Scan(scan =>\par ?? \{\par ?? scan.LookForRegistries();\par ?? scan.Assembly(\cf5 "MyApplication.Module1"\cf0 );\par ?? \});\par ?? \});}
+-->
+<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid; overflow: scroll;">
+ <p style="margin: 0px;">
+
+ <span style="color: green;">// This code would add any configuration from</span></p>
+ <p style="margin: 0px;">
+
+ <span style="color: green;">// Registry classes found in the </span>
+ </p>
+ <p style="margin: 0px;">
+
+ <span style="color: green;">// assembly named 'MyApplication.Module1'</span></p>
+ <p style="margin: 0px;">
+
+ <span style="color: #2b91af;">ObjectFactory</span>.Configure(x =></p>
+ <p style="margin: 0px;">
+ {</p>
+ <p style="margin: 0px;">
+ ...
[truncated message content] |