From: <jer...@us...> - 2008-10-27 01:07:32
|
Revision: 193 http://structuremap.svn.sourceforge.net/structuremap/?rev=193&view=rev Author: jeremydmiller Date: 2008-10-27 01:07:28 +0000 (Mon, 27 Oct 2008) Log Message: ----------- Making the final check in (knock on wood) for the 2.5 binary release Modified Paths: -------------- trunk/Source/HTML/ConfiguringStructureMap.htm trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/ConfigurationExpression.cs trunk/Source/StructureMap/Graph/AssemblyScanner.cs trunk/Source/StructureMap/InitializationExpression.cs trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs trunk/Source/StructureMap/Interceptors/InstanceInterceptor.cs trunk/Source/StructureMap/Pipeline/BuildFrame.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs trunk/Source/StructureMap/Pipeline/IBuildInterceptor.cs trunk/Source/StructureMap/Pipeline/IBuildPolicy.cs trunk/Source/StructureMap/Pipeline/Instance.cs trunk/Source/StructureMap/Pipeline/SmartInstance.cs trunk/Source/StructureMap.AutoMocking/AutoMocker.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs trunk/Source/StructureMap.Testing/ModelQueryTester.cs trunk/Source/StructureMap.Testing/ObjectFactoryInitializeTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.dll.config Modified: trunk/Source/HTML/ConfiguringStructureMap.htm =================================================================== --- trunk/Source/HTML/ConfiguringStructureMap.htm 2008-10-23 23:02:07 UTC (rev 192) +++ trunk/Source/HTML/ConfiguringStructureMap.htm 2008-10-27 01:07:28 UTC (rev 193) @@ -15,14 +15,14 @@ else from the initial releases to StructureMap 2.5. You have three forms of configuration to choose from:</p> <ol> - <li>The Registry DSL</li> + <li>The Registry DSL -- The programmatic API for configuring the Container in code.</li> <li>Xml configuration (StructureMap.config, the App.config file, or named files)</li> - <li>StructureMap Attributes</li> + <li>StructureMap Attributes -- Not deprecated, but not really recommended either. </li> </ol> <p> The configuration is highly modular and you can mix and match configuration choices within the same Container instance. The strong recommendation is - to use the Registry DSL as much as possible, and use the Xml configuration + to use the Registry DSL as much as possible, then use the Xml configuration strictly for configuration that absolutely must be external to the code (connection strings, file paths, Url's, etc.). The attributes are deprecated and largely unnecessary now, but still supported for backwards @@ -42,89 +42,433 @@ <h4> Initializing the Container</h4> <p> - The recommended mechanism for initializing the Container is the Initialize() - method. The Initialize() method is a Nested Closure that acts against an - InitializationExpression object. The InitializationExpression has methods + The recommended mechanism for initializing the Container or ObjectFactory is the Initialize() + method. The Initialize() method is new for StructureMap 2.5, and largely + driven by (my current love affair with Lambda's) the confusion and misuse of + StructureMapConfiguration. StructureMapConfiguration is still supported, + but it is deprecated in the code and will be eliminated in a future release. Initialize() is a Nested Closure that + gives you a chance to express directives telling the Container how to construct + itself and add one or more sources of configuration. </p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\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 Container(\cf4 Action\cf0 <\cf4 ConfigurationExpression\cf0 > action)\par ?? \{\par ?? \cf3 var\cf0 expression = \cf3 new\cf0 \cf4 ConfigurationExpression\cf0 ();\par ?? action(expression);\par ??\par ?? construct(expression.BuildGraph());\par ?? \}} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: blue; overflow: scroll;">public Container(</span><span + style="color: #2b91af; overflow: scroll;">Action</span><span + style="overflow: scroll;"><</span><span + style="color: #2b91af; overflow: scroll;">ConfigurationExpression</span><span + style="overflow: scroll;">> action)</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> {</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: blue; overflow: scroll;">var</span><span + style="overflow: scroll;"> expression = </span> + <span style="color: blue; overflow: scroll;">new</span><span + style="overflow: scroll;"> </span> + <span style="color: #2b91af; overflow: scroll;">ConfigurationExpression</span><span + style="overflow: scroll;">();</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + action(expression);</span></p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + construct(expression.BuildGraph());</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> }</span></p> +</div> +<!--EndFragment--> +</div> +<!--EndFragment--> +<p> + Typically, you would make a single call to the Initialize() method at + application start up (Global.asax for web application, or the main routine for a + desktop application). The Container (ObjectFactory is simply a static + wrapper around a single Container) is completely initialized and configured by + the Initialize() method in one atomic action. <b>Any successive calls to + Initialize() will effectively wipe out any existing configuration and + effectively restart the Container.</b> Here's a sample usage of + Initialize():</p> + +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;}??\fs20 \cf3 ObjectFactory\cf0 .Initialize(x =>\par ?? \{\par ?? x.UseDefaultStructureMapConfigFile = \cf4 true\cf0 ;\par ??\par ?? x.AddRegistry(\cf4 new\cf0 \cf3 CoreRegistry\cf0 ());\par ?? x.AddRegistry(\cf4 new\cf0 \cf3 SearchRegistry\cf0 ());\par ?? x.AddRegistry(\cf4 new\cf0 \cf3 WebCoreRegistry\cf0 ());\par ?? x.AddRegistry(\cf4 new\cf0 \cf3 WebRegistry\cf0 ());\par ?? x.AddRegistry(\cf4 new\cf0 \cf3 RuleRegistry\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="overflow: scroll;"> + </span><span style="color: #2b91af; overflow: scroll;">ObjectFactory</span><span + style="overflow: scroll;">.Initialize(x =></span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + {</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + x.UseDefaultStructureMapConfigFile = </span> + <span style="color: blue; overflow: scroll;">true</span><span + style="overflow: scroll;">;</span></p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + x.AddRegistry(</span><span style="color: blue; overflow: scroll;">new</span><span + style="overflow: scroll;"> </span> + <span style="color: #2b91af; overflow: scroll;">CoreRegistry</span><span + style="overflow: scroll;">());</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + x.AddRegistry(</span><span style="color: blue; overflow: scroll;">new</span><span + style="overflow: scroll;"> </span> + <span style="color: #2b91af; overflow: scroll;">SearchRegistry</span><span + style="overflow: scroll;">());</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + x.AddRegistry(</span><span style="color: blue; overflow: scroll;">new</span><span + style="overflow: scroll;"> </span> + <span style="color: #2b91af; overflow: scroll;">WebCoreRegistry</span><span + style="overflow: scroll;">());</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + x.AddRegistry(</span><span style="color: blue; overflow: scroll;">new</span><span + style="overflow: scroll;"> </span> + <span style="color: #2b91af; overflow: scroll;">WebRegistry</span><span + style="overflow: scroll;">());</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + x.AddRegistry(</span><span style="color: blue; overflow: scroll;">new</span><span + style="overflow: scroll;"> </span> + <span style="color: #2b91af; overflow: scroll;">RuleRegistry</span><span + style="overflow: scroll;">());</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + });</span></p> +</div> +<!--EndFragment--> +<p> + Inside the Initialization() method you can declare directives against an + InitializationExpression object. The InitializationExpression object has + these methods for all all the possible configuration directives.</p> - <p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;}??\fs20 \cf3 public\cf0 \cf3 interface\cf0 \cf4 IInitializationExpression\par ??\cf0 \{\par ?? \cf5 // Directives on how to treat the StructureMap.config file\par ??\cf0 \cf3 bool\cf0 UseDefaultStructureMapConfigFile \{ \cf3 set\cf0 ; \}\par ?? \cf3 bool\cf0 IgnoreStructureMapConfig \{ \cf3 set\cf0 ; \}\par ??\par ?? \cf5 // Xml configuration from the App.Config file\par ??\cf0 \cf3 bool\cf0 PullConfigurationFromAppConfig \{ \cf3 set\cf0 ; \}\par ??\par ?? \cf5 // Ancillary sources of Xml configuration\par ??\cf0 \cf3 void\cf0 AddConfigurationFromXmlFile(\cf3 string\cf0 fileName);\par ?? \cf3 void\cf0 AddConfigurationFromNode(\cf4 XmlNode\cf0 node);\par ??\par ?? \cf5 // Specifying Registry's\par ??\cf0 \cf3 void\cf0 AddRegistry<T>() \cf3 where\cf0 T : \cf4 Registry\cf0 , \cf3 new\cf0 ();\par ?? \cf3 void\cf0 AddRegistry(\cf4 Registry\cf0 registry);\par ??\par ?? \cf5 // Designate the Default Profile. This will be applied as soon as the \par ??\cf0 \cf5 // Container is initialized.\par ??\cf0 \cf3 string\cf0 DefaultProfileName \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ??\par ?? \cf5 // ... and the Registry DSL as well\par ??\par ??\cf0 \cf5 // The Registry DSL\par ??\cf0 \cf4 CreatePluginFamilyExpression\cf0 <PLUGINTYPE> BuildInstancesOf<PLUGINTYPE>();\par ?? \cf4 CreatePluginFamilyExpression\cf0 <PLUGINTYPE> ForRequestedType<PLUGINTYPE>();\par ?? \cf4 GenericFamilyExpression\cf0 ForRequestedType(\cf4 Type\cf0 pluginType);\par ?? \cf4 Registry\cf0 .\cf4 BuildWithExpression\cf0 <T> ForConcreteType<T>();\par ??\par ?? \cf4 IsExpression\cf0 <T> InstanceOf<T>();\par ?? \cf4 GenericIsExpression\cf0 InstanceOf(\cf4 Type\cf0 pluginType);\par ??\par ?? \cf4 ProfileExpression\cf0 CreateProfile(\cf3 string\cf0 profileName);\par ?? \cf3 void\cf0 CreateProfile(\cf3 string\cf0 profileName, \cf4 Action\cf0 <\cf4 ProfileExpression\cf0 > action);\par ??\par ?? \cf3 void\cf0 RegisterInterceptor(\cf4 TypeInterceptor\cf0 interceptor);\par ?? \cf4 MatchedTypeInterceptor\cf0 IfTypeMatches(\cf4 Predicate\cf0 <\cf4 Type\cf0 > match);\par ??\par ?? \cf3 void\cf0 Scan(\cf4 Action\cf0 <\cf4 IAssemblyScanner\cf0 > action);\par ??\par ?? \cf4 CreatePluginFamilyExpression\cf0 <PLUGINTYPE> FillAllPropertiesOfType<PLUGINTYPE>();\par ?? \}} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> </p> - <p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> </span> + <span style="color: blue; overflow: scroll;">public</span><span + style="overflow: scroll;"> </span> + <span style="color: blue; overflow: scroll;">interface</span><span + style="overflow: scroll;"> </span> + <span style="color: #2b91af; overflow: scroll;">IInitializationExpression</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> {</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: green; overflow: scroll;">// Directives on how to + treat the StructureMap.config file</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: blue; overflow: scroll;">bool</span><span + style="overflow: scroll;"> UseDefaultStructureMapConfigFile { </span> + <span style="color: blue; overflow: scroll;">set</span><span + style="overflow: scroll;">; }</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: blue; overflow: scroll;">bool</span><span + style="overflow: scroll;"> IgnoreStructureMapConfig { </span> + <span style="color: blue; overflow: scroll;">set</span><span + style="overflow: scroll;">; }</span></p> + <p style="margin: 0px;"> </p> - <p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: green; overflow: scroll;">// Xml configuration from + the App.Config file</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: blue; overflow: scroll;">bool</span><span + style="overflow: scroll;"> PullConfigurationFromAppConfig { </span> + <span style="color: blue; overflow: scroll;">set</span><span + style="overflow: scroll;">; }</span></p> + <p style="margin: 0px;"> </p> - <p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: green; overflow: scroll;">// Ancillary sources of Xml + configuration</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: blue; overflow: scroll;">void</span><span + style="overflow: scroll;"> AddConfigurationFromXmlFile(</span><span + style="color: blue; overflow: scroll;">string</span><span + style="overflow: scroll;"> fileName);</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: blue; overflow: scroll;">void</span><span + style="overflow: scroll;"> AddConfigurationFromNode(</span><span + style="color: #2b91af; overflow: scroll;">XmlNode</span><span + style="overflow: scroll;"> node);</span></p> + <p style="margin: 0px;"> </p> - <h4> - Using a Bootstrapper</h4> - <p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: green; overflow: scroll;">// Specifying Registry's</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: blue; overflow: scroll;">void</span><span + style="overflow: scroll;"> AddRegistry<T>() </span> + <span style="color: blue; overflow: scroll;">where</span><span + style="overflow: scroll;"> T : </span> + <span style="color: #2b91af; overflow: scroll;">Registry</span><span + style="overflow: scroll;">, </span> + <span style="color: blue; overflow: scroll;">new</span><span + style="overflow: scroll;">();</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: blue; overflow: scroll;">void</span><span + style="overflow: scroll;"> AddRegistry(</span><span + style="color: #2b91af; overflow: scroll;">Registry</span><span + style="overflow: scroll;"> registry);</span></p> + <p style="margin: 0px;"> </p> - <p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: green; overflow: scroll;">// Designate the Default + Profile. This will be applied as soon as the </span> + </p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: green; overflow: scroll;">// Container is + initialized.</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: blue; overflow: scroll;">string</span><span + style="overflow: scroll;"> DefaultProfileName { </span> + <span style="color: blue; overflow: scroll;">get</span><span + style="overflow: scroll;">; </span> + <span style="color: blue; overflow: scroll;">set</span><span + style="overflow: scroll;">; }</span></p> + <p style="margin: 0px;"> </p> - <h4> - The StructureMap.config File</h4> - <p> - Historically, StructureMap looked for all of its configuration in a file named - "StructureMap.config" file in the ApplicationBase folder. By default, if - the StructureMap.config file is found in the ApplicationBase folder, the Xml - configuration from StructureMap.config will be applied to the internal container - of ObjectFactory. Technically, you could still do all configuration in the - StructureMap.config file. In this case, the StructureMap.config file would - be read and applied in the first call to any of the ObjectFactory methods that - request services. Likewise, StructureMap will not throw any exceptions if - the StructureMap.config file cannot be found.</p> - <p> - The default behavior can be overriden. First, if you are using the - StructureMap.config file, you might want to make the existence of this file - mandatory to prevent odd problems from missing configuration:</p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: green; overflow: scroll;">// ... and the Registry DSL + as well</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> }</span></p> + <p style="margin: 0px;"> + </p> +</div> +<!--EndFragment--> +<p> + </p> +<h4> + Adding Configuration to an Existing Container</h4> +<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;\red0\green0\blue255;}??\fs20 \cf3 // This code enforces the existence of the StructureMap.config file\par ??\cf0 \cf3 // Initialize() will throw an exception if the StructureMap.config file\par ??\cf0 \cf3 // cannot be found\par ??\cf0 \cf4 ObjectFactory\cf0 .Initialize(x =>\par ?? \{\par ?? x.UseDefaultStructureMapConfigFile = \cf5 true\cf0 ;\par ?? \});} +{\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;"> +<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 enforces the existence of the - StructureMap.config file</span></p> + <span style="color: green;">// This code would add any configuration from</span></p> <p style="margin: 0px;"> - <span style="color: green;">// Initialize() will throw an exception if the - StructureMap.config file</span></p> + <span style="color: green;">// Registry classes found in the </span> + </p> <p style="margin: 0px;"> - <span style="color: green;">// cannot be found</span></p> + <span style="color: green;">// assembly named 'MyApplication.Module1'</span></p> <p style="margin: 0px;"> - <span style="color: #2b91af;">ObjectFactory</span>.Initialize(x =></p> + <span style="color: #2b91af;">ObjectFactory</span>.Configure(x =></p> <p style="margin: 0px;"> {</p> <p style="margin: 0px;"> - x.UseDefaultStructureMapConfigFile = <span style="color: blue;">true</span>;</p> + x.Scan(scan =></p> <p style="margin: 0px;"> + + {</p> + <p style="margin: 0px;"> + + scan.LookForRegistries();</p> + <p style="margin: 0px;"> + + scan.Assembly(<span style="color: #a31515;">"MyApplication.Module1"</span>);</p> + <p style="margin: 0px;"> + + });</p> + <p style="margin: 0px;"> });</p> </div> <!--EndFragment--> <p> - You can also specifically ignore the StructureMap.config file at initialization - time so that the StructureMap.config file will never be used:</p> + To summarize, Initialize() completely resets the configuration of a Container, + and Configure() is purely additive. If Configure() should happen to be + called before Initialize(), it will set up the Container with the configuration + in the Configure() call. Configure() offers a subset of the Initialize() + method (it leaves out the directives for the StructureMap.config file), and it + also includes the entire Registry DSL. You can take advantage of that fact + to add a few types or instances at a time:</p> <!-- -{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;\red163\green21\blue21;}??\fs20 \cf3 ObjectFactory\cf0 .Initialize(x =>\par ?? \{\par ?? x.IgnoreStructureMapConfig = \cf4 true\cf0 ;\par ?? \par ?? x.ForRequestedType<\cf3 IWidget\cf0 >().TheDefault.Is\par ?? .OfConcreteType<\cf3 DoctorTester\cf0 .\cf3 NumberWidget\cf0 >()\par ?? .WithCtorArg(\cf5 "age"\cf0 ).EqualToAppSetting(\cf5 "age"\cf0 );\par ?? \});} +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;}??\fs20 \par ?? \cf3 ObjectFactory\cf0 .Configure(x =>\par ?? \{\par ?? x.ForRequestedType<\cf3 ISomething\cf0 >().TheDefaultIsConcreteType<\cf3 SomethingOne\cf0 >();\par ?? \});\par ??} --> -<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid; overflow: scroll;"> <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> - <span style="color: #2b91af;">ObjectFactory</span>.Initialize(x =></p> + <span style="color: #2b91af;">ObjectFactory</span>.Configure(x =></p> <p style="margin: 0px;"> {</p> <p style="margin: 0px;"> - x.IgnoreStructureMapConfig = <span style="color: blue;">true</span>;</p> + x.ForRequestedType<<span style="color: #2b91af;">ISomething</span>>().TheDefaultIsConcreteType<<span + style="color: #2b91af;">SomethingOne</span>>();</p> <p style="margin: 0px;"> });</p> </div> <!--EndFragment--> <p> - </p> + </p> <p> + </p> +<p> + </p> +<h4> + Using the App.Config File</h4> +<p> + The <a href="http://msdn.microsoft.com/en-us/library/system.configuration.aspx"> + System.Configuration</a> namespace in the .Net framework provides a lot of + functionality for caching and encrypting configuration. To take advantage + of this functionality StructureMap offers an option to embed configuration + directly into the App.config file (web.config for web development). Just + add a section for StructureMap like this:</p> +<!-- +{\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;\red0\green128\blue0;}??\fs20 \cf1 <?\cf3 xml\cf1 \cf4 version\cf1 =\cf0 "\cf1 1.0\cf0 "\cf1 \cf4 encoding\cf1 =\cf0 "\cf1 utf-8\cf0 "\cf1 ?>\par ??<\cf3 configuration\cf1 >\par ?? <\cf3 configSections\cf1 >\par ?? <\cf3 section\cf1 \cf4 name\cf1 =\cf0 "\cf1 StructureMap\cf0 "\cf1 \cf4 type\cf1 =\cf0 "\cf1 StructureMap.Configuration.StructureMapConfigurationSection,StructureMap\cf0 "\cf1 />\par ?? </\cf3 configSections\cf1 >\par ??\par ?? <\cf3 StructureMap\cf1 >\par ?? <!--\cf6 Put StructureMap configuration here \cf1 -->\par ?? \par ?? <\cf3 Assembly\cf1 \cf4 Name\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets\cf0 "\cf1 />\par ??\par ?? <\cf3 PluginFamily\cf1 \cf4 Assembly\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets\cf0 "\cf1 \cf4 Type\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets.IThing`2\cf0 "\cf1 \cf4 DefaultKey\cf1 =\cf0 "\cf1 Cornflower\cf0 "\cf1 >\par ?? <\cf3 Plugin\cf1 \cf4 Assembly\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets\cf0 "\cf1 \cf4 Type\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets.ColorThing`2\cf0 "\cf1 \cf4 ConcreteKey\cf1 =\cf0 "\cf1 Color\cf0 "\cf1 />\par ?? <\cf3 Plugin\cf1 \cf4 Assembly\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets\cf0 "\cf1 \cf4 Type\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets.ComplexThing`2\cf0 "\cf1 \cf4 ConcreteKey\cf1 =\cf0 "\cf1 Complex\cf0 "\cf1 />\par ??\par ?? <\cf3 Instance\cf1 \cf4 Key\cf1 =\cf0 "\cf1 Cornflower\cf0 "\cf1 \cf4 Type\cf1 =\cf0 "\cf1 Color\cf0 "\cf1 >\par ?? <\cf3 Property\cf1 \cf4 Name\cf1 =\cf0 "\cf1 color\cf0 "\cf1 \cf4 Value\cf1 =\cf0 "\cf1 Cornflower\cf0 "\cf1 />\par ?? </\cf3 Instance\cf1 >\par ??\par ?? <\cf3 Instance\cf1 \cf4 Key\cf1 =\cf0 "\cf1 Complicated\cf0 "\cf1 \cf4 Type\cf1 =\cf0 "\cf1 Complex\cf0 "\cf1 >\par ?? <\cf3 Property\cf1 \cf4 Name\cf1 =\cf0 "\cf1 name\cf0 "\cf1 \cf4 Value\cf1 =\cf0 "\cf1 Jeremy\cf0 "\cf1 />\par ?? <\cf3 Property\cf1 \cf4 Name\cf1 =\cf0 "\cf1 age\cf0 "\cf1 \cf4 Value\cf1 =\cf0 "\cf1 32\cf0 "\cf1 />\par ?? <\cf3 Property\cf1 \cf4 Name\cf1 =\cf0 "\cf1 ready\cf0 "\cf1 \cf4 Value\cf1 =\cf0 "\cf1 true\cf0 "\cf1 />\par ?? </\cf3 Instance\cf1 >\par ?? </\cf3 PluginFamily\cf1 >\par ??\par ?? <\cf3 PluginFamily\cf1 \cf4 Assembly\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets\cf0 "\cf1 \cf4 Type\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets.ISimpleThing`1\cf0 "\cf1 \cf4 DefaultKey\cf1 =\cf0 "\cf1 Simple\cf0 "\cf1 >\par ?? <\cf3 Plugin\cf1 \cf4 Assembly\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets\cf0 "\cf1 \cf4 Type\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets.SimpleThing`1\cf0 "\cf1 \cf4 ConcreteKey\cf1 =\cf0 "\cf1 Simple\cf0 "\cf1 />\par ?? </\cf3 PluginFamily\cf1 >\par ?? </\cf3 StructureMap\cf1 >\par ?? \par ?? \par ?? <\cf3 appSettings\cf1 >\par ?? <\cf3 add\cf1 \cf4 key\cf1 =\cf0 "\cf1 Color\cf0 "\cf1 \cf4 value\cf1 =\cf0 "\cf1 Blue\cf0 "\cf1 />\par ?? <\cf3 add\cf1 \cf4 key\cf1 =\cf0 "\cf1 Day\cf0 "\cf1 \cf4 value\cf1 =\cf0 "\cf1 Monday\cf0 "\cf1 />\par ?? </\cf3 appSettings\cf1 >\par ??\par ??\par ??</\cf3 configuration\cf1 >} +--> +<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: blue;"><?</span><span style="color: #a31515;">xml</span><span + style="color: blue;"> </span><span style="color: red;">version</span><span + style="color: blue;">=</span>"<span style="color: blue;">1.0</span>"<span + style="color: blue;"> </span><span style="color: red;">encoding</span><span + style="color: blue;">=</span>"<span style="color: blue;">utf-8</span>"<span + style="color: blue;"> ?></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"><</span><span style="color: #a31515;">configuration</span><span + style="color: blue;">></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> <</span><span style="color: #a31515;">configSections</span><span + style="color: blue;">></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> <</span><span + style="color: #a31515;">section</span><span style="color: blue;"> </span> + <span style="color: red;">name</span><span style="color: blue;">=</span>"<span + style="color: blue;">StructureMap</span>"<span style="color: blue;"> </span> + <span style="color: red;">type</span><span style="color: blue;">=</span>"<span + style="color: blue;">StructureMap.Configuration.StructureMapConfigurationSection,StructureMap</span>"<span + style="color: blue;">/></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> </</span><span style="color: #a31515;">configSections</span><span + style="color: blue;">></span></p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: blue;"> <</span><span style="color: #a31515;">StructureMap</span><span + style="color: blue;">></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> <!--</span><span + style="color: green;"> Put StructureMap configuration here </span> + <span style="color: blue;">--></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> </</span><span style="color: #a31515;">StructureMap</span><span + style="color: blue;">></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"></</span><span style="color: #a31515;">configuration</span><span + style="color: blue;">></span></p> +</div> +<!--EndFragment--> +<p> + Then you need to explicitly tell ObjectFactory to use this 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;\red0\green0\blue255;\red0\green128\blue0;}??\fs20 \cf3 ObjectFactory\cf0 .Initialize(x =>\par ?? \{\par ?? x.UseDefaultStructureMapConfigFile = \cf4 false\cf0 ;\par ??\par ?? \cf5 // Tell StructureMap to look for configuration \par ??\cf0 \cf5 // from the App.config file\par ??\cf0 \cf5 // The default is false\par ??\cf0 x.PullConfigurationFromAppConfig = \cf4 true\cf0 ;\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: #2b91af;">ObjectFactory</span>.Initialize(x =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: green;">// Tell StructureMap to look for configuration </span> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// from the App.config file</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// The default is false</span></p> + <p style="margin: 0px;"> + + x.PullConfigurationFromAppConfig = <span style="color: blue;">true</span>;</p> + <p style="margin: 0px;"> +& });</p> +</div> +<!--EndFragment--> +<p> + </p> +<h4> + The StructureMap.config File</h4> +<p>In the beginning, StructureMap configuration began and ended with a single file named "StructureMap.config" in the application base folder that contained StructureMap Xml configuration (in short, wherever your App.config file would go). Today, the default behavior is that StructureMap will automatically read in configuration data from the StructureMap.config if it is found when either ObjectFactory.Initialize() is called, or the first time that a service is requested from ObjectFactory. You can technically use only the StructureMap.config file and completely forgo the the usage of any programmatic bootstrapping./p> + +<p>You can override the default behavior for the StructureMap.config file. If you want to make the StructureMap.config file mandatory, you can do this:</p> + <!-- +{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green128\blue0;\red0\green0\blue255;}??\fs20 \cf3 ObjectFactory\cf0 .Initialize(x =>\par ?? \{\par ?? \cf4 // We put the properties for an NHibernate ISession\par ??\cf0 \cf4 // in the StructureMap.config file, so this file\par ??\cf0 \cf4 // must be there for our application to \par ??\cf0 \cf4 // function correctly\par ??\cf0 x.UseDefaultStructureMapConfigFile = \cf5 true\cf0 ;\par ??\par ?? x.AddRegistry(\cf5 new\cf0 \cf3 CoreRegistry\cf0 ());\par ?? x.AddRegistry(\cf5 new\cf0 \cf3 SearchRegistry\cf0 ());\par ?? x.AddRegistry(\cf5 new\cf0 \cf3 WebCoreRegistry\cf0 ());\par ?? x.AddRegistry(\cf5 new\cf0 \cf3 WebRegistry\cf0 ());\par ?? x.AddRegistry(\cf5 new\cf0 \cf3 RuleRegistry\cf0 ());\par ?? \});} +--> <div style="border: thin solid black; background: white none repeat scroll 0% 0%; font-size: 10pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: black; font-family: courier new;"> +<p style="margin: 0px;"><span style="overflow: scroll;"> </span><span style="overflow: scroll; color: rgb(43, 145, 175);">ObjectFactory</span><span style="overflow: scroll;">.Initialize(x =></span></p> + +<p style="margin: 0px;"><span style="overflow: scroll;"> {</span></p> + +<p style="margin: 0px;"><span style="overflow: scroll;"> </span><span style="overflow: scroll; color: green;">// We put the properties for an NHibernate ISession</span></p> + +<p style="margin: 0px;"><span style="overflow: scroll;"> </span><span style="overflow: scroll; color: green;">// in the StructureMap.config file, so this file</span></p> + +<p style="margin: 0px;"><span style="overflow: scroll;"> </span><span style="overflow: scroll; color: green;">// must be there for our application to </span></p> + +<p style="margin: 0px;"><span style="overflow: scroll;"> </span><span style="overflow: scroll; color: green;">// function correctly</span></p> + +<p style="margin: 0px;"><span style="overflow: scroll;"> x.UseDefaultStructureMapConfigFile = </span><span style="overflow: scroll; color: blue;">true</span><span style="overflow: scroll;">;</span></p> + +<p style="margin: 0px;"><span style="overflow: scroll;"> });</span></p> + </div> <!--EndFragment--> +<p>At other times you might want to force ObjectFactory to ignore the StructureMap.config file even if it does exist.</p> + <!-- +{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;\red163\green21\blue21;}??\fs20 \cf3 ObjectFactory\cf0 .Initialize(x =>\par ?? \{\par ?? x.IgnoreStructureMapConfig = \cf4 true\cf0 ;\par ?? \par ?? x.ForRequestedType<\cf3 IWidget\cf0 >().TheDefault.Is\par ?? .OfConcreteType<\cf3 DoctorTester\cf0 .\cf3 NumberWidget\cf0 >()\par ?? .WithCtorArg(\cf5 "age"\cf0 ).EqualToAppSetting(\cf5 "age"\cf0 );\par ?? \});} +--> <div style="border: thin solid black; background: white none repeat scroll 0% 0%; font-size: 10pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: black; font-family: courier new;"> +<p style="margin: 0px;"><span style="overflow: scroll;"> </span><span style="overflow: scroll; color: rgb(43, 145, 175);">ObjectFactory</span><span style="overflow: scroll;">.Initialize(x =></span></p> + +<p style="margin: 0px;"><span style="overflow: scroll;"> {</span></p> + +<p style="margin: 0px;"><span style="overflow: scroll;"> x.IgnoreStructureMapConfig = </span><span style="overflow: scroll; color: blue;">true</span><span style="overflow: scroll;">;</span></p> + +<p style="margin: 0px;"><span style="overflow: scroll;">& });</span></p> + </div> <!--EndFragment--><p> + </p> +<p> </p> <p> </p> @@ -147,7 +491,7 @@ {</p> <p style="margin: 0px;"> - <span style="color: #2b91af;">ObjectFactory</span>.Initialize(x =></p> + <span style="color: #2b91af;">ObjectFactory</span>.Initialize(x =>/p> <p style="margin: 0px;"> {</p> <p style="margin: 0px;"> @@ -195,74 +539,14 @@ <p style="margin: 0px"> </p> <p style="margin: 0px"> - </p> + & </p> <p style="margin: 0px"> </p> <h4 style="margin: 0px"> - Adding Configuration to a Container after Initialization</h4> + Using Container independent of ObjectFactory/h4> <p style="margin: 0px"> </p> <p style="margin: 0px"> - Sometimes you may want to add additional types and Instances to an existing - container. The Configure() method on both ObjectFactory and IContainer is - used for this purpose. - </p> - <p style="margin: 0px"> - </p> - <p style="margin: 0px"> - Here's a scenario. You're building a composite desktop application, and - for performance reasons you want to delay loading the screens and features for a - module of the application until the user explicitly activates that module. - When the user decides to start using that module, your code needs to immediately - add more types and Instances to the already running ObjectFactory. The - following code would search an assembly named - "MyCompany.MyApp.ExtensionAssembly" for Registry classes. The - configuration embedded in these new Registry classes would be added to the - Container internal to ObjectFactory.</p> - <p style="margin: 0px"> - </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 // Adding configuration from an extension Assembly\par ??\cf0 \cf3 // after ObjectFactory is already configured\par ??\cf0 \cf4 ObjectFactory\cf0 .Configure(x =>\par ?? \{\par ?? x.Scan(scan =>\par ?? \{\par ?? scan.Assembly(\cf5 "MyCompany.MyApp.ExtensionAssembly"\cf0 );\par ?? scan.LookForRegistries();\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: green;">// Adding configuration from an extension Assembly</span></p> - <p style="margin: 0px;"> - - <span style="color: green;">// after ObjectFactory is already configured</span></p> - <p style="margin: 0px;"> - - <span style="color: #2b91af;">ObjectFactory</span>.Configure(x =></p> - <p style="margin: 0px;"> - {</p> - <p style="margin: 0px;"> - - x.Scan(scan =></p> - <p style="margin: 0px;"> - {</p> - <p style="margin: 0px;"> - - scan.Assembly(<span style="color: #a31515;">"MyCompany.MyApp.ExtensionAssembly"</span>);</p> - <p style="margin: 0px;"> - - scan.LookForRegistries();</p> - <p style="margin: 0px;"> - - });</p> - <p style="margin: 0px;"> - });</p> - </div> -<!--EndFragment--> -<p style="margin: 0px"> - </p> - <p style="margin: 0px"> - </p> - <h4 style="margin: 0px"> - Using Container independent of ObjectFactory</h4> - <p style="margin: 0px"> - </p> - <p style="margin: 0px"> New to 2.5 is the ability to create an instance of the underlying Container class independent of the static ObjectFactory class (actually, you always could do this, but it's much easier in 2.5). The IContainer interface has @@ -454,101 +738,13 @@ <p style="margin: 0px"> </p> <p style="margin: 0px"> - </p> -<p> - </p> -<!-- -{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 WebCoreRegistry\cf0 : \cf4 Registry\par ??\cf0 \{\par ?? \cf3 public\cf0 WebCoreRegistry()\par ?? \{\par ?? \cf5 // This is used as a sort of lightweight ScriptManager in\par ??\cf0 \cf5 // our website application\par ??\cf0 ForRequestedType<\cf4 ICachedSet\cf0 >().TheDefaultIsConcreteType<\cf4 CachedSet\cf0 >()\par ?? .CacheBy(\cf4 InstanceScope\cf0 .Hybrid);\par ??\par ?? ForRequestedType<\cf4 IControlBuilder\cf0 >().TheDefault.Is.OfConcreteType<\cf4 AspNetControlBuilder\cf0 >();\par ?? ForRequestedType<\cf4 IPartialRenderer\cf0 >().TheDefault.Is.OfConcreteType<\cf4 PartialRenderer\cf0 >();\par ??\par ?? Scan(x =>\par ?? \{\par ?? \cf5 // Scan "this" assembly. In other words, the assembly that \par ??\cf0 \cf5 // contains the WebCoreRegistry class\par ??\cf0 x.TheCallingAssembly();\par ??\par ?? x.IncludeNamespaceContainingType<\cf4 AuthenticationContext\cf0 >();\par ?? x.IncludeNamespaceContainingType<\cf4 ISecurityDataService\cf0 >();\par ??\par ?? x.WithDefaultConventions();\par ?? \});\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;"> - class</span> <span style="color: #2b91af;">WebCoreRegistry</span> : - <span style="color: #2b91af;">Registry</span></p> - <p style="margin: 0px;"> - {</p> - <p style="margin: 0px;"> - <span style="color: blue;">public</span> - WebCoreRegistry()</p> - <p style="margin: 0px;"> - {</p> - <p style="margin: 0px;"> - - <span style="color: green;">// This is used as a sort of lightweight - ScriptManager in</span></p> - <p style="margin: 0px;"> - - <span style="color: green;">// our website application</span></p> - <p style="margin: 0px;"> - ForRequestedType<<span - style="color: #2b91af;">ICachedSet</span>>().TheDefaultIsConcreteType<<span - style="color: #2b91af;">CachedSet</span>>()</p> - <p style="margin: 0px;"> - - .CacheBy(<span style="color: #2b91af;">InstanceScope</span>.Hybrid);</p> - <p style="margin: 0px;"> - </p> - <p style="margin: 0px;"> - ForRequestedType<<span - style="color: #2b91af;">IControlBuilder</span>>().TheDefault.Is.OfConcreteType<<span - style="color: #2b91af;">AspNetControlBuilder</span>>();</p> - <p style="margin: 0px;"> - ForRequestedType<<span - style="color: #2b91af;">IPartialRenderer</span>>().TheDefault.Is.OfConcreteType<<span - style="color: #2b91af;">PartialRenderer</span>>();</p> - <p style="margin: 0px;"> - </p> - <p style="margin: 0px;"> - Scan(x =></p> - <p style="margin: 0px;"> - {</p> - <p style="margin: 0px;"> - - <span style="color: green;">// Scan "this" assembly. In other words, the - assembly that </span> - </p> - <p style="margin: 0px;"> - - <span style="color: green;">// contains the WebCoreRegistry class</span></p> - <p style="margin: 0px;"> - - x.TheCallingAssembly();</p> - <p style="margin: 0px;"> - </p> - <p style="margin: 0px;"> - - x.IncludeNamespaceContainingType<<span style="color: #2b91af;">AuthenticationContext</span>>();</p> - <p style="margin: 0px;"> - - x.IncludeNamespaceContainingType<<span style="color: #2b91af;">ISecurityDataService</span>>();</p> - <p style="margin: 0px;"> - </p> - <p style="margin: 0px;"> - - x.WithDefaultConventions();</p> - <p style="margin: 0px;"> - });</p> - <p style="margin: 0px;"> - }</p> - <p style="margin: 0px;"> - }</p> -</div> -<!--EndFragment--> -<p> - </p> -<h4> - </h4> + & </p> <p style="margin: 0px"> </p> -<p style="margin: 0px"> - </p> -<p style="margin: 0px"> - </p> <h4 style="margin: 0px"> </h4> <h4 style="margin: 0px"> - StructureMapConfiguration/h4> - <p style="margin: 0px"> + StructureMapConfigurationp style="margin: 0px"> </p> <p style="margin: 0px"> </p> Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-10-23 23:02:07 UTC (rev 192) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-10-27 01:07:28 UTC (rev 193) @@ -8,7 +8,8 @@ namespace StructureMap.Configuration.DSL.Expressions { /// <summary> - /// Represents the parameters for creating instances of a given Type + /// Expression Builder that has grammars for defining policies at the + /// PluginType level /// </summary> public class CreatePluginFamilyExpression<PLUGINTYPE> { @@ -29,11 +30,19 @@ }); } + /// <summary> + /// Define the Default Instance for this PluginType + /// </summary> public IsExpression<PLUGINTYPE> TheDefault { get { return new InstanceExpression<PLUGINTYPE>(i => registerDefault(i)); } } + /// <summary> + /// Add multiple Instance's to this PluginType + /// </summary> + /// <param name="action"></param> + /// <returns></returns> public CreatePluginFamilyExpression<PLUGINTYPE> AddInstances(Action<IInstanceExpression<PLUGINTYPE>> action) { var list = new List<Instance>(); @@ -108,7 +117,12 @@ return this; } - + /// <summary> + /// Register an Action to run against any object of this PluginType immediately after + /// it is created, but before the new object is passed back to the caller + /// </summary> + /// <param name="handler"></param> + /// <returns></returns> public CreatePluginFamilyExpression<PLUGINTYPE> OnCreation(Action<PLUGINTYPE> handler) { _children.Add( @@ -127,6 +141,14 @@ return this; } + /// <summary> + /// Register a Func to run against any object of this PluginType immediately after it is created, + /// but before the new object is passed back to the caller. Unlike <see cref="OnCreation">OnCreation()</see>, + /// EnrichWith() gives the the ability to return a different object. Use this method for runtime AOP + /// scenarios or to return a decorator. + /// </summary> + /// <param name="handler"></param> + /// <returns></returns> public CreatePluginFamilyExpression<PLUGINTYPE> EnrichWith(EnrichmentHandler<PLUGINTYPE> handler) { _children.Add( @@ -141,9 +163,20 @@ return this; } - + /// <summary> + /// Shortcut method to add an additional Instance to this Plugin Type + /// as just a Concrete Type. This will only work if the Concrete Type + /// has no primitive constructor or mandatory Setter arguments. + /// </summary> + /// <typeparam name="PLUGGEDTYPE"></typeparam> + /// <returns></returns> public CreatePluginFamilyExpression<PLUGINTYPE> AddConcreteType<PLUGGEDTYPE>() { + if (!PluginCache.GetPlugin(typeof(PLUGGEDTYPE)).CanBeAutoFilled) + { + throw new StructureMapException(231); + } + _alterations.Add(family => { string name = PluginCache.GetPlugin(typeof (PLUGGEDTYPE)).ConcreteKey; @@ -154,12 +187,24 @@ return this; } + /// <summary> + /// Registers an IBuildInterceptor for this Plugin Type that executes before + /// any object of this PluginType is created. IBuildInterceptor's can be + /// used to create a custom scope + /// </summary> + /// <param name="interceptor"></param> + /// <returns></returns> public CreatePlu... [truncated message content] |