You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
|
Feb
(5) |
Mar
(9) |
Apr
(9) |
May
(4) |
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(3) |
2008 |
Jan
(11) |
Feb
(6) |
Mar
|
Apr
(16) |
May
(28) |
Jun
(13) |
Jul
(3) |
Aug
(19) |
Sep
(11) |
Oct
(37) |
Nov
(1) |
Dec
(17) |
2009 |
Jan
(16) |
Feb
(6) |
Mar
|
Apr
(6) |
May
(1) |
Jun
(10) |
Jul
(4) |
Aug
(4) |
Sep
(4) |
Oct
(8) |
Nov
(3) |
Dec
(45) |
2010 |
Jan
(8) |
Feb
(21) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
From: <jer...@us...> - 2008-07-10 20:49:48
|
Revision: 126 http://structuremap.svn.sourceforge.net/structuremap/?rev=126&view=rev Author: jeremydmiller Date: 2008-07-10 13:49:46 -0700 (Thu, 10 Jul 2008) Log Message: ----------- fixing some crap with profile manager, improvements to diagnostics, little fixes Modified Paths: -------------- trunk/Source/HTML/HTML.csproj trunk/Source/HTML/InjectingServicesAtRuntime.htm trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap/Diagnostics/TextReportWriter.cs trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs trunk/Source/StructureMap/ExplicitArgsExpression.cs trunk/Source/StructureMap/Graph/AssemblyScanner.cs trunk/Source/StructureMap/Graph/Constructor.cs trunk/Source/StructureMap/Graph/ITypeScanner.cs trunk/Source/StructureMap/Graph/Plugin.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/Graph/PluginGraph.cs trunk/Source/StructureMap/IContainer.cs trunk/Source/StructureMap/IInstanceFactory.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/Pipeline/BuildPolicy.cs trunk/Source/StructureMap/Pipeline/CacheInterceptor.cs trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs trunk/Source/StructureMap/Pipeline/Instance.cs trunk/Source/StructureMap/Pipeline/LiteralInstance.cs trunk/Source/StructureMap/Pipeline/Profile.cs trunk/Source/StructureMap/Pipeline/ProfileManager.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap/Properties/AssemblyInfo.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap.DataAccess/IDatabaseEngine.cs trunk/Source/StructureMap.DataAccess/StructureMap.DataAccess.csproj trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs trunk/Source/StructureMap.Testing/DataAccess/CommandCollectionTester.cs trunk/Source/StructureMap.Testing/DataAccess/CommandFactoryTester.cs trunk/Source/StructureMap.Testing/DataAccess/DataSessionTester.cs trunk/Source/StructureMap.Testing/DataAccess/ExecutionStates/AutoCommitExecutionStateTester.cs trunk/Source/StructureMap.Testing/DataAccess/ExecutionStates/TransactionalExecutionStateTester.cs trunk/Source/StructureMap.Testing/DataAccess/Parameterization/ParameterTemplateTester.cs trunk/Source/StructureMap.Testing/DataAccess/ReaderSourceCollectionTester.cs trunk/Source/StructureMap.Testing/Examples.cs trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerMergeTester.cs trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerTester.cs trunk/Source/StructureMap.Testing/PipelineGraphTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing/TestData/AttributeNormalized.xml trunk/Source/StructureMap.Testing/TestData/DefaultInstance.xml trunk/Source/StructureMap.Testing.Widget/StructureMap.Testing.Widget.csproj trunk/Source/StructureMap.Testing.Widget2/StructureMap.Testing.Widget2.csproj trunk/Source/StructureMap.Testing.Widget3/StructureMap.Testing.Widget3.csproj trunk/Source/StructureMap.Testing.Widget4/StructureMap.Testing.Widget4.csproj trunk/Source/StructureMap.Testing.Widget5/StructureMap.Testing.Widget5.csproj trunk/Source/StructureMap.sln Added Paths: ----------- trunk/Source/StructureMap.DataAccess/structuremap.snk trunk/Source/StructureMap.Testing/Properties/ trunk/Source/StructureMap.Testing/Properties/Settings.Designer.cs trunk/Source/StructureMap.Testing/Properties/Settings.settings trunk/Source/StructureMap.Testing.Widget/structuremap.snk trunk/Source/StructureMap.Testing.Widget2/structuremap.snk trunk/Source/StructureMap.Testing.Widget3/structuremap.snk trunk/Source/StructureMap.Testing.Widget4/structuremap.snk trunk/Source/StructureMap.Testing.Widget5/structuremap.snk Removed Paths: ------------- trunk/Source/HTML/Concepts.htm Deleted: trunk/Source/HTML/Concepts.htm =================================================================== --- trunk/Source/HTML/Concepts.htm 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/HTML/Concepts.htm 2008-07-10 20:49:46 UTC (rev 126) @@ -1,49 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> - <head> - <title></title> - </head> - <body> - <h3>Patterns and Concepts</h3> - <p> - Object oriented systems are composed of a myriad array of objects communicating - by sending messages to exposed interfaces. To a large degree, the qualities of - an OO design are determined by the structure, organization, and responsibility - assignments of the objects in a system. The qualities of a system most - affected by structure are flexibility, extensibility, maintainability, and - testability. Applications usually meet their demise when the system is - determined to be too difficult or costly to change. The symptoms of a dying - application are a loss of clearly defined structure, an unclear division - of responsibilities in the code, and difficulty testing and troubleshooting the - application. </p> - <p> - Over the years a series of rules and principles have been discovered and - developed to describe well-structured systems. Possibly most important is - <em>Separation of Concerns</em> – pulling separate aspects of the system like - persistence, security, or business logic into separate classes and packages. - Another key concept is the combination of highly cohesive classes in a loosely - coupled structure. The more highly coupled two components of a system are, the - more difficult the system is to maintain, test, and reuse. A class should have a - cohesive set of responsibilities in a narrow domain. In other words, - simpleton classes that do only one thing are much easier to code and test than - <em>God</em> classes that take on far too many unrelated responsibilities. </p> - <p> </p> - <h4>Separation of Concerns</h4> - <h4>Services and Dependencies</h4> - <h4>Dependency Injection</h4> - <h4>Container</h4> - <h4>Service Locator</h4> - <h3>StructureMap Terms</h3> - <h4>PluginType</h4> - <p>Object Oriented Design</p> - <h4>Auto Wiring</h4> - <p>Every "real" IoC container supports the concept of "Auto Wiring." Auto - Wiring simply means that StructureMap can figure out dependency chains for you.</p> - <h4>Instance</h4> - <h4>Scoping</h4> - <h4>PluginFamily</h4> - <h4>Profile</h4> - <h4>Interceptor</h4> - <h4>PostProcessor</h4> - </body> -</html> \ No newline at end of file Modified: trunk/Source/HTML/HTML.csproj =================================================================== --- trunk/Source/HTML/HTML.csproj 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/HTML/HTML.csproj 2008-07-10 20:49:46 UTC (rev 126) @@ -62,7 +62,7 @@ <Content Include="BestPractices.htm" /> <Content Include="ChangingDefaultsAtRuntime.htm" /> <Content Include="CompositeConfiguration.htm" /> - <Content Include="Concepts.htm" /> + <Content Include="Glossary.htm" /> <Content Include="ConcreteTypes.htm" /> <Content Include="ConfigurationArchitecture.htm" /> <Content Include="ConfiguringStructureMap.htm" /> Modified: trunk/Source/HTML/InjectingServicesAtRuntime.htm =================================================================== --- trunk/Source/HTML/InjectingServicesAtRuntime.htm 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/HTML/InjectingServicesAtRuntime.htm 2008-07-10 20:49:46 UTC (rev 126) @@ -4,8 +4,10 @@ <title>Injecting Services or Mocks at Runtime</title> </head> <body> - <h1>Injecting Services, Mocks, and Stubs at Runtime</h1> + <h1>Injecting Modules, Services, Mocks, and Stubs at Runtime</h1> <p>In the beginning (2003), there was attributes and 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 @@ -21,37 +23,161 @@ normal configuration).</p> <h4>Injecting a Service at Runtime</h4> - <p>In my desktop applications the main form implements some sort of + <p>In my desktop applications the main form usually implements some sort of IApplicationShell interface. I've found it valuable to place the main form itself into StructureMap, as well as several child controls of the main form as well so that various Controllers, Presenters, and Commands can interact with - parts of the main shell. I probably could build the ApplicationShell + parts of the main shell without tight coupling. I probably could build the ApplicationShell itself inside of StructureMap, but the child controls like (I'm making this up) IQueryToolBar or IExplorerPane are easiest to create as part of the - ApplicationShell and loaded later.</p> + ApplicationShell and loaded into StructureMap later.</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 ApplicationShell\cf0 : \cf4 Form\cf0 , \cf4 IApplicationShell\par ??\cf0 \{\par ?? \par ?? \}} --> <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"> <p style="margin: 0px;"> + </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 ApplicationShell\cf0 : \cf4 Form\cf0 , \cf4 IApplicationShell\par ??\cf0 \{\par ?? \cf3 public\cf0 \cf4 IQueryToolBar\cf0 QueryToolBar\par ?? \{\par ?? \cf3 get\par ??\cf0 \{\par ?? \cf3 return\cf0 \cf3 null\cf0 ;\par ?? \}\par ?? \}\par ??\par ?? \cf3 public\cf0 \cf4 IExplorerPane\cf0 ExplorerPane\par ?? \{\par ?? \cf3 get\par ??\cf0 \{\par ?? \cf3 return\cf0 \cf3 null\cf0 ;\par ?? \}\par ?? \}\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"> + <p style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> - <span style="color: #2b91af;">ApplicationShell</span> : - <span style="color: #2b91af;">Form</span>, <span style="color: #2b91af;"> - IApplicationShell</span></p> - <p style="margin: 0px;"> + <span style="color: #2b91af;">ApplicationShell</span> : + <span style="color: #2b91af;">Form</span>, <span style="color: #2b91af;"> + IApplicationShell</span></p> + <p style="margin: 0px;"> {</p> - <p style="margin: 0px;"> - </p> - <p style="margin: 0px;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: #2b91af;">IQueryToolBar</span> QueryToolBar...</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: #2b91af;">IExplorerPane</span> ExplorerPane...</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> }</p> - </div> + </div> <!--EndFragment--> -<p> </p> +</div> +<!--EndFragment--> +<p>Easy enough. The main shell has some controls on it. Now, we may want + a centralized class to govern the behavior of just the query tool bar along the + top of the main form. That class obviously needs to find the IQueryToolBar + on the main form, but I need a clean way of connecting the IQueryToolBar to this + new QueryController class.</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 QueryController\par ??\cf0 \{\par ?? \cf3 private\cf0 \cf4 IQueryToolBar\cf0 _toolBar;\par ??\par ?? \cf3 public\cf0 QueryController(\cf4 IQueryToolBar\cf0 toolBar)\par ?? \{\par ?? _toolBar = toolBar;\par ?? \}\par ?? \}} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;"> + class</span> <span style="color: #2b91af;">QueryController</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;">private</span> + <span style="color: #2b91af;">IQueryToolBar</span> _toolBar;</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + QueryController(<span style="color: #2b91af;">IQueryToolBar</span> toolBar)</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + _toolBar = toolBar;</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + }</p> +</div> +<!--EndFragment--> +<p>StructureMap is going to build up the QueryController, but it doesn't help to + inject in a new IQueryToolBar that isn't visible anywhere in the application. + We need to get to exactly the right instance of that control. So let's use + the new Inject<T>(T instance) method on ObjectFactory to register the child + controls from the main form.</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof65001\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 // Familiar stuff for the average WinForms or WPF developer\par ??\cf0 \cf3 // Create the main form\par ??\cf0 \cf4 ApplicationShell\cf0 shell = \cf5 new\cf0 \cf4 ApplicationShell\cf0 ();\par ??\par ?? \cf3 // Put the main form, and some of its children into StructureMap\par ??\cf0 \cf3 // where other Controllers and Commands can get to them\par ??\cf0 \cf3 // without being coupled to the main form\par ??\cf0 \cf4 ObjectFactory\cf0 .Inject<\cf4 IApplicationShell\cf0 >(shell);\par ?? \cf4 ObjectFactory\cf0 .Inject<\cf4 IQueryToolBar\cf0 >(shell.QueryToolBar);\par ?? \cf4 ObjectFactory\cf0 .Inject<\cf4 IExplorerPane\cf0 >(shell.ExplorerPane);\par ??\par ??\par ?? \cf4 Application\cf0 .Run(shell);} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"> + <p style="margin: 0px;"> + + <span style="color: green;">// Familiar stuff for the average WinForms or WPF + developer</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// Create the main form</span></p> + <p style="margin: 0px;"> + + <span style="color: #2b91af;">ApplicationShell</span> shell = + <span style="color: blue;">new</span> <span style="color: #2b91af;"> + ApplicationShell</span>();</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// Put the main form, and some of its children into + StructureMap</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// where other Controllers and Commands can get to + them</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// without being coupled to the main form</span></p> + <p style="margin: 0px;"> + + <span style="color: #2b91af;">ObjectFactory</span>.Inject<<span + style="color: #2b91af;">IApplicationShell</span>>(shell);</p> + <p style="margin: 0px;"> + + <span style="color: #2b91af;">ObjectFactory</span>.Inject<<span + style="color: #2b91af;">IQueryToolBar</span>>(shell.QueryToolBar);</p> + <p style="margin: 0px;"> + + <span style="color: #2b91af;">ObjectFactory</span>.Inject<<span + style="color: #2b91af;">IExplorerPane</span>>(shell.ExplorerPane);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + <span style="color: #2b91af;">Application</span>.Run(shell);</p> +</div> +<!--EndFragment--> +<p>I've used this exact strategy on three applications now to great s.Run(shell);</p> +</div> +<!--EndFragment--> +<p>Now, a call to ObjectFactory.GetInstance<QueryController>() will poke the + IQueryToolBar instance we registered above into the constructor of the new + QueryController object. Remember, one of the primary usages of + StructureMap is simply to get the right service dependencies and metadata to the + right concrete classes so you can concentrate on doing QueryController stuff in + the QueryController class instead of bootstrapping all the stuff it needs.</p> +<p>I've used this exact strategy on three applications now to great success. + The previous design had a lot of "thisThing.ThatThing.QueryToolBar" properties + just to get access to the child controls on the main form. It was + devolving into spaghetti code before I adopted the strategy above.</p> +<p>The ObjectFactory.Inject<T>(T instance) method is identical to the older + ObjectFactory.InjectStub<T>(T stub) method. I've marked the older method + as deprecated because I think the name is misleading. </p> +<p>Use this strategy for any type of service or component that you need to inject + into other services, but isn't convenient or possible to build through + StructureMap itself.</p> <h4>Injecting a Mock or a Stub at Runtime</h4> + <p>On its maiden cruise in 2004, my team quickly realized that we needed a way to +On its maiden cruise in 2004, my team quickly realized that we needed a way to + make StructureMap deliver up mock objects in unit tests. It obviously + isn't efficient to muck with an Xml file for each and every unit test that + requires this function, so we wanted a way to temporarily load ObjectFactory up + with a mock object in place of its normal behavior for a given type.</p> <h4></h4> <h4></h4> <h4></h4> <h4></h4> - <h4></h4> </body> </html> \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -31,12 +31,16 @@ internal void ConfigurePluginGraph(PluginGraph graph) { + if (graph.Registries.Contains(this)) return; + graph.Log.StartSource("Registry: " + TypePath.GetAssemblyQualifiedName(GetType())); foreach (Action<PluginGraph> action in _actions) { action(graph); } + + graph.Registries.Add(this); } @@ -193,5 +197,28 @@ { _actions.Add(graph => graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(instance)); } + + public bool Equals(Registry obj) + { + if (ReferenceEquals(null, obj)) return false; + return GetType().Equals(obj.GetType()); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + + if (obj is Registry) return false; + + + if (obj.GetType() != typeof (Registry)) return false; + return Equals((Registry) obj); + } + + public override int GetHashCode() + { + return 0; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/Container.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -82,10 +82,19 @@ { Instance defaultInstance = _pipelineGraph.GetDefault(typeof (PLUGINTYPE)); - ExplicitInstance<PLUGINTYPE> instance = new ExplicitInstance<PLUGINTYPE>(args, defaultInstance); + ExplicitInstance instance = new ExplicitInstance(typeof(PLUGINTYPE), args, defaultInstance); return GetInstance<PLUGINTYPE>(instance); } + public object GetInstance(Type type, ExplicitArguments args) + { + Instance defaultInstance = _pipelineGraph.GetDefault(type); + + Instance instance = new ExplicitInstance(type, args, defaultInstance); + + return GetInstance(type, instance); + } + public void Inject<PLUGINTYPE>(PLUGINTYPE instance) { _pipelineGraph.Inject(instance); @@ -288,6 +297,8 @@ } } + + #endregion private IBuildSession withNewSession() Modified: trunk/Source/StructureMap/Diagnostics/TextReportWriter.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/TextReportWriter.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/Diagnostics/TextReportWriter.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -26,6 +26,11 @@ _lines.Add(new TextLine(contents)); } + public void AddContent(string contents) + { + _lines.Add(new PlainLine(contents)); + } + public void Write(StringWriter writer) { CharacterWidth[] widths = CharacterWidth.For(_columnCount); @@ -67,5 +72,27 @@ { Debug.WriteLine(Write()); } + + } + + internal class PlainLine : Line + { + public string Contents { get; set; } + + public PlainLine(string contents) + { + Contents = contents; + } + + public void OverwriteCounts(CharacterWidth[] widths) + { + // no-op + } + + public void Write(TextWriter writer, CharacterWidth[] widths) + { + writer.WriteLine(Contents); + } + } } Modified: trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -86,7 +86,7 @@ - void IPipelineGraphVisitor.PluginType(Type pluginType, Instance defaultInstance) + void IPipelineGraphVisitor.PluginType(Type pluginType, Instance defaultInstance, IBuildPolicy policy) { // don't care } Modified: trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -61,7 +61,7 @@ writer.WriteLine(); } - void IPipelineGraphVisitor.PluginType(Type pluginType, Instance defaultInstance) + void IPipelineGraphVisitor.PluginType(Type pluginType, Instance defaultInstance, IBuildPolicy policy) { _writer.AddDivider('-'); string[] contents = new string[]{TypePath.GetAssemblyQualifiedName(pluginType), string.Empty, string.Empty}; @@ -73,6 +73,8 @@ } _writer.AddText(contents); + + _writer.AddContent("Built by: " + policy.ToString()); } private void setContents(string[] contents, Instance instance) Modified: trunk/Source/StructureMap/ExplicitArgsExpression.cs =================================================================== --- trunk/Source/StructureMap/ExplicitArgsExpression.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/ExplicitArgsExpression.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -1,3 +1,4 @@ +using System; using StructureMap.Pipeline; namespace StructureMap @@ -60,5 +61,15 @@ { return _manager.GetInstance<T>(_args); } + + /// <summary> + /// Create an instance using the explicit arguments + /// </summary> + /// <param name="type"></param> + /// <returns></returns> + public object GetInstance(Type type) + { + return _manager.GetInstance(type, _args); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/AssemblyScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -29,6 +29,14 @@ { if (!Registry.IsPublicRegistry(type)) return; + foreach (var previous in pluginGraph.Registries) + { + if (previous.GetType().Equals(type)) + { + return; + } + } + Registry registry = (Registry) Activator.CreateInstance(type); registry.ConfigurePluginGraph(pluginGraph); }); Modified: trunk/Source/StructureMap/Graph/Constructor.cs =================================================================== --- trunk/Source/StructureMap/Graph/Constructor.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/Graph/Constructor.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -43,6 +43,11 @@ return returnValue; } + public static bool HasConstructors(Type pluggedType) + { + return GetGreediestConstructor(pluggedType) != null; + } + public static ConstructorInfo GetGreediestConstructor(Type pluggedType) { ConstructorInfo returnValue = null; @@ -112,5 +117,10 @@ { return _ctor.GetParameters().Length > 0; } + + public bool IsValid() + { + return _ctor != null; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/ITypeScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/ITypeScanner.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/Graph/ITypeScanner.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Text; using StructureMap.Configuration.DSL; +using StructureMap.Pipeline; namespace StructureMap.Graph { @@ -19,7 +20,7 @@ Type pluginType = FindPluginType(type); if (pluginType != null) { - registry.ForRequestedType(pluginType).TheDefaultIsConcreteType(type); + registry.ForRequestedType(pluginType).AddInstance(new ConfiguredInstance(type)); } } Modified: trunk/Source/StructureMap/Graph/Plugin.cs =================================================================== --- trunk/Source/StructureMap/Graph/Plugin.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/Graph/Plugin.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -123,5 +123,17 @@ { _setters.Visit(arguments); } + + public bool IsValid() + { + return _constructor.IsValid(); + } + + public static Plugin CreateForConcreteType(Type type) + { + if (!Constructor.HasConstructors(type)) return null; + + return new Plugin(type, DEFAULT); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -44,8 +44,11 @@ if (IsConcrete(pluginType)) { - Plugin plugin = new Plugin(pluginType, Plugin.DEFAULT); - Plugins.Add(plugin); + Plugin plugin = Plugin.CreateForConcreteType(pluginType); + if (plugin != null) + { + Plugins.Add(plugin); + } } } Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.Reflection; +using StructureMap.Configuration.DSL; using StructureMap.Diagnostics; using StructureMap.Interceptors; using StructureMap.Pipeline; @@ -21,6 +23,8 @@ private readonly ProfileManager _profileManager = new ProfileManager(); private readonly bool _useExternalRegistries = true; private bool _sealed = false; + private List<Registry> _registries = new List<Registry>(); + /// <summary> /// Default constructor @@ -37,6 +41,11 @@ _useExternalRegistries = useExternalRegistries; } + public List<Registry> Registries + { + get { return _registries; } + } + public AssemblyScanner Assemblies { get { return _assemblies; } Modified: trunk/Source/StructureMap/IContainer.cs =================================================================== --- trunk/Source/StructureMap/IContainer.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/IContainer.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -66,5 +66,6 @@ ExplicitArgsExpression With<T>(T arg); IExplicitProperty With(string argName); void AssertConfigurationIsValid(); + object GetInstance(Type type, ExplicitArguments args); } } \ No newline at end of file Modified: trunk/Source/StructureMap/IInstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/IInstanceFactory.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/IInstanceFactory.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -23,5 +23,6 @@ InstanceBuilder FindBuilderByConcreteKey(string concreteKey); void ForEachInstance(Action<Instance> action); void ImportFrom(PluginFamily family); + void AcceptVisitor(IPipelineGraphVisitor visitor, Instance defaultInstance); } } \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -144,5 +144,11 @@ _instanceBuilders.Add(family.Plugins); family.EachInstance(instance => _instances.Fill(instance.Name, instance)); } + + public void AcceptVisitor(IPipelineGraphVisitor visitor, Instance defaultInstance) + { + visitor.PluginType(PluginType, defaultInstance, _policy); + ForEachInstance(i => visitor.Instance(PluginType, i)); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -53,7 +53,7 @@ /// <returns></returns> public static object FillDependencies(Type type) { - return manager.FillDependencies(type); + return container.FillDependencies(type); } /// <summary> @@ -64,7 +64,7 @@ /// <returns></returns> public static T FillDependencies<T>() { - return (T) manager.FillDependencies(typeof (T)); + return (T) container.FillDependencies(typeof (T)); } [Obsolete("Please use Inject(Type, object) instead.")] @@ -75,7 +75,7 @@ public static void Inject(Type pluginType, object instance) { - manager.Inject(pluginType, instance); + container.Inject(pluginType, instance); } [Obsolete("Please use Inject() instead.")] @@ -86,12 +86,12 @@ public static void Inject<PLUGINTYPE>(PLUGINTYPE instance) { - manager.Inject<PLUGINTYPE>(instance); + container.Inject<PLUGINTYPE>(instance); } public static void Inject<PLUGINTYPE>(string name, PLUGINTYPE instance) { - manager.Inject<PLUGINTYPE>(name, instance); + container.Inject<PLUGINTYPE>(name, instance); } [Obsolete("Please use Inject<PLUGINTYPE>(name) instead.")] @@ -107,18 +107,18 @@ public static string WhatDoIHave() { - return manager.WhatDoIHave(); + return container.WhatDoIHave(); } public static void AssertConfigurationIsValid() { - manager.AssertConfigurationIsValid(); + container.AssertConfigurationIsValid(); } #region Container and setting defaults - private static IContainer manager + private static IContainer container { get { @@ -136,6 +136,7 @@ return _manager; } } + public static string Profile @@ -145,7 +146,7 @@ lock (_lockObject) { _profile = value; - manager.SetDefaultsToProfile(_profile); + container.SetDefaultsToProfile(_profile); } } get { return _profile; } @@ -161,22 +162,22 @@ public static void Configure(Action<Registry> configure) { - manager.Configure(configure); + container.Configure(configure); } public static void SetDefault(Type pluginType, Instance instance) { - manager.SetDefault(pluginType, instance); + container.SetDefault(pluginType, instance); } public static void SetDefault<PLUGINTYPE>(Instance instance) { - manager.SetDefault<PLUGINTYPE>(instance); + container.SetDefault<PLUGINTYPE>(instance); } public static void SetDefault<PLUGINTYPE, CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE { - manager.SetDefault<PLUGINTYPE, CONCRETETYPE>(); + container.SetDefault<PLUGINTYPE, CONCRETETYPE>(); } @@ -230,7 +231,7 @@ /// <returns></returns> public static object GetInstance(Type pluginType) { - return manager.GetInstance(pluginType); + return container.GetInstance(pluginType); } /// <summary> @@ -240,17 +241,17 @@ /// <returns></returns> public static PLUGINTYPE GetInstance<PLUGINTYPE>() { - return (PLUGINTYPE) manager.GetInstance(typeof (PLUGINTYPE)); + return (PLUGINTYPE) container.GetInstance(typeof (PLUGINTYPE)); } public static object GetInstance(Type TargetType, Instance instance) { - return manager.GetInstance(TargetType, instance); + return container.GetInstance(TargetType, instance); } public static TargetType GetInstance<TargetType>(Instance instance) { - return (TargetType) manager.GetInstance(typeof (TargetType), instance); + return (TargetType) container.GetInstance(typeof (TargetType), instance); } /// <summary> @@ -261,7 +262,7 @@ /// <returns></returns> public static object GetNamedInstance(Type pluginType, string name) { - return manager.GetInstance(pluginType, name); + return container.GetInstance(pluginType, name); } /// <summary> @@ -272,17 +273,17 @@ /// <returns></returns> public static PLUGINTYPE GetNamedInstance<PLUGINTYPE>(string name) { - return (PLUGINTYPE) manager.GetInstance(typeof (PLUGINTYPE), name); + return (PLUGINTYPE) container.GetInstance(typeof (PLUGINTYPE), name); } public static void SetDefaultInstanceName(Type TargetType, string InstanceName) { - manager.SetDefault(TargetType, InstanceName); + container.SetDefault(TargetType, InstanceName); } public static void SetDefaultInstanceName<TargetType>(string InstanceName) { - manager.SetDefault(typeof (TargetType), InstanceName); + container.SetDefault(typeof (TargetType), InstanceName); } /// <summary> @@ -292,7 +293,7 @@ /// <returns></returns> public static IList GetAllInstances(Type pluginType) { - return manager.GetAllInstances(pluginType); + return container.GetAllInstances(pluginType); } /// <summary> @@ -302,7 +303,7 @@ /// <returns></returns> public static IList<PLUGINTYPE> GetAllInstances<PLUGINTYPE>() { - return manager.GetAllInstances<PLUGINTYPE>(); + return container.GetAllInstances<PLUGINTYPE>(); } /// <summary> @@ -313,7 +314,7 @@ /// <returns></returns> public static ExplicitArgsExpression With<T>(T arg) { - return manager.With(arg); + return container.With(arg); } /// <summary> @@ -323,7 +324,7 @@ /// <returns></returns> public static IExplicitProperty With(string argName) { - return manager.With(argName); + return container.With(argName); } Modified: trunk/Source/StructureMap/Pipeline/BuildPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/BuildPolicy.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/Pipeline/BuildPolicy.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -31,5 +31,22 @@ } #endregion + + public bool Equals(BuildPolicy obj) + { + return !ReferenceEquals(null, obj); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj is BuildPolicy; + } + + public override int GetHashCode() + { + return 0; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/CacheInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/CacheInterceptor.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/Pipeline/CacheInterceptor.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -48,5 +48,10 @@ protected abstract void storeInCache(string instanceKey, Type pluginType, object instance); protected abstract bool isCached(string instanceKey, Type pluginType); protected abstract object retrieveFromCache(string instanceKey, Type pluginType); + + public override string ToString() + { + return GetType().FullName + " / " + _innerPolicy.ToString(); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -46,6 +46,8 @@ { foreach (KeyValuePair<string, object> arg in _args) { + if (arg.Value == null) continue; + instance.SetProperty(arg.Key, arg.Value.ToString()); instance.Child(arg.Key).Is(arg.Value); } @@ -62,11 +64,11 @@ } } - public class ExplicitInstance<PLUGINTYPE> : ConfiguredInstance + public class ExplicitInstance : ConfiguredInstance { private readonly ExplicitArguments _args; - public ExplicitInstance(ExplicitArguments args, Instance defaultInstance) + public ExplicitInstance(Type pluginType, ExplicitArguments args, Instance defaultInstance) { args.Configure(this); _args = args; @@ -78,7 +80,7 @@ } else { - setPluggedType(typeof(PLUGINTYPE)); + setPluggedType(pluginType); } } Modified: trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -5,6 +5,8 @@ { public class HttpContextBuildPolicy : CacheInterceptor { + private string _prefix = Guid.NewGuid().ToString(); + public static bool HasContext() { return HttpContext.Current != null; @@ -25,9 +27,9 @@ return HttpContext.Current.Items[getKey(instanceKey, pluginType)]; } - private static string getKey(string instanceKey, Type pluginType) + private string getKey(string instanceKey, Type pluginType) { - return string.Format("{0}:{1}", pluginType.AssemblyQualifiedName, instanceKey); + return string.Format("{0}:{1}:{2}", pluginType.AssemblyQualifiedName, instanceKey, _prefix); } protected override CacheInterceptor clone() Modified: trunk/Source/StructureMap/Pipeline/Instance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Instance.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/Pipeline/Instance.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -33,6 +33,28 @@ set { _name = value; } } + public virtual object Build(Type pluginType, IBuildSession session) + { + object rawValue = createRawObject(pluginType, session); + return applyInterception(rawValue, pluginType); + } + + private object createRawObject(Type pluginType, IBuildSession session) + { + try + { + return build(pluginType, session); + } + catch (StructureMapException ex) + { + throw; + } + catch (Exception ex) + { + throw new StructureMapException(400, ex); + } + } + public InstanceInterceptor Interceptor { get { return _interceptor; } @@ -80,27 +102,7 @@ } } - public virtual object Build(Type pluginType, IBuildSession session) - { - object rawValue = createRawObject(pluginType, session); - return applyInterception(rawValue, pluginType); - } - private object createRawObject(Type pluginType, IBuildSession session) - { - try - { - return build(pluginType, session); - } - catch (StructureMapException ex) - { - throw; - } - catch (Exception ex) - { - throw new StructureMapException(400, ex); - } - } private object applyInterception(object rawValue, Type pluginType) { Modified: trunk/Source/StructureMap/Pipeline/LiteralInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/LiteralInstance.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/Pipeline/LiteralInstance.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -43,5 +43,10 @@ { return "Object: " + _object.ToString(); } + + public override string ToString() + { + return string.Format("LiteralInstance: {0}", _object); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/Profile.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Profile.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/Pipeline/Profile.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -63,6 +63,14 @@ } } + public void Merge(Profile destination) + { + foreach (KeyValuePair<Type, Instance> pair in _instances) + { + destination.SetDefault(pair.Key, pair.Value); + } + } + public void FindMasterInstances(PluginGraph graph) { Dictionary<Type, Instance> master = new Dictionary<Type, Instance>(); @@ -92,5 +100,7 @@ _instances.Add(destinationType, instance); } } + + } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ProfileManager.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -10,16 +10,31 @@ private readonly Profile _default = new Profile(""); private readonly Profile _machineProfile = new Profile("MACHINE"); private readonly Dictionary<string, Profile> _profiles = new Dictionary<string, Profile>(); - private Profile _currentProfile; + private Profile _currentProfile = new Profile(string.Empty); private string _defaultMachineProfileName; private string _defaultProfileName; + private object _locker = new object(); public ProfileManager() { - _currentProfile = _default; + } + private void setProfile(Profile profile) + { + lock (_locker) + { + _currentProfile = new Profile(profile.Name); + profile.FillAllTypesInto(_currentProfile); + + if (!ReferenceEquals(profile, _default)) + { + _default.FillAllTypesInto(_currentProfile); + } + } + } + public string DefaultMachineProfileName { get { return _defaultMachineProfileName; } @@ -39,14 +54,14 @@ { if (string.IsNullOrEmpty(value)) { - _currentProfile = _default; + setProfile(_default); } else { validateHasProfile(value); - _currentProfile = getProfile(value); - _default.FillAllTypesInto(_currentProfile); + Profile profile = getProfile(value); + setProfile(profile); } } } @@ -70,6 +85,11 @@ { Profile profile = getProfile(profileName); profile.SetDefault(pluginType, instance); + if (profileName == _defaultProfileName || profileName == _defaultMachineProfileName) + { + _default.FillTypeInto(pluginType, instance); + _currentProfile.FillTypeInto(pluginType, instance); + } } private Profile getProfile(string profileName) @@ -95,7 +115,8 @@ public void SetDefault(Type pluginType, Instance instance) { - _default.SetDefault(pluginType, instance); + _currentProfile.SetDefault(pluginType, instance); + _default.FillTypeInto(pluginType, instance); } public Instance GetDefault(Type pluginType) @@ -115,7 +136,7 @@ backfillProfiles(); - _currentProfile = _default; + setProfile(_default); } private void backfillProfiles() @@ -181,6 +202,8 @@ { pair.Value.CopyDefault(basicType, templatedType); } + + CurrentProfile = CurrentProfile; } public void ImportFrom(ProfileManager source) @@ -190,12 +213,16 @@ Profile fromProfile = pair.Value; Profile toProfile = getProfile(pair.Key); - fromProfile.FillAllTypesInto(toProfile); + fromProfile.Merge(toProfile); } - source._default.FillAllTypesInto(_default); + source._default.Merge(_default); + + setProfileDefaults(new GraphLog()); + + CurrentProfile = CurrentProfile; } } } \ No newline at end of file Modified: trunk/Source/StructureMap/PipelineGraph.cs =================================================================== --- trunk/Source/StructureMap/PipelineGraph.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/PipelineGraph.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -10,7 +10,7 @@ public interface IPipelineGraphVisitor { - void PluginType(Type pluginType, Instance defaultInstance); + void PluginType(Type pluginType, Instance defaultInstance, IBuildPolicy policy); void Instance(Type pluginType, Instance instance); } @@ -86,8 +86,7 @@ Type pluginType = pair.Value.PluginType; Instance defaultInstance = _profileManager.GetDefault(pluginType); - visitor.PluginType(pluginType, defaultInstance); - pair.Value.ForEachInstance(instance => visitor.Instance(pluginType, instance)); + pair.Value.AcceptVisitor(visitor, defaultInstance); } @@ -106,7 +105,10 @@ { internal List<Instance> Instances = new List<Instance>(); - public void PluginType(Type pluginType, Instance defaultInstance){} + public void PluginType(Type pluginType, Instance defaultInstance, IBuildPolicy policy) + { + // don't care + } public void Instance(Type pluginType, Instance instance) { Modified: trunk/Source/StructureMap/Properties/AssemblyInfo.cs =================================================================== --- trunk/Source/StructureMap/Properties/AssemblyInfo.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/Properties/AssemblyInfo.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -12,4 +12,8 @@ [assembly : InternalsVisibleTo( "StructureMap.AutoMocking, PublicKey=00240000048000009400000006020000002400005253413100040000010001008d9a2a76e43cd9b1b1944b1f3b489a046b33f0bcd755b25cc5d3ed7b18ded38240d6db7578cd986c72d3feb4f94a7ab26fcfa41e3e4f41cf2c029fba91159db05c44d63f0b2bfac24353a07f4a1230dd3d4240340adafa2275277fa083c75958062cd0e60016701db6af7ae718efdf1e802a840595b49c290964255b3c60c494" + )] +[assembly: + InternalsVisibleTo( + "StructureMap.Testing, PublicKey=00240000048000009400000006020000002400005253413100040000010001008d9a2a76e43cd9b1b1944b1f3b489a046b33f0bcd755b25cc5d3ed7b18ded38240d6db7578cd986c72d3feb4f94a7ab26fcfa41e3e4f41cf2c029fba91159db05c44d63f0b2bfac24353a07f4a1230dd3d4240340adafa2275277fa083c75958062cd0e60016701db6af7ae718efdf1e802a840595b49c290964255b3c60c494" )] \ No newline at end of file Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-07-10 20:49:46 UTC (rev 126) @@ -392,6 +392,7 @@ <None Include="..\structuremap.snk"> <Link>Properties\structuremap.snk</Link> </None> + <None Include="ConfigurationClasses.cd" /> <Compile Include="Configuration\DictionaryReader.cs" /> <Compile Include="Configuration\ITypeReader.cs" /> <Compile Include="Configuration\PrimitiveArrayReader.cs" /> Modified: trunk/Source/StructureMap/StructureMapConfiguration.cs =================================================================== --- trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -99,6 +99,7 @@ public static PluginGraph GetPluginGraph() { ConfigurationParser[] parsers = _parserBuilder.GetParsers(); + PluginGraphBuilder pluginGraphBuilder = new PluginGraphBuilder(parsers, _registries.ToArray(), _log); return pluginGraphBuilder.Build(); } Modified: trunk/Source/StructureMap.DataAccess/IDatabaseEngine.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/IDatabaseEngine.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap.DataAccess/IDatabaseEngine.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -15,4 +15,6 @@ IDataParameter CreateParameter(string parameterName, DbType dbType, bool isNullable); string GetParameterName(string logicalName); } + + } \ No newline at end of file Modified: trunk/Source/StructureMap.DataAccess/StructureMap.DataAccess.csproj =================================================================== --- trunk/Source/StructureMap.DataAccess/StructureMap.DataAccess.csproj 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap.DataAccess/StructureMap.DataAccess.csproj 2008-07-10 20:49:46 UTC (rev 126) @@ -11,8 +11,7 @@ <AssemblyKeyContainerName> </AssemblyKeyContainerName> <AssemblyName>StructureMap.DataAccess</AssemblyName> - <AssemblyOriginatorKeyFile> - </AssemblyOriginatorKeyFile> + <AssemblyOriginatorKeyFile>structuremap.snk</AssemblyOriginatorKeyFile> <DefaultClientScript>JScript</DefaultClientScript> <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout> <DefaultTargetSchema>IE50</DefaultTargetSchema> @@ -27,6 +26,7 @@ <UpgradeBackupLocation> </UpgradeBackupLocation> <OldToolsVersion>2.0</OldToolsVersion> + <SignAssembly>true</SignAssembly> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <OutputPath>bin\Debug\</OutputPath> @@ -219,6 +219,7 @@ <Compile Include="MSSQL\MSSQLDatabaseEngine.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Oracle\OracleDatabaseEngine.cs" /> <Compile Include="ParameterCollection.cs"> <SubType>Code</SubType> </Compile> @@ -302,8 +303,10 @@ </ProjectReference> </ItemGroup> <ItemGroup> + <None Include="structuremap.snk" /> + </ItemGroup> + <ItemGroup> <Folder Include="Exceptions\" /> - <Folder Include="Oracle\" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <PropertyGroup> Added: trunk/Source/StructureMap.DataAccess/structuremap.snk =================================================================== (Binary files differ) Property changes on: trunk/Source/StructureMap.DataAccess/structuremap.snk ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -44,7 +44,7 @@ return new InstanceMemento[0]; } - protected override bool containsKey(string instanceKey) + protected internal override bool containsKey(string instanceKey) { throw new NotImplementedException(); } Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2008-06-23 17:44:01 UTC (rev 125) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2008-07-10 20:49:46 UTC (rev 126) @@ -14,7 +14,7 @@ [SetUp] public void SetUp() { - manager = new Container(registry => + container = new Container(registry => { registry.ScanAssemblies().IncludeAssemblyContainingType<ColorWidget>(); @@ -43,19 +43,19 @@ #endregion - private IContainer manager; + private IContainer container; [Test] public void AddAnInstanceWithANameAndAPropertySpecifyingConcreteKey() { - ... [truncated message content] |
From: <jer...@us...> - 2008-06-23 17:44:03
|
Revision: 125 http://structuremap.svn.sourceforge.net/structuremap/?rev=125&view=rev Author: jeremydmiller Date: 2008-06-23 10:44:01 -0700 (Mon, 23 Jun 2008) Log Message: ----------- docs Modified Paths: -------------- trunk/Source/HTML/HTML.csproj trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap/ExplicitArgsExpression.cs trunk/Source/StructureMap/IContainer.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs trunk/Source/StructureMap.Testing/Configuration/DictionaryAndArrayArgumentTester.cs trunk/Source/StructureMap.Testing/Configuration/PrimitiveArrayReaderTester.cs trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing/TestData/StructureMap.config trunk/Source/StructureMap.Testing.Widget5/OtherGridColumn.cs trunk/Source/StructureMap.sln Added Paths: ----------- trunk/Source/HTML/AttributeNormalized.htm trunk/Source/HTML/AutoMocking.htm trunk/Source/HTML/BestPractices.htm trunk/Source/HTML/ChangingDefaultsAtRuntime.htm trunk/Source/HTML/CompositeConfiguration.htm trunk/Source/HTML/Concepts.htm trunk/Source/HTML/ConcreteTypes.htm trunk/Source/HTML/ConfigurationArchitecture.htm trunk/Source/HTML/ConfiguringStructureMap.htm trunk/Source/HTML/ConstructorAndSetterInjection.htm trunk/Source/HTML/CreatingContainer.htm trunk/Source/HTML/Default.htm trunk/Source/HTML/Diagnostics.htm trunk/Source/HTML/EnvironmentTests.htm trunk/Source/HTML/ExtendingStructureMap.htm trunk/Source/HTML/FAQ.htm trunk/Source/HTML/FluentInterfaceAPI.htm trunk/Source/HTML/Generics.htm trunk/Source/HTML/GentleGuide.htm trunk/Source/HTML/HTML.csproj.user trunk/Source/HTML/ImplicitInstances.htm trunk/Source/HTML/InjectingServicesAtRuntime.htm trunk/Source/HTML/Interception.htm trunk/Source/HTML/NodeNormalized.htm trunk/Source/HTML/Profiles.htm trunk/Source/HTML/QuickStart.htm trunk/Source/HTML/RetrievingServices.htm trunk/Source/HTML/RuntimeArchitecture.htm trunk/Source/HTML/Sample.xml trunk/Source/HTML/ScanningAssemblies.htm trunk/Source/HTML/Scoping.htm trunk/Source/HTML/StructureMapAndMocks.htm trunk/Source/HTML/StructureMapDoctor.htm trunk/Source/HTML/TroubleShooting.htm trunk/Source/HTML/UsingStructureMapWithinUnitTests.htm trunk/Source/HTML/WhatWillStructureMapDoWhenI.htm trunk/Source/HTML/XmlConfiguration.htm trunk/Source/StructureMap.Testing/Examples.cs trunk/Source/StructureMap.sln.cache Removed Paths: ------------- trunk/Source/StructureMap/Delegates.cs Property Changed: ---------------- trunk/ Property changes on: trunk ___________________________________________________________________ Name: svn:ignore - build results + build results push.bat Added: trunk/Source/HTML/AttributeNormalized.htm =================================================================== --- trunk/Source/HTML/AttributeNormalized.htm (rev 0) +++ trunk/Source/HTML/AttributeNormalized.htm 2008-06-23 17:44:01 UTC (rev 125) @@ -0,0 +1,462 @@ +<!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> + </head> + <body> + <h1>Attribute Normalized Xml Instances</h1> + <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> + <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, + PluginFamily/Instance, Interceptor, and Source nodes in Xml configuration are + all Instance roots. The rules for an Instance node are the same regardless + of the context. The root node optionally specifies the name of the + instance and the concrete type of the instance.</p> + <p>For a class called ColorRule,</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;\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;"> + <p style="margin: 0px;"> + [<span style="color: #2b91af;">Pluggable</span>(<span + style="color: #a31515;">"Color"</span>)]</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;">class</span> + <span style="color: #2b91af;">ColorRule</span> : <span style="color: #2b91af;"> + Rule</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;">private</span> + <span style="color: blue;">string</span> _Color;</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">string</span> ID = <span style="color: #2b91af;">Guid</span>.NewGuid().ToString();</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + ColorRule(<span style="color: blue;">string</span> Color)</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + _Color = Color;</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;">string</span> Color</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: blue;">get</span> { <span style="color: blue;">return</span> + _Color; }</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p>an Instance node might look like:</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;}??\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;"> + <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 + style="color: blue;">Red</span>"<span style="color: blue;"> </span> + <span style="color: red;">Type</span><span style="color: blue;">=</span>"<span + style="color: blue;">Color</span>"<span style="color: blue;"> </span> + <span style="color: red;">Color</span><span style="color: blue;">=</span>"<span + style="color: blue;">Red</span>"<span style="color: blue;"> /></span></p> + </div> +<!--EndFragment--> +<p>The "name" of an Instance is definied by the Key attribute. The concrete + type can be specified in one of two ways. You can either use the "Type" + attribute above to specify the aliased concrete type, or do it more explicitly + by setting the PluggedType attribute to the assembly qualified name of the + concrete type.</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;}??\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;"> + <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 + style="color: blue;">Red</span>"<span style="color: blue;"> </span> + <span style="color: red;">PluggedType</span><span style="color: blue;">=</span>"<span + style="color: blue;">StructureMap.Testing.Widget.Color, + StructureMap.Testing.Widget</span>"<span style="color: blue;"> </span> + <span style="color: red;">Color</span><span style="color: blue;">=</span>"<span + 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> +<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> +</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> +</div> + +<h4>Long Strings</h4> + <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> +<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: red;">Type</span><span style="color: blue;">="Sql"</span><span style="color: fuchsia;"> </span><span style="color: red;">Key</span><span style="color: blue;">="SomeQuery"></span></pre> +<pre style="margin: 0px;"><span style="color: blue;"> <bigProp></span></pre> +<pre style="margin: 0px;"> <span style="color: blue;"><![</span><span style="color: fuchsia;">CDATA[</span></pre> +<pre style="margin: 0px;"><span style="color: fuchsia;"> select </span><span style="color: blue;">*</span><span style="color: fuchsia;"> from table</span></pre> +<pre style="margin: 0px;"><span style="color: fuchsia;"> where</span></pre> +<pre style="margin: 0px;"><span style="color: fuchsia;"> somecolumn = </span><span style="color: blue;">'something'</span><span style="color: fuchsia;"> or</span></pre> +<pre style="margin: 0px;"><span style="color: fuchsia;"> some_other_column = </span><span style="color: blue;">'something else'</span></pre> +<pre style="margin: 0px;"><span style="color: fuchsia;"> </span><span style="color: blue;">]]></span></pre> +<pre style="margin: 0px;"><span style="color: #0000FF"> </span><span style="color: blue;"></</span><span style="color: #800000">bigProp</span><span style="color: blue;">></span></pre> +<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> + <p>Enumeration arguments are defined the same way as + primitive properties. Use the string names of the + enumeration for the values.</p> +<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;">public</span> <span style="color: blue;">enum</span> BreedEnum</pre> +<pre style="margin: 0px;"> {</pre> +<pre style="margin: 0px;"> Hereford,</pre> +<pre style="margin: 0px;"> Angus,</pre> +<pre style="margin: 0px;"> Longhorn</pre> +<pre style="margin: 0px;"> }</pre> +<pre style="margin: 0px;"> </pre> +<pre style="margin: 0px;"> [Pluggable("Cow")]</pre> +<pre style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> Cow</pre> +<pre style="margin: 0px;"> {</pre> +<pre style="margin: 0px;"> <span style="color: blue;">public</span> BreedEnum Breed;</pre> +<pre style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: blue;">long</span> Weight;</pre> +<pre style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span> Name;</pre> +<pre style="margin: 0px;"> </pre> +<pre style="margin: 0px;"> <span style="color: blue;">public</span> Cow(<span style="color: blue;">long</span> Weight, BreedEnum Breed, <span style="color: blue;">string</span> Name)</pre> +<pre style="margin: 0px;"> {</pre> +<pre style="margin: 0px;"> <span style="color: blue;">this</span>.Breed = Breed;</pre> +<pre style="margin: 0px;"> <span style="color: blue;">this</span>.Weight = Weight;</pre> +<pre style="margin: 0px;"> <span style="color: blue;">this</span>.Name = Name;</pre> +<pre style="margin: 0px;"> }</pre> +<pre style="margin: 0px;"> }</pre> +</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: #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> + <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 + property type. If a child property is omitted or + defined with no value, StructureMap will use the default + instance of the property type. Simply add a child node to the main instance + node with the name of the constructor argument or setter property name.</p> +<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;"> [PluginFamily, Pluggable("Default", "")]</pre> +<pre style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> GrandChild</pre> +<pre style="margin: 0px;"> {</pre> +<pre style="margin: 0px;"> <span style="color: blue;">public</span> GrandChild(<span style="color: blue;">bool</span> RightHanded, <span style="color: blue;">int</span> BirthYear)</pre> +<pre style="margin: 0px;"> {</pre> +<pre style="margin: 0px;"> }</pre> +<pre style="margin: 0px;"> }</pre> +<pre style="margin: 0px;"> </pre> +<pre style="margin: 0px;"> </pre> +<pre style="margin: 0px;"> [Pluggable("Leftie", "")]</pre> +<pre style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> LeftieGrandChild : GrandChild</pre> +<pre style="margin: 0px;"> {</pre> +<pre style="margin: 0px;"> <span style="color: blue;">public</span> LeftieGrandChild(<span style="color: blue;">int</span> BirthYear) : <span style="color: blue;">base</span>(<span style="color: blue;">false</span>, BirthYear)</pre> +<pre style="margin: 0px;"> {</pre> +<pre style="margin: 0px;"> }</pre> +<pre style="margin: 0px;"> }</pre> +<pre style="margin: 0px;"> </pre> +<pre style="margin: 0px;"> </pre> +<pre style="margin: 0px;"> [PluginFamily, Pluggable("Default", "")]</pre> +<pre style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> Child</pre> +<pre style="margin: 0px;"> {</pre> +<pre style="margin: 0px;"> <span style="color: blue;">public</span> Child(<span style="color: blue;">string</span> Name, GrandChild MyGrandChild)</pre> +<pre style="margin: 0px;"> {</pre> +<pre style="margin: 0px;"> }</pre> +<pre style="margin: 0px;"> }</pre> +</div> +<br> +<h4>Inline Definition</h4> +<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;">StructureMap.Testing.Widget.Child</span><span style="color: fuchsia;"> </span><span style="color: red;">Type</span><span style="color: blue;">="Default"</span><span style="color: fuchsia;"> </span><span style="color: red;">Key</span><span style="color: blue;">="Tom" </span><span style="color: red;">Name</span><span style="color: blue;">="Tom"></span></pre> +<pre style="margin: 0px;"> <span style="color: blue;"><</span><span style="color: maroon;">MyGrandChild</span><span style="color: fuchsia;"> </span><span style="color: red;">Name</span><span style="color: blue;">="MyGrandChild"</span><span style="color: fuchsia;"> </span><span style="color: red;">Type</span><span style="color: blue;">="Leftie" </span><span style="color: #FF0000">BirthYear</span><span style="color: blue;">="1984" /></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> +<h4>Reference Definition</h4> +<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;">StructureMap.Testing.Widget.Child</span><span style="color: fuchsia;"> </span><span style="color: red;">Type</span><span style="color: blue;">="Default"</span><span style="color: fuchsia;"> </span><span style="color: red;">Key</span><span style="color: blue;">="Marsha" </span><span style="color: red;">Name</span><span style="color: blue;">="Marsha"></span></pre> +<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> +<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 + nodes for each element of the array. These <Child> nodes are Attribute + Normalized InstanceMemento's and follow the same rules expressed in this + document.</p> +<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;"> [Pluggable("Compound")]</pre> +<pre style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> CompoundStrategy : IStrategy</pre> +<pre style="margin: 0px;"> {</pre> +<pre style="margin: 0px;"> <span style="color: blue;">public</span> CompoundStrategy(IStrategy[] innerStrategies)</pre> +<pre style="margin: 0px;"> {</pre> +<pre style="margin: 0px;"> }</pre> +<pre style="margin: 0px;"> }</pre> +</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;">Instance</span><span style="color: fuchsia;"> </span><span style="color: red;">Key</span><span style="color: blue;">="ArrayTest"</span><span style="color: fuchsia;"> </span><span style="color: red;">Type</span><span style="color: blue;">="Compound"></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: green;">-- Referenced Instance --</span><span style="color: blue;">></span></pre> +<pre style="margin: 0px;"> <span style="color: blue;"><</span><span style="color: #800000">Child</span><span style="color: fuchsia;"> </span><span style="color: red;">Key</span><span style="color: blue;">="Red" /></span></pre> +<pre style="margin: 0px;"> </pre> +<pre style="margin: 0px;"> <span style="color: blue;"><</span><span style="color: #800000">Child</span><span style="color: blue;">><!</span><span style="color: green;">-- Default Instance --</span><span style="color: blue;">></</span><span style="color: #800000">Child</span><span style="color: blue;">></span></pre> +<pre style="margin: 0px;"> </pre> +<pre style="margin: 0px;"> <span style="color: blue;"><!</span><span style="color: green;">-- Inline Definition --</span><span style="color: blue;">></span></pre> +<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> +</div> +<h3>Primitive Arrays</h3> + <p>Primitive arrays like string[] or int[] can be defined in Xml. For a class + with arguments like:</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;}??\fs20 \cf3 public\cf0 ClassWithStringAndIntArray(\cf3 int\cf0 [] numbers, \cf3 string\cf0 [] strings)\par ?? \{\par ?? _numbers = numbers;\par ?? _strings = strings;\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + ClassWithStringAndIntArray(<span style="color: blue;">int</span>[] numbers, + <span style="color: blue;">string</span>[] strings)</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + _numbers = numbers;</p> + <p style="margin: 0px;"> + _strings = strings;</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p>The Xml configuration is:</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;}??\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;"> + <p style="margin: 0px;"> + <span style="color: blue;"> <</span><span style="color: #a31515;">DefaultInstance</span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> </span><span style="color: red;"> + PluginType</span><span style="color: blue;">=</span>"<span style="color: blue;">StructureMap.Testing.Configuration.ClassWithStringAndIntArray, + StructureMap.Testing</span>"</p> + <p style="margin: 0px;"> + <span style="color: blue;"> </span><span style="color: red;"> + PluggedType</span><span style="color: blue;">=</span>"<span + style="color: blue;">StructureMap.Testing.Configuration.ClassWithStringAndIntArray, + StructureMap.Testing</span>"<span style="color: blue;">></span></p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span class="style1" style="color: blue;"> <</span><span + class="style1" style="color: #a31515;">numbers</span><span class="style1" + style="color: blue;"> </span><span class="style1" style="color: red;">Values</span><span + class="style1" style="color: blue;">=</span>"<span class="style1" + style="color: blue;">1,2,3</span>"<span class="style1" style="color: blue;">/></span></p> + <p style="margin: 0px;"> + <span class="style1" style="color: blue;"> <</span><span + class="style1" style="color: #a31515;">strings</span><span class="style1" + style="color: blue;"> </span><span class="style1" style="color: red;">Values</span><span + class="style1" style="color: blue;">=</span>"<span class="style1" + style="color: blue;">1,2,3</span>"<span class="style1" style="color: blue;">/></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> </</span><span style="color: #a31515;">DefaultInstance</span><span + style="color: blue;">></span></p> + </div> +<!--EndFragment--> +<p>By default, the Values attribute is assumed to be a comma delimited list. + The delimiter of the list can be optionally overriden by using the Delimiter + attribute.</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;}??\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;"> + <p style="margin: 0px;"> + <span style="color: blue;"> <</span><span style="color: #a31515;">DefaultInstance</span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> </span><span style="color: red;"> + PluginType</span><span style="color: blue;">=</span>"<span style="color: blue;">StructureMap.Testing.Configuration.ClassWithStringAndIntArray, + StructureMap.Testing</span>"</p> + <p style="margin: 0px;"> + <span style="color: blue;"> </span><span style="color: red;"> + PluggedType</span><span style="color: blue;">=</span>"<span + style="color: blue;">StructureMap.Testing.Configuration.ClassWithStringAndIntArray, + StructureMap.Testing</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;">numbers</span><span style="color: blue;"> </span> + <span style="color: red;">Values</span><span style="color: blue;">=</span>"<span + style="color: blue;">1;2;3</span>"<span style="color: blue;"> </span> + <span style="color: red;">Delimiter</span><span style="color: blue;">=</span>"<span + style="color: blue;">;</span>"<span style="color: blue;">/></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> <</span><span + style="color: #a31515;">strings</span><span style="color: blue;"> </span> + <span style="color: red;">Values</span><span style="color: blue;">=</span>"<span + style="color: blue;">1,2,3</span>"<span style="color: blue;">/></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> </</span><span style="color: #a31515;">DefaultInstance</span><span + style="color: blue;">></span></p> +</div> +<!--EndFragment--> +<h3>Dictionaries and NameValueCollection</h3> +<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;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;"> + class</span> <span style="color: #2b91af;">ClassWithDictionary</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;"> + IDictionary</span><<span style="color: blue;">string</span>, + <span style="color: blue;">string</span>> _dictionary;</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + ClassWithDictionary(<span style="color: #2b91af;">IDictionary</span><<span + style="color: blue;">string</span>, <span style="color: blue;">string</span>> + dictionary)</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + _dictionary = + dictionary;</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: #2b91af;">IDictionary</span><<span style="color: blue;">string</span>, + <span style="color: blue;">string</span>> Dictionary</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: blue;">get</span> { <span style="color: blue;">return</span> + _dictionary; }</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + }</p> +</div> +<!--EndFragment--> +<p>The "dictionary" argument to the constructor function could be defined as:</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;}??\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 Property\cf1 \cf4 Name\cf1 =\cf0 '\cf1 dictionary\cf0 '\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 Property\cf1 >\par ?? </\cf3 DefaultInstance\cf1 >} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"> +<!-- +{\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;"> + <p style="margin: 0px;"> + <span style="color: blue;"> <</span><span style="color: #a31515;">DefaultInstance</span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> </span><span style="color: red;"> + PluginType</span><span style="color: blue;">=</span>"<span style="color: blue;">StructureMap.Testing.Configuration.ClassWithDictionary, + StructureMap.Testing</span>"</p> + <p style="margin: 0px;"> + <span style="color: blue;"> </span><span style="color: red;"> + PluggedType</span><span style="color: blue;">=</span>"<span + style="color: blue;">StructureMap.Testing.Configuration.ClassWithDictionary, + StructureMap.Testing</span>"<span style="color: blue;">></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> <</span><span + style="color: #a31515;">dictionary</span><span style="color: blue;">></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> <</span><span + style="color: #a31515;">Pair</span><span style="color: blue;"> </span> + <span style="color: red;">Key</span><span style="color: blue;">="color" </span> + <span style="color: red;">Value</span><span style="color: blue;">="red"/></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> <</span><span + style="color: #a31515;">Pair</span><span style="color: blue;"> </span> + <span style="color: red;">Key</span><span style="color: blue;">="state" </span> + <span style="color: red;">Value</span><span style="color: blue;">="texas"/></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> <</span><span + style="color: #a31515;">Pair</span><span style="color: blue;"> </span> + <span style="color: red;">Key</span><span style="color: blue;">="direction" </span> + <span style="color: red;">Value</span><span style="color: blue;">="north"/></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> </</span><span + style="color: #a31515;">dictionary</span><span style="color: blue;">></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> </</span><span style="color: #a31515;">DefaultInstance</span><span + style="color: blue;">></span></p> + </div> +<!--EndFragment--> +<p style="margin: 0px;"> + </p> + + </div> +<!--EndFragment--> +<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> + + </body> +</html> Added: trunk/Source/HTML/AutoMocking.htm =================================================================== --- trunk/Source/HTML/AutoMocking.htm (rev 0) +++ trunk/Source/HTML/AutoMocking.htm 2008-06-23 17:44:01 UTC (rev 125) @@ -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/BestPractices.htm =================================================================== --- trunk/Source/HTML/BestPractices.htm (rev 0) +++ trunk/Source/HTML/BestPractices.htm 2008-06-23 17:44:01 UTC (rev 125) @@ -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/ChangingDefaultsAtRuntime.htm =================================================================== --- trunk/Source/HTML/ChangingDefaultsAtRuntime.htm (rev 0) +++ trunk/Source/HTML/ChangingDefaultsAtRuntime.htm 2008-06-23 17:44:01 UTC (rev 125) @@ -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/CompositeConfiguration.htm =================================================================== --- trunk/Source/HTML/CompositeConfiguration.htm (rev 0) +++ trunk/Source/HTML/CompositeConfiguration.htm 2008-06-23 17:44:01 UTC (rev 125) @@ -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/Concepts.htm =================================================================== --- trunk/Source/HTML/Concepts.htm (rev 0) +++ trunk/Source/HTML/Concepts.htm 2008-06-23 17:44:01 UTC (rev 125) @@ -0,0 +1,49 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> +<html> + <head> + <title></title> + </head> + <body> + <h3>Patterns and Concepts</h3> + <p> + Object oriented systems are composed of a myriad array of objects communicating + by sending messages to exposed interfaces. To a large degree, the qualities of + an OO design are determined by the structure, organization, and responsibility + assignments of the objects in a system. The qualities of a system most + affected by structure are flexibility, extensibility, maintainability, and + testability. Applications usually meet their demise when the system is + determined to be too difficult or costly to change. The symptoms of a dying + application are a loss of clearly defined structure, an unclear division + of responsibilities in the code, and difficulty testing and troubleshooting the + application. </p> + <p> + Over the years a series of rules and principles have been discovered and + developed to describe well-structured systems. Possibly most important is + <em>Separation of Concerns</em> – pulling separate aspects of the system like + persistence, security, or business logic into separate classes and packages. + Another key concept is the combination of highly cohesive classes in a loosely + coupled structure. The more highly coupled two components of a system are, the + more difficult the system is to maintain, test, and reuse. A class should have a + cohesive set of responsibilities in a narrow domain. In other words, + simpleton classes that do only one thing are much easier to code and test than + <em>God</em> classes that take on far too many unrelated responsibilities. </p> + <p> </p> + <h4>Separation of Concerns</h4> + <h4>Services and Dependencies</h4> + <h4>Dependency Injection</h4> + <h4>Container</h4> + <h4>Service Locator</h4> + <h3>StructureMap Terms</h3> + <h4>PluginType</h4> + <p>Object Oriented Design</p> + <h4>Auto Wiring</h4> + <p>Every "real" IoC container supports the concept of "Auto Wiring." Auto + Wiring simply means that StructureMap can figure out dependency chains for you.</p> + <h4>Instance</h4> + <h4>Scoping</h4> + <h4>PluginFamily</h4> + <h4>Profile</h4> + <h4>Interceptor</h4> + <h4>PostProcessor</h4> + </body> +</html> \ No newline at end of file Added: trunk/Source/HTML/ConcreteTypes.htm =================================================================== --- trunk/Source/HTML/ConcreteTypes.htm (rev 0) +++ trunk/Source/HTML/ConcreteTypes.htm 2008-06-23 17:44:01 UTC (rev 125) @@ -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/ConfigurationArchitecture.htm =================================================================== --- trunk/Source/HTML/ConfigurationArchitecture.htm (rev 0) +++ trunk/Source/HTML/ConfigurationArchitecture.htm 2008-06-23 17:44:01 UTC (rev 125) @@ -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/ConfiguringStructureMap.htm =================================================================== --- trunk/Source/HTML/ConfiguringStructureMap.htm (rev 0) +++ trunk/Source/HTML/ConfiguringStructureMap.htm 2008-06-23 17:44:01 UTC (rev 125) @@ -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/ConstructorAndSetterInjection.htm =================================================================== --- trunk/Source/HTML/ConstructorAndSetterInjection.htm (rev 0) +++ trunk/Source/HTML/ConstructorAndSetterInjection.htm 2008-06-23 17:44:01 UTC (rev 125) @@ -0,0 +1,391 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> +<html> + <head> + <title>Constructor and Setter Injection</title> + </head> + <body> + <h1>Constructor and Setter Injection</h1> + + <p>StructureMap supports two forms of Dependency Injection:</p> + + <ol> + <li>Constructor Injection -- "Pushing" dependencies into a concrete class through + constructor arguments.</li> + <li>Setter Injection -- "Pushing" depencencies into a concrete class through public + properties. The "Setter" nomenclature is taken from Java where properties + are getSomething() and setSomething(value).</li> + </ol> + + <p>You can certainly mix and match Setter Injection with Constructor Injection on + the same classes, but Constructor Injection will always be used (except for + empty constructors) and Setter Injection has to be explicitly configured. + See + <a href="http://martinfowler.com/articles/injection.html#ConstructorVersusSetterInjection"> + Martin Fowler's discussion on Constructor versus Setter Injection</a> for more + information. My feeling has always been that Constructor Injection is + preferrable from a design perspective. When you exclusively use + Constructor Injection, the code is somewhat self-documenting because the + constructor arguments will clearly delineate the dependencies of a concrete + class. It's also important to think about the constructor method of a + class being a contract. If you satisfy all of the arguments of the + constructor method, the class should be ready to function. Relying on + Setter Injection can make a class harder to use because it isn't always obvious + which setters need to be created externally to use the class. Of course, + not using any form of Dependency Injection can be the worst answer because then + you have no idea what it really takes to bootstrap the service. </p> + <h2>Using Constructor Injection</h2> + <p>Now, the first question you might ask is how does StructureMap know which + constructor function to use in a class that has multiple constructors? The + answer is that StructureMap will automatically select the "greediest" public + constructor of a class to use for injection. In this case, the "greediest" + constructor is the constructor with the most arguments. In the case of a + tie, StructureMap will use the first constructor that it encountered. For + example, in the code below, the second constructor that takes in two arguments + would be used because it is "greedier."</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;}??\fs20 \cf3 public\cf0 GreaterThanRule()\par ?? \{\par ?? \}\par ??\par ?? \cf3 public\cf0 GreaterThanRule(\cf3 string\cf0 Attribute, \cf3 int\cf0 Value)\par ?? \{\par ?? _Attribute = Attribute;\par ?? _Value = Value;\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + GreaterThanRule()</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> + GreaterThanRule(<span style="color: blue;">string</span> Attribute, + <span style="color: blue;">int</span> Value)</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + _Attribute = Attribute;</p> + <p style="margin: 0px;"> + _Value = Value;</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p> </p> + <p>You can always override this behavior by decorating the constructor you want + StructureMap to use with the [StructureMap.DefaultConstructor] attribute like + this sample:</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;}??\fs20 [\cf3 DefaultConstructor\cf0 ]\par ?? \cf4 public\cf0 DataSession(\cf3 IDatabaseEngine\cf0 database)\par ?? : \cf4 this\cf0 (database,\par ?? \cf4 new\cf0 \cf3 CommandFactory\cf0 (database),\par ?? \cf4 new\cf0 \cf3 AutoCommitExecutionState\cf0 (database.GetConnection(), database.GetDataAdapter()),\par ?? \cf4 new\cf0 \cf3 TransactionalExecutionState\cf0 (database.GetConnection(), database.GetDataAdapter()))\par ?? \{\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"> + <p style="margin: 0px;"> + [<span style="color: #2b91af;">DefaultConstructor</span>]</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + DataSession(<span style="color: #2b91af;">IDatabaseEngine</span> database)</p> + <p style="margin: 0px;"> + : + <span style="color: blue;">this</span>(database,</p> + <p style="margin: 0px;"> + + <span style="color: blue;">new</span> <span style="color: #2b91af;"> + CommandFactory</span>(database),</p> + <p style="margin: 0px;"> + + <span style="color: blue;">new</span> <span style="color: #2b91af;"> + AutoCommitExecutionState</span>(database.GetConnection(), + dat... [truncated message content] |
From: <jer...@us...> - 2008-06-19 03:10:36
|
Revision: 124 http://structuremap.svn.sourceforge.net/structuremap/?rev=124&view=rev Author: jeremydmiller Date: 2008-06-18 20:10:34 -0700 (Wed, 18 Jun 2008) Log Message: ----------- updated NAnt Modified Paths: -------------- trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap/Diagnostics/GraphLog.cs trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs trunk/Source/StructureMap/IContainer.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/Pipeline/Instance.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/bin/Rhino.Mocks.dll trunk/bin/nant/NAnt.CompressionTasks.dll trunk/bin/nant/NAnt.CompressionTasks.xml trunk/bin/nant/NAnt.Core.dll trunk/bin/nant/NAnt.Core.xml trunk/bin/nant/NAnt.DotNetTasks.dll trunk/bin/nant/NAnt.DotNetTasks.xml trunk/bin/nant/NAnt.MSNetTasks.dll trunk/bin/nant/NAnt.MSNetTasks.xml trunk/bin/nant/NAnt.NUnit.dll trunk/bin/nant/NAnt.NUnit1Tasks.dll trunk/bin/nant/NAnt.NUnit2Tasks.dll trunk/bin/nant/NAnt.NUnit2Tasks.xml trunk/bin/nant/NAnt.SourceControlTasks.dll trunk/bin/nant/NAnt.SourceControlTasks.xml trunk/bin/nant/NAnt.VSNetTasks.dll trunk/bin/nant/NAnt.VSNetTasks.xml trunk/bin/nant/NAnt.VisualCppTasks.dll trunk/bin/nant/NAnt.VisualCppTasks.xml trunk/bin/nant/NAnt.Win32Tasks.dll trunk/bin/nant/NAnt.Win32Tasks.xml trunk/bin/nant/NAnt.exe trunk/bin/nant/NAnt.exe.config trunk/bin/nant/NAnt.xml trunk/bin/nant/NDoc.Documenter.NAnt.dll trunk/bin/nant/lib/mono/1.0/nunit.core.dll trunk/bin/nant/lib/mono/1.0/nunit.framework.dll trunk/bin/nant/lib/mono/1.0/nunit.util.dll trunk/bin/nant/lib/mono/2.0/nunit.core.dll trunk/bin/nant/lib/mono/2.0/nunit.framework.dll trunk/bin/nant/lib/mono/2.0/nunit.util.dll trunk/bin/nant/lib/net/1.0/nunit.core.dll trunk/bin/nant/lib/net/1.0/nunit.framework.dll trunk/bin/nant/lib/net/1.0/nunit.util.dll trunk/bin/nant/lib/net/1.1/nunit.core.dll trunk/bin/nant/lib/net/1.1/nunit.framework.dll trunk/bin/nant/lib/net/1.1/nunit.util.dll trunk/bin/nant/lib/net/2.0/nunit.core.dll trunk/bin/nant/lib/net/2.0/nunit.framework.dll trunk/bin/nant/lib/net/2.0/nunit.util.dll trunk/bin/nant/log4net.dll trunk/bin/nant/scvs.exe Added Paths: ----------- trunk/bin/nant/extensions/ trunk/bin/nant/extensions/common/ trunk/bin/nant/extensions/common/2.0/ trunk/bin/nant/extensions/common/2.0/NAnt.MSBuild.dll trunk/bin/nant/extensions/common/2.0/NAnt.MSBuild.xml trunk/bin/nant/lib/common/ trunk/bin/nant/lib/common/neutral/ trunk/bin/nant/lib/common/neutral/ICSharpCode.SharpCvsLib.Console.dll trunk/bin/nant/lib/common/neutral/ICSharpCode.SharpCvsLib.dll trunk/bin/nant/lib/common/neutral/ICSharpCode.SharpZipLib.dll trunk/bin/nant/lib/common/neutral/NUnitCore.dll Modified: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs 2008-06-16 02:12:53 UTC (rev 123) +++ trunk/Source/StructureMap/Container.cs 2008-06-19 03:10:34 UTC (rev 124) @@ -5,6 +5,7 @@ using System.Text; using StructureMap.Configuration.DSL; using StructureMap.Diagnostics; +using StructureMap.Exceptions; using StructureMap.Graph; using StructureMap.Interceptors; using StructureMap.Pipeline; @@ -280,6 +281,17 @@ return new ExplicitArgsExpression(this).With(argName); } + public void AssertConfigurationIsValid() + { + ValidationBuildSession session = new ValidationBuildSession(_pipelineGraph, _interceptorLibrary); + session.PerformValidations(); + + if (!session.Success) + { + throw new StructureMapConfigurationException(session.BuildErrorMessages()); + } + } + #endregion private IBuildSession withNewSession() Modified: trunk/Source/StructureMap/Diagnostics/GraphLog.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/GraphLog.cs 2008-06-16 02:12:53 UTC (rev 123) +++ trunk/Source/StructureMap/Diagnostics/GraphLog.cs 2008-06-19 03:10:34 UTC (rev 124) @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.IO; using System.Text; @@ -12,15 +13,22 @@ { private string _currentSource; private readonly List<Error> _errors = new List<Error>(); + private List<string> _sources = new List<string>(); public int ErrorCount { get { return _errors.Count; } } + public string[] Sources + { + get { return _sources.ToArray(); } + } + public void StartSource(string description) { _currentSource = description; + _sources.Add(description); } public void RegisterError(IDiagnosticInstance instance, int code, params object[] args) Modified: trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs 2008-06-16 02:12:53 UTC (rev 123) +++ trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs 2008-06-19 03:10:34 UTC (rev 124) @@ -107,6 +107,11 @@ } } + public void Source(string source) + { + throw new NotImplementedException(); + } + private void validate(Type pluginType, Instance instance, object builtObject) { MethodInfo[] methods = ValidationMethodAttribute.GetValidationMethods(builtObject.GetType()); Modified: trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2008-06-16 02:12:53 UTC (rev 123) +++ trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2008-06-19 03:10:34 UTC (rev 124) @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Text; using StructureMap.Graph; using StructureMap.Pipeline; @@ -20,19 +21,46 @@ public string GetText() { + StringBuilder sb = new StringBuilder(); + StringWriter writer = new StringWriter(sb); + + writeSources(writer); + writeContentsOfPluginTypes(writer); + + return sb.ToString(); + } + + private void writeContentsOfPluginTypes(StringWriter stringWriter) + { _writer = new TextReportWriter(3); _instances = new List<Instance>(); _writer.AddDivider('='); - _writer.AddText("PluginType", "Name", "Description"); + _writer.AddText("PluginType", "Name", "Description"); _graph.Visit(this); _writer.AddDivider('='); - return _writer.Write(); + _writer.Write(stringWriter); } + private void writeSources(StringWriter writer) + { + writer.WriteLine("==========================================================================================================="); + writer.WriteLine("Configuration Sources:"); + writer.WriteLine(); + + for (int i = 0; i < _graph.Log.Sources.Length; i++) + { + var source = _graph.Log.Sources[i]; + string message = (i.ToString() + ")").PadRight(5) + source; + writer.WriteLine(message); + } + + writer.WriteLine(); + } + void IPipelineGraphVisitor.PluginType(Type pluginType, Instance defaultInstance) { _writer.AddDivider('-'); @@ -68,5 +96,6 @@ _writer.AddText(contents); } + } } Modified: trunk/Source/StructureMap/IContainer.cs =================================================================== --- trunk/Source/StructureMap/IContainer.cs 2008-06-16 02:12:53 UTC (rev 123) +++ trunk/Source/StructureMap/IContainer.cs 2008-06-19 03:10:34 UTC (rev 124) @@ -66,5 +66,6 @@ ExplicitArgsExpression With<T>(T arg); IExplicitProperty With(string argName); + void AssertConfigurationIsValid(); } } \ No newline at end of file Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-06-16 02:12:53 UTC (rev 123) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-06-19 03:10:34 UTC (rev 124) @@ -339,7 +339,10 @@ return manager.With(argName); } - + public static void AssertConfigurationIsValid() + { + manager.AssertConfigurationIsValid(); + } } Modified: trunk/Source/StructureMap/Pipeline/Instance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Instance.cs 2008-06-16 02:12:53 UTC (rev 123) +++ trunk/Source/StructureMap/Pipeline/Instance.cs 2008-06-19 03:10:34 UTC (rev 124) @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using StructureMap.Configuration.DSL; using StructureMap.Diagnostics; using StructureMap.Graph; using StructureMap.Interceptors; @@ -164,4 +166,5 @@ return thisInstance; } } + } \ No newline at end of file Modified: trunk/Source/StructureMap/PipelineGraph.cs =================================================================== --- trunk/Source/StructureMap/PipelineGraph.cs 2008-06-16 02:12:53 UTC (rev 123) +++ trunk/Source/StructureMap/PipelineGraph.cs 2008-06-19 03:10:34 UTC (rev 124) @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using StructureMap.Diagnostics; using StructureMap.Graph; using StructureMap.Pipeline; @@ -24,9 +25,12 @@ private MissingFactoryFunction _missingFactory = (pluginType, profileManager) => null; + private GraphLog _log; + public PipelineGraph(PluginGraph graph) { _profileManager = graph.ProfileManager; + _log = graph.Log; foreach (PluginFamily family in graph.PluginFamilies) { @@ -42,6 +46,11 @@ } } + public GraphLog Log + { + get { return _log; } + } + public void ImportFrom(PluginGraph graph) { foreach (PluginFamily family in graph.PluginFamilies) @@ -80,6 +89,8 @@ visitor.PluginType(pluginType, defaultInstance); pair.Value.ForEachInstance(instance => visitor.Instance(pluginType, instance)); } + + } // Useful for the validation logic Modified: trunk/bin/Rhino.Mocks.dll =================================================================== (Binary files differ) Modified: trunk/bin/nant/NAnt.CompressionTasks.dll =================================================================== (Binary files differ) Modified: trunk/bin/nant/NAnt.CompressionTasks.xml =================================================================== --- trunk/bin/nant/NAnt.CompressionTasks.xml 2008-06-16 02:12:53 UTC (rev 123) +++ trunk/bin/nant/NAnt.CompressionTasks.xml 2008-06-19 03:10:34 UTC (rev 124) @@ -109,7 +109,10 @@ Extracts files from a zip file. </summary> <remarks> - <para>Uses <see href="http://www.icsharpcode.net/OpenSource/SharpZipLib/">#ziplib</see> (SharpZipLib), an open source Zip/GZip library written entirely in C#.</para> + <para> + Uses <see href="http://www.icsharpcode.net/OpenSource/SharpZipLib/">#ziplib</see> + (SharpZipLib), an open source Zip/GZip library written entirely in C#. + </para> </remarks> <example> <para>Extracts all the file from the zip, preserving the directory structure.</para> @@ -125,13 +128,14 @@ Extracts the files from the zip file. </summary> </member> - <member name="M:NAnt.Compression.Tasks.UnZipTask.ExtractFile(System.IO.Stream,System.String,System.DateTime)"> + <member name="M:NAnt.Compression.Tasks.UnZipTask.ExtractFile(System.IO.Stream,System.String,System.DateTime,System.Int64)"> <summary> Extracts a file entry from the specified stream. </summary> <param name="inputStream">The <see cref="T:System.IO.Stream"/> containing the compressed entry.</param> <param name="entryName">The name of the entry including directory information.</param> <param name="entryDate">The date of the entry.</param> + <param name="entrySize">The uncompressed size of the entry.</param> <exception cref="T:NAnt.Core.BuildException"> <para>The destination directory for the entry could not be created.</para> <para>-or-</para> @@ -171,12 +175,21 @@ entries in the archive. The default is <see langword="true" />. </summary> </member> + <member name="P:NAnt.Compression.Tasks.UnZipTask.Encoding"> + <summary> + The character encoding that has been used for filenames inside the + zip file. The default is the system's OEM code page. + </summary> + </member> <member name="T:NAnt.Compression.Tasks.ZipTask"> <summary> Creates a zip file from the specified filesets. </summary> <remarks> - <para>Uses <see href="http://www.icsharpcode.net/OpenSource/SharpZipLib/">#ziplib</see> (SharpZipLib), an open source Tar/Zip/GZip library written entirely in C#.</para> + <para> + Uses <see href="http://www.icsharpcode.net/OpenSource/SharpZipLib/">#ziplib</see> + (SharpZipLib), an open source Tar/Zip/GZip library written entirely in C#. + </para> </remarks> <example> <para> @@ -234,6 +247,38 @@ The set of files to be included in the archive. </summary> </member> + <member name="P:NAnt.Compression.Tasks.ZipTask.DuplicateHandling"> + <summary> + Specifies the behaviour when a duplicate file is found. The default + is <see cref="F:NAnt.Compression.Types.DuplicateHandling.Add"/>. + </summary> + </member> + <member name="P:NAnt.Compression.Tasks.ZipTask.Encoding"> + <summary> + The character encoding to use for filenames and comment inside the + zip file. The default is the system's OEM code page. + </summary> + </member> + <member name="T:NAnt.Compression.Types.DuplicateHandling"> + <summary> + Specifies how entries with the same name should be processed. + </summary> + </member> + <member name="F:NAnt.Compression.Types.DuplicateHandling.Add"> + <summary> + Overwrite existing entry with same name. + </summary> + </member> + <member name="F:NAnt.Compression.Types.DuplicateHandling.Preserve"> + <summary> + Preserve existing entry with the same name. + </summary> + </member> + <member name="F:NAnt.Compression.Types.DuplicateHandling.Fail"> + <summary> + Report failure when two entries have the same name. + </summary> + </member> <member name="T:NAnt.Compression.Types.TarFileSet"> <summary> A <see cref="T:NAnt.Compression.Types.TarFileSet"/> is a <see cref="T:NAnt.Core.Types.FileSet"/> with extra Modified: trunk/bin/nant/NAnt.Core.dll =================================================================== (Binary files differ) Modified: trunk/bin/nant/NAnt.Core.xml =================================================================== --- trunk/bin/nant/NAnt.Core.xml 2008-06-16 02:12:53 UTC (rev 123) +++ trunk/bin/nant/NAnt.Core.xml 2008-06-19 03:10:34 UTC (rev 124) @@ -161,10 +161,6 @@ </summary> <remarks> <para> - Should only be applied to properties exposing strongly typed arrays or - strongly typed collections. - </para> - <para> The XML format is like this: <code> <![CDATA[ @@ -562,6 +558,19 @@ <summary> Indicates the location that a task executable can be located in. </summary> + <remarks> + <para> + When applied to a task deriving from <see cref="T:NAnt.Core.Tasks.ExternalProgramBase"/>, + the program to execute will first be searched for in the designated + location. + </para> + <para> + If the program does not exist in that location, and the file name is + not an absolute path then the list of tool paths of the current + target framework will be searched (in the order in which they are + defined in the NAnt configuration file). + </para> + </remarks> </member> <member name="M:NAnt.Core.Attributes.ProgramLocationAttribute.#ctor(NAnt.Core.Attributes.LocationType)"> <summary> @@ -651,7 +660,7 @@ </code> NOTE: Attribute values must be of type of string if you want to be able to have macros. The field stores the exact value during - InitializeTask. Just before ExecuteTask is called NAnt will expand + Initialize. Just before ExecuteTask is called NAnt will expand all the macros with the current values. </example> </member> @@ -683,17 +692,13 @@ <exception cref="T:System.ArgumentNullException"><paramref name="name"/> is <see langword="null"/>.</exception> <exception cref="T:System.ArgumentOutOfRangeException"><paramref name="name"/> is a zero-length <see cref="T:System.String"/>.</exception> </member> - <member name="T:NAnt.Core.Filters.ChainableReader"> + <member name="T:NAnt.Core.Configuration.DirList"> <summary> - Functions as a chainable TextReader + Represents an explicitly named list of directories. </summary> <remarks> - Implements a abstraction over a TextReader that allows the class to represent - either a TextReader or another ChainableReader to which it is chained. - - By passing a ChainableReader as a constructor paramater it is possiable to - chain many ChainableReaders together. The last ChainableReader in the chain must - be based on a TextReader. + A <see cref="T:NAnt.Core.Configuration.DirList"/> is useful when you want to capture a list of + directories regardless whether they currently exist. </remarks> </member> <member name="T:NAnt.Core.Element"> @@ -725,7 +730,7 @@ </summary> <remarks> Derived classes that wish to add custom initialization should override - the <see cref="M:NAnt.Core.Element.InitializeElement(System.Xml.XmlNode)"/> method. + the <see cref="M:NAnt.Core.Element.Initialize"/> method. </remarks> </member> <member name="M:NAnt.Core.Element.Log(NAnt.Core.Level,System.String)"> @@ -756,6 +761,16 @@ </summary> <param name="elementNode">The XML node of the element to use for initialization.</param> </member> + <member name="M:NAnt.Core.Element.Initialize"> + <summary> + Derived classes should override to this method to provide extra + initialization and validation not covered by the base class. + </summary> + <remarks> + Access to the <see cref="P:NAnt.Core.Element.XmlNode"/> that was used to initialize + this <see cref="T:NAnt.Core.Element"/> is available through <see cref="P:NAnt.Core.Element.XmlNode"/>. + </remarks> + </member> <member name="M:NAnt.Core.Element.CopyTo(NAnt.Core.Element)"> <summary> Copies all instance data of the <see cref="T:NAnt.Core.Element"/> to a given @@ -998,6 +1013,116 @@ Internal interface used for setting element attributes. </summary> </member> + <member name="P:NAnt.Core.Configuration.DirList.Directory"> + <summary> + The base of the directory of this dirlist. The default is the project + base directory. + </summary> + </member> + <member name="P:NAnt.Core.Configuration.ManagedExecutionMode.Environment"> + <summary> + Gets the collection of environment variables that should be passed + to external programs that are launched. + </summary> + <value> + <summary> + The collection of environment variables that should be passed + to external programs that are launched. + </summary> + </value> + </member> + <member name="P:NAnt.Core.Configuration.RuntimeEngine.Arguments"> + <summary> + The command-line arguments for the runtime engine. + </summary> + </member> + <member name="T:NAnt.Core.Extensibility.ExtensionAssembly"> + <summary> + Represents an <see cref="P:NAnt.Core.Extensibility.ExtensionAssembly.Assembly"/> in which one or more extensions + are found. + </summary> + </member> + <member name="M:NAnt.Core.Extensibility.ExtensionAssembly.#ctor(System.Reflection.Assembly)"> + <summary> + Initializes a new instance of the <see cref="T:NAnt.Core.Extensibility.ExtensionAssembly"/> + class for a given <see cref="P:NAnt.Core.Extensibility.ExtensionAssembly.Assembly"/>. + </summary> + <param name="assembly">The <see cref="P:NAnt.Core.Extensibility.ExtensionAssembly.Assembly"/> for which to construct an <see cref="T:NAnt.Core.Extensibility.ExtensionAssembly"/>.</param> + </member> + <member name="P:NAnt.Core.Extensibility.ExtensionAssembly.Assembly"> + <summary> + Gets the <see cref="P:NAnt.Core.Extensibility.ExtensionAssembly.Assembly"/> containing extensions. + </summary> + </member> + <member name="M:NAnt.Core.Extensibility.ExtensionBuilder.#ctor(NAnt.Core.Extensibility.ExtensionAssembly)"> + <summary> + Initializes a instance of the <see cref="T:NAnt.Core.Extensibility.ExtensionBuilder"/> + class for an extension in a given <see cref="P:NAnt.Core.Extensibility.ExtensionBuilder.ExtensionAssembly"/>. + </summary> + <param name="extensionAssembly">The <see cref="P:NAnt.Core.Extensibility.ExtensionBuilder.ExtensionAssembly"/> in which the extension is found.</param> + <exception cref="T:System.ArgumentNullException"><paramref name="extensionAssembly"/> is <see langword="null"/>.</exception> + </member> + <member name="P:NAnt.Core.Extensibility.ExtensionBuilder.ExtensionAssembly"> + <summary> + Gets the <see cref="P:NAnt.Core.Extensibility.ExtensionBuilder.ExtensionAssembly"/> in which the extension + was found. + </summary> + </member> + <member name="P:NAnt.Core.Extensibility.ExtensionBuilder.Assembly"> + <summary> + Gets the <see cref="P:NAnt.Core.Extensibility.ExtensionBuilder.Assembly"/> from which the extension will + be created. + </summary> + <value> + The <see cref="P:NAnt.Core.Extensibility.ExtensionBuilder.Assembly"/> containing the extension. + </value> + </member> + <member name="M:NAnt.Core.Extensibility.PluginConsumerAttribute.#ctor(System.Type)"> + <summary> + Initializes a new instance of the <see cref="T:NAnt.Core.Extensibility.PluginConsumerAttribute"/> + with the specified type. + </summary> + <param name="type">The type of the <see cref="T:NAnt.Core.Extensibility.IPlugin"/> to consume.</param> + <exception cref="T:System.ArgumentNullException"><paramref name="type"/> is <see langword="null"/>.</exception> + </member> + <member name="T:NAnt.Core.Extensibility.PluginScanner"> + <summary> + Responsible for scanning types for plugins, and maintaining a cache of + <see cref="T:NAnt.Core.Extensibility.PluginBuilder"/> instances. + </summary> + </member> + <member name="M:NAnt.Core.Extensibility.PluginScanner.ScanTypeForPlugins(NAnt.Core.Extensibility.ExtensionAssembly,System.Type,NAnt.Core.Task)"> + <summary> + Scans a given <see cref="T:System.Type"/> for plugins. + </summary> + <param name="extensionAssembly">The <see cref="T:NAnt.Core.Extensibility.ExtensionAssembly"/> containing the <see cref="T:System.Type"/> to scan.</param> + <param name="type">The <see cref="T:System.Type"/> to scan.</param> + <param name="task">The <see cref="T:NAnt.Core.Task"/> which will be used to output messages to the build log.</param> + <returns> + <see langword="true"/> if <paramref name="type"/> represents a + <see cref="T:NAnt.Core.Extensibility.IPlugin"/>; otherwise, <see langword="false"/>. + </returns> + </member> + <member name="M:NAnt.Core.Extensibility.PluginScanner.RegisterPlugins(NAnt.Core.Extensibility.IPluginConsumer)"> + <summary> + Registers matching plugins for the specified <see cref="T:NAnt.Core.Extensibility.IPluginConsumer"/>. + </summary> + <param name="consumer">The <see cref="T:NAnt.Core.Extensibility.IPluginConsumer"/> which plugins must be registered for.</param> + <exception cref="T:System.ArgumentNullException"><paramref name="consumer"/> is <see langword="null"/>.</exception> + </member> + <member name="T:NAnt.Core.Filters.ChainableReader"> + <summary> + Functions as a chainable TextReader + </summary> + <remarks> + Implements a abstraction over a TextReader that allows the class to represent + either a TextReader or another ChainableReader to which it is chained. + + By passing a ChainableReader as a constructor paramater it is possiable to + chain many ChainableReaders together. The last ChainableReader in the chain must + be based on a TextReader. + </remarks> + </member> <member name="M:NAnt.Core.Filters.ChainableReader.Chain(NAnt.Core.Filters.ChainableReader)"> <summary> Makes it so all calls to Read and Peek are passed the ChainableReader @@ -1070,21 +1195,35 @@ is <see langword="false"/>. </summary> </member> - <member name="M:NAnt.Core.Filters.FilterBuilder.#ctor(System.String)"> + <member name="M:NAnt.Core.Filters.FilterBuilder.#ctor(NAnt.Core.Extensibility.ExtensionAssembly,System.String)"> <summary> Creates a new instance of the <see cref="T:NAnt.Core.Filters.FilterBuilder"/> class - for the specified Element class. + for the specified <see cref="T:NAnt.Core.Filters.Filter"/> class in the specified + <see cref="T:NAnt.Core.Extensibility.ExtensionAssembly"/>. </summary> - <param name="className">The class representing the Element.</param> + <param name="extensionAssembly">The <see cref="T:NAnt.Core.Extensibility.ExtensionAssembly"/> containing the <see cref="T:NAnt.Core.Filters.Filter"/>.</param> + <param name="className">The class representing the <see cref="T:NAnt.Core.Filters.Filter"/>.</param> </member> - <member name="M:NAnt.Core.Filters.FilterBuilder.#ctor(System.String,System.String)"> + <member name="P:NAnt.Core.Filters.FilterBuilder.ClassName"> <summary> - Creates a new instance of the <see cref="T:NAnt.Core.Filters.FilterBuilder"/> class - for the specified Element class in the assembly specified. + Gets the name of the <see cref="T:NAnt.Core.Filters.Filter"/> class that can be created + using this <see cref="T:NAnt.Core.Filters.FilterBuilder"/>. </summary> - <param name="className">The class representing the Element.</param> - <param name="assemblyFileName">The assembly containing the Element.</param>/// + <value> + The name of the <see cref="T:NAnt.Core.Filters.Filter"/> class that can be created using + this <see cref="T:NAnt.Core.Filters.FilterBuilder"/>. + </value> </member> + <member name="P:NAnt.Core.Filters.FilterBuilder.FilterName"> + <summary> + Gets the name of the filter which the <see cref="T:NAnt.Core.Filters.FilterBuilder"/> + can create. + </summary> + <value> + The name of the task which the <see cref="T:NAnt.Core.TaskBuilder"/> can + create. + </value> + </member> <member name="T:NAnt.Core.Filters.FilterBuilderCollection"> <summary> Contains a strongly typed collection of <see cref="T:NAnt.Core.Filters.FilterBuilder"/> objects. @@ -1307,13 +1446,13 @@ </summary> </member> <member name="P:NAnt.Core.DataTypeBase.ID"> - <summary> - The ID used to be referenced later. + <summary> + The ID used to be referenced later. </summary> </member> <member name="P:NAnt.Core.DataTypeBase.RefID"> - <summary> - The ID to use as the reference. + <summary> + The ID to use as the reference. </summary> </member> <member name="P:NAnt.Core.DataTypeBase.CanBeReferenced"> @@ -1715,8 +1854,8 @@ </para> <para> Tokens are specified by using the <see cref="T:NAnt.Core.Types.Token"/> element. It is - possoble to specify from 1 to n tokens and replacement values. Values can - be any valid NAnt expression + possible to specify from 1 to n tokens and replacement values. Values can + be any valid NAnt expression. </para> <para> Filters are intended to be used as a element of a <see cref="T:NAnt.Core.Filters.FilterChain"/>. @@ -1773,7 +1912,7 @@ Char as an int or -1 if at the end of the stream. </returns> </member> - <member name="M:NAnt.Core.Filters.ReplaceTokens.InitializeElement(System.Xml.XmlNode)"> + <member name="M:NAnt.Core.Filters.ReplaceTokens.Initialize"> <summary> Initialize the filter by setting its parameters. </summary> @@ -1798,11 +1937,12 @@ </member> <member name="M:NAnt.Core.Filters.ReplaceTokens.CompareCharacters(System.Int32,System.Int32)"> <summary> - Compares to characters taking into account the _ignoreCase flag. + Compares to characters taking <see cref="P:NAnt.Core.Filters.ReplaceTokens.IgnoreCase"/> into account. </summary> <param name="char1"></param> <param name="char2"></param> - <returns></returns> + <returns> + </returns> </member> <member name="P:NAnt.Core.Filters.ReplaceTokens.BeginToken"> <summary> @@ -1920,6 +2060,30 @@ <exception cref="T:System.BadImageFormatException"><paramref name="assemblyFile"/> is not a valid assembly.</exception> <exception cref="T:System.IO.PathTooLongException">An assembly or module was loaded twice with two different evidences, or the assembly name is longer than MAX_PATH characters.</exception> </member> + <member name="M:NAnt.Core.Functions.AssemblyFunctions.Load(System.String)"> + <summary> + Loads an assembly given the long form of its name. + </summary> + <param name="assemblyString">The long form of the assembly name.</param> + <returns> + The loaded assembly. + </returns> + <exception cref="T:System.ArgumentNullException"><paramref name="assemblyString"/> is a <see langword="null"/>.</exception> + <exception cref="T:System.IO.FileNotFoundException"><paramref name="assemblyString"/> is not found.</exception> + <example> + <para> + Determine the location of the Microsoft Access 11 Primary Interop + Assembly by loading it using its fully qualified name, and copy it + to the build directory. + </para> + <code> + <![CDATA[ + <property name="access.pia.path" value="${assembly::get-location(assembly::load('Microsoft.Office.Interop.Access, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'))}" /> + <copy file="${access.pia.path}" todir="${build.dir}" /> + ]]> + </code> + </example> + </member> <member name="M:NAnt.Core.Functions.AssemblyFunctions.GetFullName(System.Reflection.Assembly)"> <summary> Gets the full name of the assembly, also known as the display name. @@ -1982,6 +2146,17 @@ <returns> The full name of the assembly, also known as the display name. </returns> + <example> + <para> + Output the full name of the <c>nunit.framework</c> assembly to the + build log. + </para> + <code> + <![CDATA[ + <echo message="${assemblyname::get-full-name(assemblyname::get-assembly-name('nunit.framework.dll'))}" /> + ]]> + </code> + </example> <seealso cref="M:NAnt.Core.Functions.AssemblyFunctions.GetName(System.Reflection.Assembly)"/> </member> <member name="M:NAnt.Core.Functions.AssemblyNameFunctions.GetName(System.Reflection.AssemblyName)"> @@ -1992,6 +2167,17 @@ <returns> The simple, unencrypted name of the assembly. </returns> + <example> + <para> + Output the simple name of the <c>nunit.framework</c> assembly to + the build log. + </para> + <code> + <![CDATA[ + <echo message="${assemblyname::get-name(assemblyname::get-assembly-name('nunit.framework.dll'))}" /> + ]]> + </code> + </example> <seealso cref="M:NAnt.Core.Functions.AssemblyFunctions.GetName(System.Reflection.Assembly)"/> </member> <member name="M:NAnt.Core.Functions.AssemblyNameFunctions.GetVersion(System.Reflection.AssemblyName)"> @@ -2002,6 +2188,17 @@ <returns> The version of the assembly. </returns> + <example> + <para> + Output the major version of the <c>nunit.framework</c> assembly + to the build log. + </para> + <code> + <![CDATA[ + <echo message="${version::get-major-version(assemblyname::get-version(assemblyname::get-assembly-name('nunit.framework.dll')))}" /> + ]]> + </code> + </example> <seealso cref="M:NAnt.Core.Functions.AssemblyFunctions.GetName(System.Reflection.Assembly)"/> <seealso cref="T:NAnt.Core.Functions.VersionFunctions"/> </member> @@ -2019,6 +2216,17 @@ <remarks> The assembly is not added to this domain. </remarks> + <example> + <para> + Output the full name of the <c>nunit.framework</c> assembly to the + build log. + </para> + <code> + <![CDATA[ + <echo message="${assemblyname::get-full-name(assemblyname::get-assembly-name('nunit.framework.dll'))}" /> + ]]> + </code> + </example> </member> <member name="M:NAnt.Core.Functions.BooleanConversionFunctions.Parse(System.String)"> <summary> @@ -2243,6 +2451,11 @@ <see cref="T:System.Globalization.DateTimeFormatInfo"/> for the invariant culture. </remarks> </member> + <member name="T:NAnt.Core.Functions.DirectoryFunctions"> + <summary> + Groups a set of functions for dealing with directories. + </summary> + </member> <member name="M:NAnt.Core.Functions.DirectoryFunctions.GetCreationTime(System.String)"> <summary> Returns the creation date and time of the specified directory. @@ -2255,15 +2468,6 @@ <exception cref="T:System.ArgumentException"><paramref name="path"/> is a zero-length string, contains only white space, or contains one or more invalid characters.</exception> <exception cref="T:System.IO.PathTooLongException">The specified path, file name, or both exceed the system-defined maximum length.</exception> </member> - <member name="M:NAnt.Core.Functions.DirectoryFunctions.GetCurrentDirectory"> - <summary> - Gets the current working directory. - </summary> - <returns> - A <see cref="T:System.String"/> containing the path of the current working - directory. - </returns> - </member> <member name="M:NAnt.Core.Functions.DirectoryFunctions.GetLastWriteTime(System.String)"> <summary> Returns the date and time the specified directory was last written to. @@ -2289,6 +2493,15 @@ <exception cref="T:System.IO.PathTooLongException">The specified path, file name, or both exceed the system-defined maximum length.</exception> <exception cref="T:System.NotSupportedException">The <paramref name="path"/> parameter is in an invalid format.</exception> </member> + <member name="M:NAnt.Core.Functions.DirectoryFunctions.GetCurrentDirectory"> + <summary> + Gets the current working directory. + </summary> + <returns> + A <see cref="T:System.String"/> containing the path of the current working + directory. + </returns> + </member> <member name="M:NAnt.Core.Functions.DirectoryFunctions.GetParentDirectory(System.String)"> <summary> Retrieves the parent directory of the specified path. @@ -2349,6 +2562,20 @@ </code> </example> </member> + <member name="T:NAnt.Core.Functions.DnsFunctions"> + <summary> + Functions for requesting information from DNS. + </summary> + </member> + <member name="M:NAnt.Core.Functions.DnsFunctions.GetHostName"> + <summary> + Gets the host name of the local computer. + </summary> + <returns> + A string that contains the DNS host name of the local computer. + </returns> + <exception cref="T:System.Net.Sockets.SocketException">An error is encountered when resolving the local host name.</exception> + </member> <member name="M:NAnt.Core.Functions.DoubleConversionFunctions.Parse(System.String)"> <summary> Converts the specified string representation of a number to its @@ -2517,6 +2744,11 @@ </code> </example> </member> + <member name="T:NAnt.Core.Functions.FileFunctions"> + <summary> + Groups a set of functions for dealing with files. + </summary> + </member> <member name="M:NAnt.Core.Functions.FileFunctions.GetCreationTime(System.String)"> <summary> Returns the creation date and time of the specified file. @@ -2610,7 +2842,6 @@ <exception cref="T:System.ArgumentException"><paramref name="assemblyFile"/> is an empty <see cref="T:System.String"/>.</exception> <exception cref="T:System.IO.FileNotFoundException"><paramref name="assemblyFile"/> is not found, or the file you are trying to check does not specify a filename extension.</exception> <exception cref="T:System.Security.SecurityException">The caller does not have path discovery permission.</exception> - <exception cref="T:System.IO.FileLoadException">The file could not be loaded for some reason.</exception> </member> <member name="T:NAnt.Core.Functions.FileVersionInfoFunctions"> <summary> @@ -2841,6 +3072,18 @@ <see langword="true" /> if the specified target exists; otherwise, <see langword="false" />. </returns> + <example> + <para> + Execute target "clean", if it exists. + </para> + <code> + <![CDATA[ + <if test="${target::exists('clean')}"> + <call target="clean" /> + </if> + ]]> + </code> + </example> </member> <member name="M:NAnt.Core.Functions.TargetFunctions.GetCurrentTarget"> <summary> @@ -2873,15 +3116,14 @@ <see langword="false" />. </returns> </member> - <member name="M:NAnt.Core.Functions.TaskFunctions.GetLocation(System.String)"> + <member name="M:NAnt.Core.Functions.TaskFunctions.GetAssembly(System.String)"> <summary> - Returns the filename of the assembly from which the specified task + Returns the <see cref="T:System.Reflection.Assembly"/> from which the specified task was loaded. </summary> - <param name="name">The task to get the location of.</param> + <param name="name">The name of the task to get the <see cref="T:System.Reflection.Assembly"/> of.</param> <returns> - The filename of the assembly from which the specified task was - loaded. + The <see cref="T:System.Reflection.Assembly"/> from which the specified task was loaded. </returns> <exception cref="T:System.ArgumentException">Task <paramref name="name"/> is not available.</exception> </member> @@ -2895,8 +3137,19 @@ <see langword="false" />. </returns> <example> - <para>Check whether the "debug" property exists.</para> - <code>property::exists('debug')</code> + <para> + Execute a set of tasks if the "build.debug" property + exists. + </para> + <code> + <![CDATA[ + <if test="${property::exists('build.debug')}"> + <echo message="Starting debug build" /> + <call target="init-debug" /> + <call target="build" /> + </if> + ]]> + </code> </example> </member> <member name="M:NAnt.Core.Functions.PropertyFunctions.IsReadOnly(System.String)"> @@ -2933,11 +3186,11 @@ </member> <member name="M:NAnt.Core.Functions.FrameworkFunctions.Exists(System.String)"> <summary> - Checks whether the specified framework exists. + Checks whether the specified framework exists, and is valid. </summary> - <param name="name">The framework to test.</param> + <param name="framework">The framework to test.</param> <returns> - <see langword="true" /> if the specified framework exists; otherwise, + <see langword="true" /> if the specified framework exists ; otherwise, <see langword="false" />. </returns> </member> @@ -2945,7 +3198,7 @@ <summary> Checks whether the SDK for the specified framework is installed. </summary> - <param name="name">The framework to test.</param> + <param name="framework">The framework to test.</param> <returns> <see langword="true"/> if the SDK for specified framework is installed; otherwise, <see langword="false"/>. @@ -3055,6 +3308,38 @@ <seealso cref="M:NAnt.Core.Functions.FrameworkFunctions.GetRuntimeFramework"/> <seealso cref="M:NAnt.Core.Functions.FrameworkFunctions.GetTargetFramework"/> </member> + <member name="M:NAnt.Core.Functions.FrameworkFunctions.GetToolPath(System.String)"> + <summary> + Gets the absolute path of the specified tool for the current + target framework. + </summary> + <param name="tool">The file name of the tool to search for.</param> + <returns> + The absolute path to <paramref name="tool"/> if found in one of the + configured tool paths; otherwise, an error is reported. + </returns> + <exception cref="T:System.IO.FileNotFoundException"><paramref name="tool"/> could not be found in the configured tool paths.</exception> + <remarks> + <para> + The configured tool paths are scanned in the order in which they + are defined in the framework configuration. + </para> + <para> + The file name of the tool to search should include the extension. + </para> + </remarks> + <example> + <para>Use <b>gacutil</b> to install an assembly in the GAC.</para> + <code> + <![CDATA[ + <exec program="${framework::get-tool-path('gacutil.exe')}" managed="strict"> + <arg value="/i" /> + <arg file="Cegeka.HealthFramework.dll" /> + </exec> + ]]> + </code> + </example> + </member> <member name="M:NAnt.Core.Functions.FrameworkFunctions.GetRuntimeEngine(System.String)"> <summary> Gets the runtime engine of the specified framework. @@ -3069,7 +3354,7 @@ <seealso cref="M:NAnt.Core.Functions.FrameworkFunctions.GetRuntimeFramework"/> <seealso cref="M:NAnt.Core.Functions.FrameworkFunctions.GetTargetFramework"/> </member> - <member name="M:NAnt.Core.Functions.FrameworkFunctions.CheckFramework(System.String)"> + <member name="M:NAnt.Core.Functions.FrameworkFunctions.GetFramework(System.String)"> <summary> Checks whether the specified framework is valid. </summary> @@ -3735,13 +4020,13 @@ <code>string::last-index-of('testing string', 'test') ==> 0</code> </example> <example> - <code>string::last-index-of('testing string', '') ==> 0</code> + <code>string::last-index-of('testing string', '') ==> 13</code> </example> <example> <code>string::last-index-of('testing string', 'Test') ==> -1</code> </example> <example> - <code>string::last-index-of('testing string', 'ing') ==> 4</code> + <code>string::last-index-of('testing string', 'ing') ==> 11</code> </example> </member> <member name="M:NAnt.Core.Functions.StringFunctions.PadLeft(System.String,System.Int32,System.String)"> @@ -3917,6 +4202,19 @@ The number of whole days represented by the given <see cref="T:System.TimeSpan"/>. </returns> + <example> + <para> + Remove all files that have not been modified in the last 7 days from directory "binaries".</para> + <code> + <![CDATA[ + <foreach item="File" in="binaries" property="filename"> + <if test="${timespan::get-days(datetime::now() - file::get-last-write-time(filename)) >= 7}"> + <delete file="${filename}" /> + </if> + </foreach> + ]]> + </code> + </example> </member> <member name="M:NAnt.Core.Functions.TimeSpanFunctions.GetHours(System.TimeSpan)"> <summary> @@ -4211,9 +4509,9 @@ The actual logging is delegated to the project. </para> <para> - If the <see cref="P:NAnt.Core.Task.Verbose"/> attribute is set on the task and a - message is logged with level <see cref="F:NAnt.Core.Level.Verbose"/>, the - priority of the message will be increased to <see cref="F:NAnt.Core.Level.Info"/>. + If the <see cref="P:NAnt.Core.Task.Verbose"/> attribute is set on the task and a + message is logged with level <see cref="F:NAnt.Core.Level.Verbose"/>, the + priority of the message will be increased to <see cref="F:NAnt.Core.Level.Info"/> when the threshold of the build log is <see cref="F:NAnt.Core.Level.Info"/>. </para> <para> @@ -4221,6 +4519,11 @@ the build log itself is still configured with threshold <see cref="F:NAnt.Core.Level.Info"/>. </para> + <para> + The threshold of the project is not taken into account to determine + whether a message should be passed to the logging infrastructure, + as build listeners might be interested in receiving all messages. + </para> </remarks> </member> <member name="M:NAnt.Core.Task.Log(NAnt.Core.Level,System.String,System.Object[])"> @@ -4255,8 +4558,14 @@ <param name="messageLevel">The <see cref="T:NAnt.Core.Level"/> to check.</param> <returns> <see langword="true"/> if messages with the given <see cref="T:NAnt.Core.Level"/> - will be output in the build log; otherwise, <see langword="false"/>. + should be passed on to the logging infrastructure; otherwise, + <see langword="false"/>. </returns> + <remarks> + The threshold of the project is not taken into account to determine + whether a message should be passed to the logging infrastructure, + as build listeners might be interested in receiving all messages. + </remarks> </member> <member name="M:NAnt.Core.Task.InitializeTaskConfiguration"> <summary> @@ -4269,8 +4578,8 @@ file if a build element is constructed from code. </remarks> </member> - <member name="M:NAnt.Core.Task.InitializeElement(System.Xml.XmlNode)"> - <summary><note>Deprecated (to be deleted).</note></summary> + <member name="M:NAnt.Core.Task.Initialize"> + <summary>Initializes the task.</summary> </member> <member name="M:NAnt.Core.Task.InitializeTask(System.Xml.XmlNode)"> <summary>Initializes the task.</summary> @@ -4278,6 +4587,25 @@ <member name="M:NAnt.Core.Task.ExecuteTask"> <summary>Executes the task.</summary> </member> + <member name="M:NAnt.Core.Task.GetAttributeConfigurationNode(NAnt.Core.FrameworkInfo,System.String)"> + <summary> + Locates the XML node for the specified attribute in either the + configuration section of the extension assembly or the.project. + </summary> + <param name="attributeName">The name of attribute for which the XML configuration node should be located.</param> + <param name="framework">The framework to use to obtain framework specific information, or <see langword="null" /> if no framework specific information should be used.</param> + <returns> + The XML configuration node for the specified attribute, or + <see langword="null" /> if no corresponding XML node could be + located. + </returns> + <remarks> + If there's a valid current framework, the configuration section for + that framework will first be searched. If no corresponding + configuration node can be located in that section, the framework-neutral + section of the project configuration node will be searched. + </remarks> + </member> <member name="P:NAnt.Core.Task.FailOnError"> <summary> Determines if task failure stops the build, or is just reported. @@ -4316,17 +4644,24 @@ <member name="P:NAnt.Core.Task.Threshold"> <summary> Gets or sets the log threshold for this <see cref="T:NAnt.Core.Task"/>. By - default the threshold of a task matches the threshold of the project. + default the threshold of a task is <see cref="F:NAnt.Core.Level.Debug"/>, + causing no messages to be filtered in the task itself. </summary> <value> The log threshold level for this <see cref="T:NAnt.Core.Task"/>. </value> <remarks> - Setting the threshold of a <see cref="T:NAnt.Core.Task"/> higher than the - threshold of the its <see cref="T:NAnt.Core.Project"/> does not have any - effect. + When the threshold of a <see cref="T:NAnt.Core.Task"/> is higher than the + threshold of the <see cref="T:NAnt.Core.Project"/>, then all messages will + still be delivered to the build listeners. </remarks> </member> + <member name="P:NAnt.Core.Task.TaskBuilder"> + <summary> + Returns the TaskBuilder used to construct an instance of this + <see cref="T:NAnt.Core.Task"/>. + </summary> + </member> <member name="P:NAnt.Core.Tasks.AttribTask.File"> <summary> The name of the file which will have its attributes set. This is @@ -4561,10 +4896,23 @@ target and all its dependent targets will be re-executed. </para> <para> - To avoid dependent targets from being executed more than once, an "unless" - attribute with value "${<see href="../functions/target.has-executed.html">target::has-executed</see>('<c><target name></c>')}" - should be added to the dependent targets. + To avoid dependent targets from being executed more than once, two + options are available: </para> + <list type="bullet"> + <item> + <description> + Add an "unless" attribute with value "${<see href="../functions/target.has-executed.html">target::has-executed</see>('<c><target name></c>')}" + to the dependent targets. + </description> + </item> + <item> + <description> + Set the <see cref="P:NAnt.Core.Tasks.CallTask.CascadeDependencies"/> attribute on the + <see cref="T:NAnt.Core.Tasks.CallTask"/> to <see langword="false "/> (<c>recommended</c>). + </description> + </item> + </list> </remarks> <example> <para> @@ -4585,7 +4933,7 @@ <![CDATA[ <project default="build"> <property name="debug" value="false" /> - <target name="init" unless="${target::has-executed('init')}"> + <target name="init"> <echo message="initializing" /> </target> <target name="compile" depends="init"> @@ -4600,6 +4948,61 @@ </project> ]]> </code> + <para> + The <see cref="P:NAnt.Core.Tasks.CallTask.CascadeDependencies"/> parameter of the + <see cref="T:NAnt.Core.Tasks.CallTask"/> defaults to <see langword="true"/>, + causing the "init" target to be executed for both + the "debug" and "release" build. + </para> + <para> + This results in the following build log: + </para> + <code> + build: + + init: + + [echo] initializing + + compile: + + [echo] compiling with debug = false + + init: + + [echo] initializing + + compile: + + [echo] compiling with debug = true + + BUILD SUCCEEDED + </code> + <para> + If the "init" should only be executed once, set the + <see cref="P:NAnt.Core.Tasks.CallTask.CascadeDependencies"/> attribute of the <see cref="T:NAnt.Core.Tasks.CallTask"/> + to <see langword="false"/>. + </para> + <para> + The build log would then look like this: + </para> + <code> + build: + + init: + + [echo] initializing + + compile: + + [echo] compiling with debug = false + + compile: + + [echo] compiling with debug = true + + BUILD SUCCEEDED + </code> </example> </member> <member name="M:NAnt.Core.Tasks.CallTask.ExecuteTask"> @@ -4607,12 +5010,11 @@ Executes the specified target. </summary> </member> - <member name="M:NAnt.Core.Tasks.CallTask.InitializeTask(System.Xml.XmlNode)"> + <member name="M:NAnt.Core.Tasks.CallTask.Initialize"> <summary> Makes sure the <see cref="T:NAnt.Core.Tasks.CallTask"/> is not calling its own parent. </summary> - <param name="taskNode">The task XML node.</param> </member> <member name="P:NAnt.Core.Tasks.CallTask.TargetName"> <summary> @@ -4627,8 +5029,8 @@ </member> <member name="P:NAnt.Core.Tasks.CallTask.CascadeDependencies"> <summary> - Cascade all the specified targets dependencies. The - default is <see langword="true" />. + Execute the specified targets dependencies -- even if they have been + previously executed. The default is <see langword="true" />. </summary> </member> <member name="T:NAnt.Core.Tasks.CopyTask"> @@ -4724,11 +5126,10 @@ Initialize new instance of the <see cref="T:NAnt.Core.Tasks.CopyTask"/>. </summary> </member> - <member name="M:NAnt.Core.Tasks.CopyTask.InitializeTask(System.Xml.XmlNode)"> + <member name="M:NAnt.Core.Tasks.CopyTask.Initialize"> <summary> Checks whether the task is initialized with valid attributes. </summary> - <param name="taskNode">The <see ... [truncated message content] |
From: <jer...@us...> - 2008-06-16 02:12:57
|
Revision: 123 http://structuremap.svn.sourceforge.net/structuremap/?rev=123&view=rev Author: jeremydmiller Date: 2008-06-15 19:12:53 -0700 (Sun, 15 Jun 2008) Log Message: ----------- adding the ability to define IDictionary<T, U>, NameValueCollection, and primitive array arguments in the xml configuration Modified Paths: -------------- trunk/Source/StructureMap/Configuration/XmlExtensions.cs trunk/Source/StructureMap/Diagnostics/Error.cs trunk/Source/StructureMap/Graph/TypeRules.cs trunk/Source/StructureMap/InstanceMemento.cs trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs trunk/Source/StructureMap/Source/XmlAttributeInstanceMemento.cs trunk/Source/StructureMap/Source/XmlNodeInstanceMemento.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing/TestData/DataMother.cs Added Paths: ----------- trunk/Source/StructureMap/Configuration/DictionaryReader.cs trunk/Source/StructureMap/Configuration/ITypeReader.cs trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs trunk/Source/StructureMap/Configuration/TypeReaderFactory.cs trunk/Source/StructureMap.Testing/Configuration/DictionaryAndArrayArgumentTester.cs trunk/Source/StructureMap.Testing/Configuration/DictionaryReaderTester.cs trunk/Source/StructureMap.Testing/Configuration/PrimitiveArrayReaderTester.cs Added: trunk/Source/StructureMap/Configuration/DictionaryReader.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DictionaryReader.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DictionaryReader.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Xml; +using StructureMap.Pipeline; + +namespace StructureMap.Configuration +{ + public class DictionaryReader : ITypeReader + { + public bool CanProcess(Type pluginType) + { + if (pluginType.Equals(typeof(NameValueCollection))) return true; + if (!pluginType.IsGenericType) return false; + + var definition = pluginType.GetGenericTypeDefinition(); + if (definition == null) return false; + + return definition.Equals(typeof (IDictionary<,>)) || definition.Equals(typeof (Dictionary<,>)); + } + + private static IBuilder findBuilder(Type pluginType) + { + if (pluginType.Equals(typeof(NameValueCollection))) return new NameValueCollectionBuilder(); + + var definition = pluginType.GetGenericTypeDefinition(); + if (definition.Equals(typeof(IDictionary<,>)) || definition.Equals(typeof(Dictionary<,>))) + { + var arguments = pluginType.GetGenericArguments(); + var builderType = typeof (DictionaryBuilder<,>).MakeGenericType(arguments); + return (IBuilder) Activator.CreateInstance(builderType); + } + + return null; + } + + public Instance Read(XmlNode node, Type pluginType) + { + var builder = findBuilder(pluginType); + node.ForEachChild("Pair").Do(element => builder.Read(element.GetAttribute("Key"), element.GetAttribute("Value"))); + + return new SerializedInstance(builder.Object); + } + + + + + + + + + internal interface IBuilder + { + void Read(string name, string value); + object Object { get; } + } + + internal class NameValueCollectionBuilder : IBuilder + { + private readonly NameValueCollection _collection = new NameValueCollection(); + + public void Read(string name, string value) + { + _collection.Add(name, value); + } + + public object Object + { + get { return _collection; } + } + } + + internal class DictionaryBuilder<KEY, VALUE> : IBuilder + { + private Dictionary<KEY, VALUE> _dictionary = new Dictionary<KEY, VALUE>(); + + public void Read(string name, string value) + { + KEY key = (KEY) Convert.ChangeType(name, typeof (KEY)); + VALUE theValue = (VALUE) Convert.ChangeType(value, typeof (VALUE)); + + _dictionary.Add(key, theValue); + } + + public object Object + { + get { return _dictionary; } + } + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Configuration/ITypeReader.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ITypeReader.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/ITypeReader.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -0,0 +1,14 @@ +using System; +using System.Linq; +using System.Text; +using System.Xml; +using StructureMap.Pipeline; + +namespace StructureMap.Configuration +{ + public interface ITypeReader + { + bool CanProcess(Type pluginType); + Instance Read(XmlNode node, Type pluginType); + } +} Added: trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs =================================================================== --- trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -0,0 +1,38 @@ +using System; +using System.Xml; +using StructureMap.Graph; +using StructureMap.Pipeline; + +namespace StructureMap.Configuration +{ + public class PrimitiveArrayReader : TypeRules, ITypeReader + { + #region ITypeReader Members + + public bool CanProcess(Type pluginType) + { + return IsPrimitiveArray(pluginType); + } + + public Instance Read(XmlNode node, Type pluginType) + { + Type elementType = pluginType.GetElementType(); + char concatenator = node.GetAttribute("Concatenator", ",").ToCharArray()[0]; + + var valueString = node.GetAttribute("Values", string.Empty); + string[] rawValues = valueString.Split(new[]{concatenator}, StringSplitOptions.RemoveEmptyEntries); + + + var array = Array.CreateInstance(elementType, rawValues.Length); + for (int i = 0; i < rawValues.Length; i++) + { + object convertedType = Convert.ChangeType(rawValues[i].Trim(), elementType); + array.SetValue(convertedType, i); + } + + return new SerializedInstance(array); + } + + #endregion + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Configuration/TypeReaderFactory.cs =================================================================== --- trunk/Source/StructureMap/Configuration/TypeReaderFactory.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/TypeReaderFactory.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; + +namespace StructureMap.Configuration +{ + public static class TypeReaderFactory + { + private static List<ITypeReader> _readers = new List<ITypeReader>(); + + static TypeReaderFactory() + { + _readers.Add(new DictionaryReader()); + _readers.Add(new PrimitiveArrayReader()); + } + + public static ITypeReader GetReader(Type pluginType) + { + foreach (var reader in _readers) + { + if (reader.CanProcess(pluginType)) + { + return reader; + } + } + + return null; + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/XmlExtensions.cs =================================================================== --- trunk/Source/StructureMap/Configuration/XmlExtensions.cs 2008-06-15 14:28:14 UTC (rev 122) +++ trunk/Source/StructureMap/Configuration/XmlExtensions.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -5,6 +5,12 @@ { public static class XmlExtensions { + public static string GetAttribute(this XmlNode node, string attributeName, string defaultValue) + { + var attribute = node.Attributes.GetNamedItem(attributeName); + return attribute == null ? defaultValue : attribute.InnerText; + } + public static XmlTextExpression ForTextInChild(this XmlNode node, string xpath) { return new XmlTextExpression(node, xpath); Modified: trunk/Source/StructureMap/Diagnostics/Error.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/Error.cs 2008-06-15 14:28:14 UTC (rev 122) +++ trunk/Source/StructureMap/Diagnostics/Error.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -8,7 +8,7 @@ { private readonly int _code; private readonly string _message; - private readonly string _stackTrace = string.Empty; + private string _stackTrace = string.Empty; public InstanceToken Instance; public string Source; @@ -27,8 +27,9 @@ public Error(int errorCode, Exception ex, params object[] args) : this(errorCode, args) { - _message += "\n\n" + ex.ToString(); - _stackTrace = ex.StackTrace; + _message += "\n\n" + ex.Message; + + writeStackTrace(ex); } @@ -36,10 +37,23 @@ { _code = exception.ErrorCode; _message = exception.Message; - _stackTrace = exception.StackTrace; + + writeStackTrace(exception); } + private void writeStackTrace(Exception exception) + { + _stackTrace = string.Empty; + Exception ex = exception; + while (ex != null) + { + _stackTrace += exception.ToString(); + _stackTrace += "\n\n"; + ex = ex.InnerException; + } + } + public int Code { get { return _code; } Modified: trunk/Source/StructureMap/Graph/TypeRules.cs =================================================================== --- trunk/Source/StructureMap/Graph/TypeRules.cs 2008-06-15 14:28:14 UTC (rev 122) +++ trunk/Source/StructureMap/Graph/TypeRules.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -77,7 +77,7 @@ protected bool IsChild(Type type) { - return !type.IsArray && !IsSimple(type); + return IsPrimitiveArray(type) || (!type.IsArray && !IsSimple(type)); } protected bool IsChildArray(Type type) @@ -85,6 +85,11 @@ return type.IsArray && !IsSimple(type.GetElementType()); } + protected bool IsPrimitiveArray(Type type) + { + return type.IsArray && IsSimple(type.GetElementType()); + } + protected bool IsConcrete(Type type) { return !type.IsInterface && !type.IsAbstract; Modified: trunk/Source/StructureMap/InstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/InstanceMemento.cs 2008-06-15 14:28:14 UTC (rev 122) +++ trunk/Source/StructureMap/InstanceMemento.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -147,6 +147,8 @@ /// <returns></returns> protected abstract string getPropertyValue(string Key); + + /// <summary> /// Returns the named child InstanceMemento /// </summary> @@ -160,6 +162,12 @@ return returnValue; } + public virtual Instance ReadChildInstance(string name, PluginGraph graph, Type childType) + { + InstanceMemento child = GetChildMemento(name); + return child == null ? null : child.ReadInstance(graph, childType); + } + /// <summary> /// Template method for implementation specific retrieval of the named property /// </summary> @@ -207,7 +215,7 @@ } catch (Exception e) { - throw new StructureMapException(260, InstanceKey, pluginType.FullName); + throw new StructureMapException(260, e, InstanceKey, pluginType.FullName); } } @@ -225,5 +233,7 @@ return new ConfiguredInstance(this, pluginGraph, pluginType); } + + } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs 2008-06-15 14:28:14 UTC (rev 122) +++ trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -81,9 +81,11 @@ private void copyChild(string name, Type childType) { - InstanceMemento child = _memento.GetChildMemento(name); + //InstanceMemento child = _memento.GetChildMemento(name); + //Instance childInstance = child == null ? new DefaultInstance() : child.ReadInstance(_pluginGraph, childType); - Instance childInstance = child == null ? new DefaultInstance() : child.ReadInstance(_pluginGraph, childType); + Instance childInstance = _memento.ReadChildInstance(name, _pluginGraph, childType) ?? new DefaultInstance(); + _instance.Child(name).Is(childInstance); } Modified: trunk/Source/StructureMap/Source/XmlAttributeInstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/Source/XmlAttributeInstanceMemento.cs 2008-06-15 14:28:14 UTC (rev 122) +++ trunk/Source/StructureMap/Source/XmlAttributeInstanceMemento.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -1,6 +1,9 @@ +using System; using System.Collections; using System.Xml; using StructureMap.Configuration; +using StructureMap.Graph; +using StructureMap.Pipeline; namespace StructureMap.Source { @@ -110,5 +113,17 @@ { return _element.OuterXml; } + + public override Instance ReadChildInstance(string name, PluginGraph graph, Type childType) + { + var reader = TypeReaderFactory.GetReader(childType); + if (reader == null) + { + return base.ReadChildInstance(name, graph, childType); + } + + XmlElement element = _element[name]; + return reader.Read(element, childType); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Source/XmlNodeInstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/Source/XmlNodeInstanceMemento.cs 2008-06-15 14:28:14 UTC (rev 122) +++ trunk/Source/StructureMap/Source/XmlNodeInstanceMemento.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Xml; using StructureMap.Configuration; +using StructureMap.Graph; +using StructureMap.Pipeline; namespace StructureMap.Source { @@ -41,6 +43,11 @@ { get { + if (!string.IsNullOrEmpty(getPluggedType())) + { + return false; + } + bool returnValue = false; string typeName = getAttribute("Type"); @@ -66,10 +73,10 @@ return getAttribute(XmlConstants.PLUGGED_TYPE); } - private XmlNode getChildNode(string Key) + private XmlElement getChildNode(string Key) { string xpath = string.Format("Property[@Name='{0}']", Key); - XmlNode nodeProperty = _innerNode.SelectSingleNode(xpath); + XmlElement nodeProperty = (XmlElement) _innerNode.SelectSingleNode(xpath); return nodeProperty; } @@ -94,6 +101,18 @@ } + public override Instance ReadChildInstance(string name, PluginGraph graph, Type childType) + { + var reader = TypeReaderFactory.GetReader(childType); + if (reader == null) + { + return base.ReadChildInstance(name, graph, childType); + } + + XmlElement element = getChildNode(name); + return reader.Read(element, childType); + } + protected override InstanceMemento getChild(string Key) { InstanceMemento returnValue = null; Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-06-15 14:28:14 UTC (rev 122) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-06-16 02:12:53 UTC (rev 123) @@ -392,6 +392,10 @@ <None Include="..\structuremap.snk"> <Link>Properties\structuremap.snk</Link> </None> + <Compile Include="Configuration\DictionaryReader.cs" /> + <Compile Include="Configuration\ITypeReader.cs" /> + <Compile Include="Configuration\PrimitiveArrayReader.cs" /> + <Compile Include="Configuration\TypeReaderFactory.cs" /> <Compile Include="Configuration\XmlExtensions.cs" /> <Compile Include="Diagnostics\Doctor.cs" /> <Compile Include="Diagnostics\DoctorReport.cs" /> Added: trunk/Source/StructureMap.Testing/Configuration/DictionaryAndArrayArgumentTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DictionaryAndArrayArgumentTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Configuration/DictionaryAndArrayArgumentTester.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -0,0 +1,138 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NUnit.Framework; +using StructureMap.Graph; +using StructureMap.Pipeline; +using StructureMap.Source; +using StructureMap.Testing.Pipeline; +using StructureMap.Testing.TestData; + +namespace StructureMap.Testing.Configuration +{ + [TestFixture] + public class DictionaryAndArrayArgumentTester + { + [Test] + public void Read_in_a_dictionary_type_from_an_attribute_normalized_memento() + { + string xml = @" +<root> + <dictionary> + <Pair Key='color' Value='red'/> + <Pair Key='state' Value='texas'/> + <Pair Key='direction' Value='north'/> + </dictionary> +</root> +"; + + var element = DataMother.BuildDocument(xml).DocumentElement; + element.SetAttribute("PluggedType", TypePath.GetAssemblyQualifiedName(typeof (ClassWithDictionary))); + + XmlAttributeInstanceMemento memento = new XmlAttributeInstanceMemento(element); + + Instance instance = memento.ReadInstance(new PluginGraph(), typeof (ClassWithDictionary)); + + + ClassWithDictionary theObject = + (ClassWithDictionary) instance.Build(typeof(ClassWithDictionary), new BuildSession(new PluginGraph())); + + + theObject.Dictionary["color"].ShouldEqual("red"); + theObject.Dictionary["state"].ShouldEqual("texas"); + theObject.Dictionary["direction"].ShouldEqual("north"); + } + + [Test] + public void Read_in_a_dictionary_type_from_a_node_normalized_memento() + { + string xml = @" +<root> + <Property Name='dictionary'> + <Pair Key='color' Value='red'/> + <Pair Key='state' Value='texas'/> + <Pair Key='direction' Value='north'/> + </Property> +</root> +"; + + var element = DataMother.BuildDocument(xml).DocumentElement; + element.SetAttribute("PluggedType", TypePath.GetAssemblyQualifiedName(typeof(ClassWithDictionary))); + + XmlNodeInstanceMemento memento = new XmlNodeInstanceMemento(element, "Type", "Key"); + + Instance instance = memento.ReadInstance(new PluginGraph(), typeof(ClassWithDictionary)); + + + ClassWithDictionary theObject = + (ClassWithDictionary)instance.Build(typeof(ClassWithDictionary), new BuildSession(new PluginGraph())); + + + theObject.Dictionary["color"].ShouldEqual("red"); + theObject.Dictionary["state"].ShouldEqual("texas"); + theObject.Dictionary["direction"].ShouldEqual("north"); + } + + [Test] + public void Read_in_a_class_with_primitive_arrays() + { + string xml = @" +<root> + <numbers Values='1,2,3'/> + <strings Values='1,2,3'/> +</root> +"; + + var element = DataMother.BuildDocument(xml).DocumentElement; + element.SetAttribute("PluggedType", TypePath.GetAssemblyQualifiedName(typeof(ClassWithStringAndIntArray))); + + XmlAttributeInstanceMemento memento = new XmlAttributeInstanceMemento(element); + PluginGraph graph = new PluginGraph(); + Instance instance = memento.ReadInstance(graph, typeof(ClassWithStringAndIntArray)); + + ClassWithStringAndIntArray theObject = (ClassWithStringAndIntArray) instance.Build(typeof (ClassWithStringAndIntArray), + new BuildSession(graph)); + + theObject.Numbers.ShouldEqual(new int[] {1, 2, 3}); + theObject.Strings.ShouldEqual(new string[] {"1", "2", "3"}); + } + } + + public class ClassWithStringAndIntArray + { + private int[] _numbers; + private string[] _strings; + + public ClassWithStringAndIntArray(int[] numbers, string[] strings) + { + _numbers = numbers; + _strings = strings; + } + + public int[] Numbers + { + get { return _numbers; } + } + + public string[] Strings + { + get { return _strings; } + } + } + + public class ClassWithDictionary + { + private readonly IDictionary<string, string> _dictionary; + + public ClassWithDictionary(IDictionary<string, string> dictionary) + { + _dictionary = dictionary; + } + + public IDictionary<string, string> Dictionary + { + get { return _dictionary; } + } + } +} Added: trunk/Source/StructureMap.Testing/Configuration/DictionaryReaderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DictionaryReaderTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Configuration/DictionaryReaderTester.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -0,0 +1,154 @@ +using System.Collections.Generic; +using System.Collections.Specialized; +using NUnit.Framework; +using StructureMap.Configuration; +using StructureMap.Pipeline; +using StructureMap.Testing.Pipeline; +using StructureMap.Testing.TestData; + +namespace StructureMap.Testing.Configuration +{ + [TestFixture] + public class DictionaryReaderTester + { + [Test] + public void Can_process_a_dictionary() + { + var reader = new DictionaryReader(); + reader.CanProcess(typeof (IDictionary<string, string>)).ShouldBeTrue(); + reader.CanProcess(typeof (IDictionary<int, string>)).ShouldBeTrue(); + reader.CanProcess(typeof (IDictionary<string, int>)).ShouldBeTrue(); + reader.CanProcess(typeof (Dictionary<string, string>)).ShouldBeTrue(); + reader.CanProcess(typeof (Dictionary<int, string>)).ShouldBeTrue(); + reader.CanProcess(typeof (Dictionary<string, int>)).ShouldBeTrue(); + } + + [Test] + public void Can_process_NameValueCollection() + { + new DictionaryReader().CanProcess(typeof (NameValueCollection)).ShouldBeTrue(); + } + + [Test] + public void Read_a_string_int_dictionary2() + { + string xml = + @" +<node> + <Pair Key='color' Value='1'/> + <Pair Key='state' Value='2'/> + <Pair Key='direction' Value='3'/> +</node> +"; + + Instance instance = new DictionaryReader().Read(DataMother.BuildDocument(xml).DocumentElement, + typeof (Dictionary<string, int>)); + instance.ShouldBeOfType(typeof (SerializedInstance)); + + var collection = + (Dictionary<string, int>) instance.Build(typeof (Dictionary<string, int>), new StubBuildSession()); + + collection["color"].ShouldEqual(1); + collection["state"].ShouldEqual(2); + collection["direction"].ShouldEqual(3); + } + + [Test] + public void Read_a_string_string_dictionary() + { + string xml = + @" +<node> + <Pair Key='color' Value='red'/> + <Pair Key='state' Value='texas'/> + <Pair Key='direction' Value='north'/> +</node> +"; + + Instance instance = new DictionaryReader().Read(DataMother.BuildDocument(xml).DocumentElement, + typeof (IDictionary<string, string>)); + instance.ShouldBeOfType(typeof (SerializedInstance)); + + var collection = + (IDictionary<string, string>) + instance.Build(typeof (IDictionary<string, string>), new StubBuildSession()); + + collection["color"].ShouldEqual("red"); + collection["state"].ShouldEqual("texas"); + collection["direction"].ShouldEqual("north"); + } + + + [Test] + public void Read_a_string_string_dictionary2() + { + string xml = + @" +<node> + <Pair Key='color' Value='red'/> + <Pair Key='state' Value='texas'/> + <Pair Key='direction' Value='north'/> +</node> +"; + + Instance instance = new DictionaryReader().Read(DataMother.BuildDocument(xml).DocumentElement, + typeof (Dictionary<string, string>)); + instance.ShouldBeOfType(typeof (SerializedInstance)); + + var collection = + (Dictionary<string, string>) instance.Build(typeof (Dictionary<string, string>), new StubBuildSession()); + + collection["color"].ShouldEqual("red"); + collection["state"].ShouldEqual("texas"); + collection["direction"].ShouldEqual("north"); + } + + [Test] + public void Read_an_instance_for_NameValueCollection() + { + string xml = + @" +<node> + <Pair Key='color' Value='red'/> + <Pair Key='state' Value='texas'/> + <Pair Key='direction' Value='north'/> +</node> +"; + + Instance instance = new DictionaryReader().Read(DataMother.BuildDocument(xml).DocumentElement, + typeof (NameValueCollection)); + instance.ShouldBeOfType(typeof (SerializedInstance)); + + var collection = (NameValueCollection) instance.Build(typeof (NameValueCollection), new StubBuildSession()); + + collection["color"].ShouldEqual("red"); + collection["state"].ShouldEqual("texas"); + collection["direction"].ShouldEqual("north"); + } + + + [Test] + public void Read_an_int_string_dictionary() + { + string xml = + @" +<node> + <Pair Key='1' Value='red'/> + <Pair Key='2' Value='texas'/> + <Pair Key='3' Value='north'/> +</node> +"; + + Instance instance = new DictionaryReader().Read(DataMother.BuildDocument(xml).DocumentElement, + typeof (IDictionary<int, string>)); + instance.ShouldBeOfType(typeof (SerializedInstance)); + + var collection = + (IDictionary<int, string>) instance.Build(typeof (IDictionary<int, string>), new StubBuildSession()); + + collection[1].ShouldEqual("red"); + collection[2].ShouldEqual("texas"); + collection[3].ShouldEqual("north"); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Configuration/PrimitiveArrayReaderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/PrimitiveArrayReaderTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Configuration/PrimitiveArrayReaderTester.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Xml; +using NUnit.Framework; +using StructureMap.Configuration; +using StructureMap.Pipeline; +using StructureMap.Testing.Pipeline; +using StructureMap.Testing.TestData; +using StructureMap.Testing.Widget; + +namespace StructureMap.Testing.Configuration +{ + [TestFixture] + public class PrimitiveeArrayReaderTester + { + [Test] + public void CanProcess_an_array_of_primitive_types() + { + PrimitiveArrayReader reader = new PrimitiveArrayReader(); + + reader.CanProcess(typeof(string)).ShouldBeFalse(); + reader.CanProcess(typeof(IWidget[])).ShouldBeFalse(); + + reader.CanProcess(typeof(string[])).ShouldBeTrue(); + reader.CanProcess(typeof(int[])).ShouldBeTrue(); + reader.CanProcess(typeof(double[])).ShouldBeTrue(); + } + + private object parseNode(string xml, Type pluginType) + { + XmlElement element = DataMother.BuildDocument(xml).DocumentElement; + PrimitiveArrayReader reader = new PrimitiveArrayReader(); + Instance instance = reader.Read(element, pluginType); + + return instance.Build(pluginType, new StubBuildSession()); + } + + [Test] + public void Parse_a_string_array_with_the_default_concatenator() + { + parseNode("<node Values='a,b,c,d'></node>", typeof (string[])).ShouldEqual(new string[] {"a", "b", "c", "d"}); + } + + + [Test] + public void Parse_a_string_array_with_overridden_concatenator() + { + parseNode("<node Values='a,b,c,d' Concatenator=';'></node>", typeof(string[])).ShouldEqual(new string[] { "a,b,c,d" }); + parseNode("<node Values='a;b;c;d' Concatenator=';'></node>", typeof(string[])).ShouldEqual(new string[] { "a", "b", "c", "d" }); + } + + + [Test] + public void Parse_a_string_array_with_the_default_concatenator_and_deal_with_leading_or_trailing_spaces() + { + parseNode("<node Values='a , b,c,d'></node>", typeof(string[])).ShouldEqual(new string[] { "a", "b", "c", "d" }); + } + + + [Test] + public void Parse_an_int_array_with_the_default_concatenator() + { + parseNode("<node Values='1,2,3,4'></node>", typeof(int[])).ShouldEqual(new int[] { 1, 2, 3, 4 }); + } + } +} Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-06-15 14:28:14 UTC (rev 122) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-06-16 02:12:53 UTC (rev 123) @@ -180,6 +180,8 @@ <Compile Include="Configuration\ConfigurationParserBuilderTester.cs" /> <Compile Include="Configuration\ConfigurationParserTester.cs" /> <Compile Include="Configuration\DefaultInstanceNodeTester.cs" /> + <Compile Include="Configuration\DictionaryAndArrayArgumentTester.cs" /> + <Compile Include="Configuration\DictionaryReaderTester.cs" /> <Compile Include="Configuration\DSL\AddInstanceTester.cs" /> <Compile Include="Configuration\DSL\AddTypesTester.cs" /> <Compile Include="Configuration\DSL\ConstructorExpressionTester.cs" /> @@ -203,6 +205,7 @@ </Compile> <Compile Include="Configuration\InlineInstanceDefinitionInProfileAndMachineNodesTester.cs" /> <Compile Include="Configuration\NormalGraphBuilderTester.cs" /> + <Compile Include="Configuration\PrimitiveArrayReaderTester.cs" /> <Compile Include="Configuration\ProfileBuilderTester.cs" /> <Compile Include="Configuration\ShortcuttedInstanceNodeTester.cs" /> <Compile Include="Diagnostics\DoctorTester.cs" /> Modified: trunk/Source/StructureMap.Testing/TestData/DataMother.cs =================================================================== --- trunk/Source/StructureMap.Testing/TestData/DataMother.cs 2008-06-15 14:28:14 UTC (rev 122) +++ trunk/Source/StructureMap.Testing/TestData/DataMother.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -19,16 +19,22 @@ public static PluginGraph BuildPluginGraphFromXml(string xml) { - xml = xml.Replace("'", "\""); - XmlDocument document = new XmlDocument(); - document.LoadXml(xml); + XmlDocument document = BuildDocument(xml); ConfigurationParser parser = new ConfigurationParser(document.DocumentElement); PluginGraphBuilder builder = new PluginGraphBuilder(parser); return builder.Build(); } + public static XmlDocument BuildDocument(string xml) + { + xml = xml.Replace("'", "\""); + XmlDocument document = new XmlDocument(); + document.LoadXml(xml); + return document; + } + public static void BackupStructureMapConfig() { if (File.Exists("StructureMap.config.bak")) File.Delete("StructureMap.config.bak"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-06-15 14:28:16
|
Revision: 122 http://structuremap.svn.sourceforge.net/structuremap/?rev=122&view=rev Author: jeremydmiller Date: 2008-06-15 07:28:14 -0700 (Sun, 15 Jun 2008) Log Message: ----------- cleaning up the xml parsing Modified Paths: -------------- trunk/Source/StructureMap/Configuration/FamilyParser.cs trunk/Source/StructureMap/Diagnostics/Error.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-06-15 01:49:31 UTC (rev 121) +++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-06-15 14:28:14 UTC (rev 122) @@ -30,12 +30,17 @@ family.SetScopeTo(scope); attachMementoSource(family, familyElement); - familyElement.ForEachChild(PLUGIN_NODE).Do(element => attachPlugin(element, family)); + attachPlugins(family, familyElement); attachInterceptors(family, familyElement); attachInstances(family, familyElement, _builder); }); } + private void attachPlugins(PluginFamily family, XmlElement familyElement) + { + familyElement.ForEachChild(PLUGIN_NODE).Do(element => attachPlugin(element, family)); + } + private void attachInstances(PluginFamily family, XmlElement familyElement, IGraphBuilder builder) { familyElement.ForEachChild(INSTANCE_NODE).Do(element => @@ -108,7 +113,6 @@ family.AddPlugin(plugin); pluginElement.ForTextInChild("Setter/@Name").Do(prop => plugin.Setters.Add(prop)); - }); } @@ -119,8 +123,10 @@ { var interceptorMemento = new XmlAttributeInstanceMemento(element); string context = contextBase + element.OuterXml; - _builder.WithSystemObject<IBuildInterceptor>(interceptorMemento, context, - interceptor => family.AddInterceptor(interceptor)); + _builder.WithSystemObject<IBuildInterceptor>( + interceptorMemento, + context, + interceptor => family.AddInterceptor(interceptor)); }); } } Modified: trunk/Source/StructureMap/Diagnostics/Error.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/Error.cs 2008-06-15 01:49:31 UTC (rev 121) +++ trunk/Source/StructureMap/Diagnostics/Error.cs 2008-06-15 14:28:14 UTC (rev 122) @@ -88,7 +88,6 @@ public void Write(StringWriter writer) { - // TODO: hit with an extension method for 3.5 writer.WriteLine("Error: " + Code); if (Instance != null) writer.WriteLine(Instance.ToString()); writer.WriteLine("Source: " + Source); Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-06-15 01:49:31 UTC (rev 121) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-06-15 14:28:14 UTC (rev 122) @@ -148,7 +148,6 @@ private void discoverImplicitInstances() { - // TODO: Apply some 3.5 lambda magic. Maybe move to PluginCollection List<Plugin> list = _plugins.FindAutoFillablePlugins(); list.RemoveAll( plugin => _instances.Exists(instance => instance.Matches(plugin))); Modified: trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs 2008-06-15 01:49:31 UTC (rev 121) +++ trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs 2008-06-15 14:28:14 UTC (rev 122) @@ -131,14 +131,6 @@ }); } - // TODO: Decide if this is important or not - //[Test] - //public void Log_error_156_if_Include_node_does_not_have_a_File() - //{ - // DataMother.WriteDocument("MissingInclude.xml", "<StructureMap><Include></Include></StructureMap>"); - // assertErrorIsLogged(156, () => builder.IncludeFile("MissingInclude.xml")); - //} - [Test, Explicit] public void Log_exception_100_if_StructureMap_config_is_required_and_missing() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-06-15 01:49:36
|
Revision: 121 http://structuremap.svn.sourceforge.net/structuremap/?rev=121&view=rev Author: jeremydmiller Date: 2008-06-14 18:49:31 -0700 (Sat, 14 Jun 2008) Log Message: ----------- VS2008 cutover Modified Paths: -------------- trunk/Source/CommonAssemblyInfo.cs trunk/Source/StructureMap/BuildSession.cs trunk/Source/StructureMap/Configuration/ConfigurationParser.cs trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Configuration/DSL/RegistryExpressions.cs trunk/Source/StructureMap/Configuration/FamilyParser.cs trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs trunk/Source/StructureMap/Configuration/ProfileBuilder.cs trunk/Source/StructureMap/Configuration/XmlConstants.cs trunk/Source/StructureMap/Diagnostics/BuildError.cs trunk/Source/StructureMap/Diagnostics/Doctor.cs trunk/Source/StructureMap/Diagnostics/ErrorCollection.cs trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs trunk/Source/StructureMap/Graph/AssemblyScanner.cs trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs trunk/Source/StructureMap/Graph/ITypeScanner.cs trunk/Source/StructureMap/Graph/PluginCollection.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/InstanceMemento.cs trunk/Source/StructureMap/Interceptors/InterceptorLibrary.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap/PluginGraphBuilder.cs trunk/Source/StructureMap/Source/XmlMementoCreator.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap/Util/Cache.cs trunk/Source/StructureMap.AutoMocking/StructureMap.AutoMocking.csproj trunk/Source/StructureMap.DataAccess/StructureMap.DataAccess.csproj trunk/Source/StructureMap.DeploymentTasks/StructureMap.DeploymentTasks.csproj trunk/Source/StructureMap.Testing/BuildSessionTester.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs trunk/Source/StructureMap.Testing/Configuration/FamilyParserTester.cs trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs trunk/Source/StructureMap.Testing/Graph/EnumerationTester.cs trunk/Source/StructureMap.Testing/Graph/ExceptionHandling/StructureMapExceptionTester.cs trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs trunk/Source/StructureMap.Testing/Graph/FullStackFacadeTester.cs trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/Graph/Interceptors/TypeInterceptionTester.cs trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs trunk/Source/StructureMap.Testing/Graph/PluginGraphBuilderTester.cs trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs trunk/Source/StructureMap.Testing/Pipeline/ProfileTester.cs trunk/Source/StructureMap.Testing/PipelineGraphTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing/TestUtility.cs trunk/Source/StructureMap.Testing.GenericWidgets/StructureMap.Testing.GenericWidgets.csproj trunk/Source/StructureMap.Testing.Widget/StructureMap.Testing.Widget.csproj trunk/Source/StructureMap.Testing.Widget2/StructureMap.Testing.Widget2.csproj trunk/Source/StructureMap.Testing.Widget3/StructureMap.Testing.Widget3.csproj trunk/Source/StructureMap.Testing.Widget4/StructureMap.Testing.Widget4.csproj trunk/Source/StructureMap.Testing.Widget5/StructureMap.Testing.Widget5.csproj trunk/Source/StructureMap.sln Added Paths: ----------- trunk/Source/StructureMap/Configuration/XmlExtensions.cs trunk/Source/StructureMap/Diagnostics/DoctorReport.cs trunk/Source/StructureMap/Diagnostics/DoctorResult.cs trunk/Source/StructureMap/Diagnostics/DoctorRunner.cs trunk/Source/StructureMap/Diagnostics/ValidationError.cs trunk/Source/StructureMap/Pipeline/SerializedInstance.cs trunk/Source/StructureMap.AutoMocking/StructureMap.AutoMocking.csproj.user trunk/Source/StructureMap.Testing/Diagnostics/DoctorTester.cs trunk/Source/StructureMap.Testing/Diagnostics/WriterExtensions.cs trunk/Source/StructureMap.Testing/Pipeline/SerializedInstanceTester.cs trunk/Source/StructureMap.Testing/SpecificationExtensions.cs trunk/Source/StructureMap.lnk trunk/Source/StructureMapDoctor/ trunk/Source/StructureMapDoctor/Program.cs trunk/Source/StructureMapDoctor/Properties/ trunk/Source/StructureMapDoctor/Properties/AssemblyInfo.cs trunk/Source/StructureMapDoctor/StructureMapDoctor.csproj Modified: trunk/Source/CommonAssemblyInfo.cs =================================================================== --- trunk/Source/CommonAssemblyInfo.cs 2008-06-07 22:48:46 UTC (rev 120) +++ trunk/Source/CommonAssemblyInfo.cs 2008-06-15 01:49:31 UTC (rev 121) @@ -5,7 +5,7 @@ //------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. -// Runtime Version:2.0.50727.1433 +// Runtime Version:2.0.50727.1434 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. Modified: trunk/Source/StructureMap/BuildSession.cs =================================================================== --- trunk/Source/StructureMap/BuildSession.cs 2008-06-07 22:48:46 UTC (rev 120) +++ trunk/Source/StructureMap/BuildSession.cs 2008-06-15 01:49:31 UTC (rev 121) @@ -72,7 +72,6 @@ } else { - // TODO: 3.5, move this to an extension method of Array? array = Array.CreateInstance(pluginType, instances.Length); for (int i = 0; i < instances.Length; i++) { Modified: trunk/Source/StructureMap/Configuration/ConfigurationParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-06-07 22:48:46 UTC (rev 120) +++ trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-06-15 01:49:31 UTC (rev 121) @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using System.Xml; using StructureMap.Diagnostics; @@ -8,89 +7,50 @@ namespace StructureMap.Configuration { - public class ConfigurationParser + public class ConfigurationParser : XmlConstants { #region statics public static ConfigurationParser FromFile(string filename) { - XmlDocument document = new XmlDocument(); + var document = new XmlDocument(); document.Load(filename); - XmlNode structureMapNode = document.SelectSingleNode("//" + XmlConstants.STRUCTUREMAP); + XmlNode structureMapNode = document.SelectSingleNode("//" + STRUCTUREMAP); if (structureMapNode == null) { throw new StructureMapException(155, filename); } - ConfigurationParser parser = new ConfigurationParser(structureMapNode); + var parser = new ConfigurationParser(structureMapNode); parser.FilePath = filename; - + return parser; } #endregion - public string Description = string.Empty; - private readonly XmlMementoCreator _mementoCreator; private readonly XmlNode _structureMapNode; private string _filePath = string.Empty; + public string Description = string.Empty; public ConfigurationParser(XmlNode structureMapNode) { _structureMapNode = structureMapNode; - // TODO: 3.5 cleanup with extension method XmlMementoStyle mementoStyle = XmlMementoStyle.NodeNormalized; - - - XmlAttribute att = _structureMapNode.Attributes[XmlConstants.MEMENTO_STYLE]; - if (att != null) + _structureMapNode.ForAttributeValue(MEMENTO_STYLE, style => { - if (att.Value == XmlConstants.ATTRIBUTE_STYLE) - { - mementoStyle = XmlMementoStyle.AttributeNormalized; - } - } + if (style == ATTRIBUTE_STYLE) mementoStyle = XmlMementoStyle.AttributeNormalized; + }); - _mementoCreator = new XmlMementoCreator( mementoStyle, - XmlConstants.TYPE_ATTRIBUTE, - XmlConstants.KEY_ATTRIBUTE); + TYPE_ATTRIBUTE, + KEY_ATTRIBUTE); } - public void ForEachFile(GraphLog log, Action<string> action) - { - // TODO: Clean up with 3.5 - string includePath = getIncludePath(); - XmlNodeList includeNodes = _structureMapNode.SelectNodes(XmlConstants.INCLUDE_NODE); - foreach (XmlElement includeElement in includeNodes) - { - string fileName = includeElement.GetAttribute("File"); - if (string.IsNullOrEmpty(fileName)) - { - log.RegisterError(156, _filePath); - } - else - { - string includedFile = Path.Combine(includePath, fileName); - action(includedFile); - } - } - } - - private string getIncludePath() - { - if (string.IsNullOrEmpty(_filePath)) - { - return string.Empty; - } - - return Path.GetDirectoryName(_filePath); - } - public string Id { get @@ -107,83 +67,53 @@ set { _filePath = value; } } - public void ParseAssemblies(IGraphBuilder builder) + public void ForEachFile(GraphLog log, Action<string> action) { - parseAssemblies(builder); - } - - - public void ParseInstances(IGraphBuilder builder) - { - XmlNodeList familyNodes = findNodes(XmlConstants.PLUGIN_FAMILY_NODE); - foreach (XmlElement familyElement in familyNodes) + string includePath = getIncludePath(); + _structureMapNode.ForTextInChild("Include/@File").Do(fileName => { - TypePath typePath = TypePath.CreateFromXmlNode(familyElement); - - builder.ConfigureFamily(typePath, - delegate(PluginFamily family) { attachInstances(family, familyElement, builder); }); - } + string includedFile = Path.Combine(includePath, fileName); + action(includedFile); + }); } - private void parseAssemblies(IGraphBuilder builder) + private string getIncludePath() { - XmlNodeList assemblyNodes = findNodes(XmlConstants.ASSEMBLY); - foreach (XmlNode assemblyNode in assemblyNodes) + if (string.IsNullOrEmpty(_filePath)) { - string assemblyName = assemblyNode.Attributes[XmlConstants.NAME].Value; - - builder.AddAssembly(assemblyName); + return string.Empty; } - } - private XmlNodeList findNodes(string nodeName) - { - return _structureMapNode.SelectNodes(nodeName); + return Path.GetDirectoryName(_filePath); } - - public void ParseFamilies(IGraphBuilder builder) + public void ParseAssemblies(IGraphBuilder builder) { - FamilyParser familyParser = new FamilyParser(builder, _mementoCreator); - - XmlNodeList familyNodes = findNodes(XmlConstants.PLUGIN_FAMILY_NODE); - foreach (XmlElement familyElement in familyNodes) - { - familyParser.ParseFamily(familyElement); - } - - XmlNodeList defaultNodes = findNodes(XmlConstants.DEFAULT_INSTANCE); - foreach (XmlElement element in defaultNodes) - { - familyParser.ParseDefaultElement(element); - } - - XmlNodeList instanceNodes = findNodes(XmlConstants.ADD_INSTANCE_NODE); - foreach (XmlElement element in instanceNodes) - { - familyParser.ParseInstanceElement(element); - } + _structureMapNode.ForTextInChild("Assembly/@Name").Do(name => builder.AddAssembly(name)); } - private void attachInstances(PluginFamily family, XmlElement familyElement, IGraphBuilder builder) + private XmlExtensions.XmlNodeExpression forEachNode(string xpath) { - foreach (XmlNode instanceNode in familyElement.ChildNodes) - { - if (instanceNode.Name != XmlConstants.INSTANCE_NODE) - { - continue; - } - - InstanceMemento memento = _mementoCreator.CreateMemento(instanceNode); - family.AddInstance(memento); - } + return _structureMapNode.ForEachChild(xpath); } public void ParseProfilesAndMachines(IGraphBuilder builder) { - ProfileAndMachineParser parser = new ProfileAndMachineParser(builder, _structureMapNode, _mementoCreator); + var parser = new ProfileAndMachineParser(builder, _structureMapNode, _mementoCreator); parser.Parse(); } + + public void Parse(IGraphBuilder builder) + { + var familyParser = new FamilyParser(builder, _mementoCreator); + + forEachNode(PLUGIN_FAMILY_NODE).Do(familyParser.ParseFamily); + forEachNode(DEFAULT_INSTANCE).Do(familyParser.ParseDefaultElement); + forEachNode(ADD_INSTANCE_NODE).Do(familyParser.ParseInstanceElement); + + ParseProfilesAndMachines(builder); + } + } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs 2008-06-07 22:48:46 UTC (rev 120) +++ trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs 2008-06-15 01:49:31 UTC (rev 121) @@ -8,11 +8,11 @@ public class ConfigurationParserBuilder { private readonly GraphLog _log; + private readonly List<string> _otherFiles = new List<string>(); private readonly List<ConfigurationParser> _parsers = new List<ConfigurationParser>(); - private readonly List<string> _otherFiles = new List<string>(); - private bool _ignoreDefaultFile = false; + private bool _ignoreDefaultFile; private bool _pullConfigurationFromAppConfig; - private bool _useAndEnforceExistenceOfDefaultFile = false; + private bool _useAndEnforceExistenceOfDefaultFile; public ConfigurationParserBuilder(GraphLog log) @@ -39,35 +39,39 @@ set { _pullConfigurationFromAppConfig = value; } } - // TODO: Clean up with 3.5 public ConfigurationParser[] GetParsers() { - List<ConfigurationParser> list = new List<ConfigurationParser>(); + var list = new List<ConfigurationParser>(); - // Pick up the configuration in the default StructureMap.config - string pathToStructureMapConfig = StructureMapConfiguration.GetStructureMapConfigurationPath(); - if (shouldUseStructureMapConfigFileAt(pathToStructureMapConfig)) - { - _log.Try(delegate() - { - ConfigurationParser parser = ConfigurationParser.FromFile(pathToStructureMapConfig); - list.Add(parser); - }).AndReportErrorAs(100, pathToStructureMapConfig); - } + addConfigurationFromStructureMapConfig(list); + addConfigurationFromExplicitlyAddedFiles(list); + addConfigurationFromApplicationConfigFile(); - foreach (string filename in _otherFiles) + list.AddRange(_parsers); + + addConfigurationFromIncludeNodes(list); + + return list.ToArray(); + } + + private void addConfigurationFromIncludeNodes(List<ConfigurationParser> list) + { + foreach (ConfigurationParser parser in list.ToArray()) { - _log.Try(delegate() - { - ConfigurationParser parser = ConfigurationParser.FromFile(filename); - parser.Description = filename; - list.Add(parser); - }).AndReportErrorAs(160, filename); + parser.ForEachFile(_log, + filename => _log.Try(() => + { + ConfigurationParser childParser = ConfigurationParser.FromFile(filename); + list.Add(childParser); + }).AndReportErrorAs(150, filename)); } + } + private void addConfigurationFromApplicationConfigFile() + { if (_pullConfigurationFromAppConfig) { - _log.Try(delegate() + _log.Try(() => { IList<XmlNode> appConfigNodes = StructureMapConfigurationSection.GetStructureMapConfiguration(); foreach (XmlNode appConfigNode in appConfigNodes) @@ -76,24 +80,33 @@ } }).AndLogAnyErrors(); } + } - list.AddRange(_parsers); + private void addConfigurationFromExplicitlyAddedFiles(List<ConfigurationParser> list) + { + foreach (string filename in _otherFiles) + { + _log.Try(() => + { + ConfigurationParser parser = ConfigurationParser.FromFile(filename); + parser.Description = filename; + list.Add(parser); + }).AndReportErrorAs(160, filename); + } + } - foreach (ConfigurationParser parser in list.ToArray()) + private void addConfigurationFromStructureMapConfig(List<ConfigurationParser> list) + { +// Pick up the configuration in the default StructureMap.config + string pathToStructureMapConfig = StructureMapConfiguration.GetStructureMapConfigurationPath(); + if (shouldUseStructureMapConfigFileAt(pathToStructureMapConfig)) { - parser.ForEachFile(_log, - delegate(string filename) - { - _log.Try(delegate() - { - ConfigurationParser childParser = ConfigurationParser.FromFile(filename); - list.Add(childParser); - }).AndReportErrorAs(150, filename); - }); + _log.Try(() => + { + ConfigurationParser parser = ConfigurationParser.FromFile(pathToStructureMapConfig); + list.Add(parser); + }).AndReportErrorAs(100, pathToStructureMapConfig); } - - - return list.ToArray(); } private bool shouldUseStructureMapConfigFileAt(string pathToStructureMapConfig) @@ -112,7 +125,7 @@ public void IncludeNode(XmlNode node, string description) { - ConfigurationParser parser = new ConfigurationParser(node); + var parser = new ConfigurationParser(node); parser.Description = description; _parsers.Add(parser); @@ -120,7 +133,7 @@ public static ConfigurationParser[] GetParsers(XmlNode node, GraphLog log) { - ConfigurationParserBuilder builder = new ConfigurationParserBuilder(log); + var builder = new ConfigurationParserBuilder(log); builder.IncludeNode(node, string.Empty); builder.IgnoreDefaultFile = true; Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-06-07 22:48:46 UTC (rev 120) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-06-15 01:49:31 UTC (rev 121) @@ -21,20 +21,19 @@ { _pluginType = typeof (PLUGINTYPE); - registry.addExpression(delegate(PluginGraph graph) + registry.addExpression(graph => { PluginFamily family = graph.FindFamily(_pluginType); family.SetScopeTo(_scope); - // TODO: clean up with 3.5 - _children.ForEach(delegate(Action<PluginGraph> action) { action(graph); }); - _alterations.ForEach(delegate(Action<PluginFamily> action) { action(family); }); + _children.ForEach(action => action(graph)); + _alterations.ForEach(action => action(family)); }); } public CreatePluginFamilyExpression<PLUGINTYPE> AddInstances(params Instance[] instances) { - return alterAndContinue(delegate(PluginFamily family) + return alterAndContinue(family => { foreach (Instance instance in instances) { @@ -44,7 +43,6 @@ } - // TODO: 3.5, Try alterAndContinue(f => {}); private CreatePluginFamilyExpression<PLUGINTYPE> alterAndContinue(Action<PluginFamily> action) { _alterations.Add(action); @@ -58,7 +56,7 @@ /// <returns></returns> public CreatePluginFamilyExpression<PLUGINTYPE> TheDefaultIs(Instance instance) { - return alterAndContinue(delegate(PluginFamily family) + return alterAndContinue(family => { family.AddInstance(instance); family.DefaultInstanceKey = instance.Name; @@ -67,8 +65,7 @@ public CreatePluginFamilyExpression<PLUGINTYPE> AddInstance(Instance instance) { - return alterAndContinue( - delegate(PluginFamily family) { family.AddInstance(instance); }); + return alterAndContinue(family => family.AddInstance(instance)); } /// <summary> @@ -83,7 +80,7 @@ { ExpressionValidator.ValidatePluggabilityOf(typeof (CONCRETETYPE)).IntoPluginType(_pluginType); - return alterAndContinue(delegate(PluginFamily family) + return alterAndContinue(family => { Plugin plugin = family.Plugins.FindOrCreate(typeof (CONCRETETYPE), true); family.DefaultInstanceKey = plugin.ConcreteKey; @@ -100,7 +97,7 @@ /// <returns></returns> public CreatePluginFamilyExpression<PLUGINTYPE> CacheBy(InstanceScope scope) { - return alterAndContinue(delegate(PluginFamily family) { family.SetScopeTo(scope); }); + return alterAndContinue(family => family.SetScopeTo(scope)); } /// <summary> @@ -109,8 +106,7 @@ /// <returns></returns> public CreatePluginFamilyExpression<PLUGINTYPE> AsSingletons() { - _alterations.Add( - delegate(PluginFamily family) { family.SetScopeTo(InstanceScope.Singleton); }); + _alterations.Add(family => family.SetScopeTo(InstanceScope.Singleton)); return this; } @@ -118,9 +114,9 @@ public CreatePluginFamilyExpression<PLUGINTYPE> OnCreation(Action<PLUGINTYPE> handler) { _children.Add( - delegate(PluginGraph graph) + graph => { - Func<object, object> function = delegate(object target) + Func<object, object> function = target => { handler((PLUGINTYPE) target); return target; @@ -136,9 +132,9 @@ public CreatePluginFamilyExpression<PLUGINTYPE> EnrichWith(EnrichmentHandler<PLUGINTYPE> handler) { _children.Add( - delegate(PluginGraph graph) + graph => { - Func<object, object> function = delegate(object target) { return handler((PLUGINTYPE) target); }; + Func<object, object> function = target => handler((PLUGINTYPE) target); PluginTypeInterceptor interceptor = new PluginTypeInterceptor(typeof (PLUGINTYPE), function); graph.InterceptorLibrary.AddInterceptor(interceptor); @@ -157,7 +153,7 @@ ExpressionValidator.ValidatePluggabilityOf(typeof (CONCRETETYPE)).IntoPluginType(typeof (PLUGINTYPE)); _alterations.Add( - delegate(PluginFamily family) + family => { Plugin plugin = new Plugin(typeof (CONCRETETYPE)); plugin.ConcreteKey = instanceName; @@ -170,13 +166,13 @@ public CreatePluginFamilyExpression<PLUGINTYPE> InterceptConstructionWith(IBuildInterceptor interceptor) { - _alterations.Add(delegate(PluginFamily family) { family.AddInterceptor(interceptor); }); + _alterations.Add(family => family.AddInterceptor(interceptor)); return this; } public CreatePluginFamilyExpression<PLUGINTYPE> AddInstancesFrom(MementoSource source) { - _alterations.Add(delegate(PluginFamily family) { family.AddMementoSource(source); }); + _alterations.Add(family => family.AddMementoSource(source)); return this; } @@ -185,7 +181,7 @@ { ExpressionValidator.ValidatePluggabilityOf(typeof (PLUGGEDTYPE)).IntoPluginType(typeof (PLUGINTYPE)); - _alterations.Add(delegate(PluginFamily family) { family.AddPlugin(typeof (PLUGGEDTYPE), concreteKey); }); + _alterations.Add(family => family.AddPlugin(typeof (PLUGGEDTYPE), concreteKey)); return this; } @@ -197,7 +193,7 @@ public CreatePluginFamilyExpression<PLUGINTYPE> TheDefaultIs(Func<PLUGINTYPE> func) { - ConstructorInstance instance = new ConstructorInstance(delegate() { return func(); }); + ConstructorInstance instance = new ConstructorInstance(() => func()); return TheDefaultIs(instance); } @@ -209,7 +205,7 @@ public CreatePluginFamilyExpression<PLUGINTYPE> AddInstance(Func<PLUGINTYPE> func) { - ConstructorInstance instance = new ConstructorInstance(delegate(){ return func();}); + ConstructorInstance instance = new ConstructorInstance(() => func()); return AddInstance(instance); } Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs 2008-06-07 22:48:46 UTC (rev 120) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs 2008-06-15 01:49:31 UTC (rev 121) @@ -19,7 +19,7 @@ private GenericFamilyExpression alterAndContinue(Action<PluginFamily> action) { - _registry.addExpression(delegate(PluginGraph graph) + _registry.addExpression(graph => { PluginFamily family = graph.FindFamily(_pluginType); action(family); @@ -36,7 +36,7 @@ public GenericFamilyExpression TheDefaultIs(Instance instance) { - return alterAndContinue(delegate(PluginFamily family) + return alterAndContinue(family => { family.AddInstance(instance); family.DefaultInstanceKey = instance.Name; @@ -51,17 +51,17 @@ public GenericFamilyExpression AddInstance(Instance instance) { - return alterAndContinue(delegate(PluginFamily family) { family.AddInstance(instance); }); + return alterAndContinue(family => family.AddInstance(instance)); } public GenericFamilyExpression CacheBy(InstanceScope scope) { - return alterAndContinue(delegate(PluginFamily family) { family.SetScopeTo(scope); }); + return alterAndContinue(family => family.SetScopeTo(scope)); } public GenericFamilyExpression OnCreation(Action<object> action) { - Func<object, object> func = delegate(object raw) + Func<object, object> func = raw => { action(raw); return raw; @@ -71,7 +71,7 @@ public GenericFamilyExpression EnrichWith(Func<object, object> func) { - _registry.addExpression(delegate(PluginGraph graph) + _registry.addExpression(graph => { PluginTypeInterceptor interceptor = new PluginTypeInterceptor(_pluginType, func); graph.InterceptorLibrary.AddInterceptor(interceptor); @@ -83,10 +83,7 @@ public GenericFamilyExpression InterceptConstructionWith(IBuildInterceptor interceptor) { - return alterAndContinue(delegate(PluginFamily family) - { - family.AddInterceptor(interceptor); - }); + return alterAndContinue(family => family.AddInterceptor(interceptor)); } public GenericFamilyExpression AddConcreteType(Type concreteType) Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2008-06-07 22:48:46 UTC (rev 120) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2008-06-15 01:49:31 UTC (rev 121) @@ -61,10 +61,7 @@ /// <returns></returns> public ProfileExpression UseNamedInstance(string instanceKey) { - _registry.addExpression(delegate(PluginGraph graph) - { - graph.SetDefault(_profileName, typeof(T), new ReferencedInstance(instanceKey)); - }); + _registry.addExpression(graph => graph.SetDefault(_profileName, typeof (T), new ReferencedInstance(instanceKey))); return _parent; } @@ -78,10 +75,7 @@ { instance.Name = "Default Instance for Profile " + _profileName; - _registry.addExpression(delegate (PluginGraph graph) - { - graph.SetDefault(_profileName, typeof(T), instance); - }); + _registry.addExpression(graph => graph.SetDefault(_profileName, typeof (T), instance)); return _parent; } @@ -134,10 +128,7 @@ public ProfileExpression Use(Instance instance) { - _registry.addExpression(delegate(PluginGraph graph) - { - graph.SetDefault(_parent._profileName, _pluginType, instance); - }); + _registry.addExpression(graph => graph.SetDefault(_parent._profileName, _pluginType, instance)); return _parent; } Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-06-07 22:48:46 UTC (rev 120) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-06-15 01:49:31 UTC (rev 121) @@ -19,7 +19,7 @@ public ScanAssembliesExpression(Registry registry) { _registry = registry; - _registry.addExpression(delegate(PluginGraph graph) + _registry.addExpression(graph => { foreach (Assembly assembly in _assemblies) { @@ -68,7 +68,7 @@ public ScanAssembliesExpression AddAllTypesOf<PLUGINTYPE>() { - _registry.addExpression(delegate(PluginGraph pluginGraph) + _registry.addExpression(pluginGraph => { PluginFamily family = pluginGraph.FindFamily(typeof (PLUGINTYPE)); @@ -88,10 +88,7 @@ public ScanAssembliesExpression With(ITypeScanner scanner) { - _registry.addExpression(delegate(PluginGraph graph) - { - graph.Assemblies.AddScanner(scanner); - }); + _registry.addExpression(graph => graph.Assemblies.AddScanner(scanner)); return this; Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-06-07 22:48:46 UTC (rev 120) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-06-15 01:49:31 UTC (rev 121) @@ -89,7 +89,7 @@ ConfiguredInstance instance = new ConfiguredInstance(); addExpression( - delegate(PluginGraph pluginGraph) { pluginGraph.FindFamily(typeof (PLUGINTYPE)).AddInstance(instance); }); + pluginGraph => pluginGraph.FindFamily(typeof (PLUGINTYPE)).AddInstance(instance)); return instance; } @@ -104,7 +104,7 @@ public LiteralInstance AddInstanceOf<PLUGINTYPE>(PLUGINTYPE target) { LiteralInstance literal = new LiteralInstance(target); - _actions.Add(delegate(PluginGraph graph) { graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(literal); }); + _actions.Add(graph => graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(literal)); return literal; } @@ -118,10 +118,7 @@ public PrototypeInstance AddPrototypeInstanceOf<PLUGINTYPE>(PLUGINTYPE prototype) { PrototypeInstance instance = new PrototypeInstance((ICloneable) prototype); - _actions.Add(delegate(PluginGraph graph) - { - graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(instance); - }); + _actions.Add(graph => graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(instance)); return instance; } @@ -129,7 +126,6 @@ /// <summary> /// convenience method for a UserControl /// </summary> - /// <typeparam name="PLUGINTYPE"></typeparam> /// <param name="url"></param> /// <returns></returns> public static UserControlInstance LoadUserControlFrom(string url) @@ -166,14 +162,13 @@ public void RegisterInterceptor(TypeInterceptor interceptor) { - addExpression( - delegate(PluginGraph pluginGraph) { pluginGraph.InterceptorLibrary.AddInterceptor(interceptor); }); + addExpression(pluginGraph => pluginGraph.InterceptorLibrary.AddInterceptor(interceptor)); } public MatchedTypeInterceptor IfTypeMatches(Predicate<Type> match) { MatchedTypeInterceptor interceptor = new MatchedTypeInterceptor(match); - _actions.Add(delegate(PluginGraph graph) { graph.InterceptorLibrary.AddInterceptor(interceptor); }); + _actions.Add(graph => graph.InterceptorLibrary.AddInterceptor(interceptor)); return interceptor; } @@ -191,12 +186,12 @@ public void AddInstanceOf(Type pluginType, Instance instance) { - _actions.Add(delegate(PluginGraph graph) { graph.FindFamily(pluginType).AddInstance(instance); }); + _actions.Add(graph => graph.FindFamily(pluginType).AddInstance(instance)); } public void AddInstanceOf<PLUGINTYPE>(Instance instance) { - _actions.Add(delegate(PluginGraph graph) { graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(instance); }); + _actions.Add(graph => graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(instance)); } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/RegistryExpressions.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/RegistryExpressions.cs 2008-06-07 22:48:46 UTC (rev 120) +++ trunk/Source/StructureMap/Configuration/DSL/RegistryExpressions.cs 2008-06-15 01:49:31 UTC (rev 121) @@ -53,7 +53,7 @@ public static ConstructorInstance ConstructedBy<PLUGINTYPE> (Func<PLUGINTYPE> builder) { - return new ConstructorInstance(delegate() { return builder(); }); + return new ConstructorInstance(() => builder()); } public static ReferencedInstance Instance(string referencedKey) Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-06-07 22:48:46 UTC (rev 120) +++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-06-15 01:49:31 UTC (rev 121) @@ -7,7 +7,7 @@ namespace StructureMap.Configuration { - public class FamilyParser + public class FamilyParser : XmlConstants { private readonly IGraphBuilder _builder; private readonly XmlMementoCreator _mementoCreator; @@ -21,26 +21,36 @@ public void ParseFamily(XmlElement familyElement) { TypePath typePath = TypePath.CreateFromXmlNode(familyElement); - _builder.ConfigureFamily(typePath, delegate(PluginFamily family) + _builder.ConfigureFamily(typePath, family => { family.DefaultInstanceKey = - familyElement.GetAttribute(XmlConstants.DEFAULT_KEY_ATTRIBUTE); + familyElement.GetAttribute(DEFAULT_KEY_ATTRIBUTE); InstanceScope scope = findScope(familyElement); family.SetScopeTo(scope); attachMementoSource(family, familyElement); - attachPlugins(family, familyElement); + familyElement.ForEachChild(PLUGIN_NODE).Do(element => attachPlugin(element, family)); attachInterceptors(family, familyElement); + attachInstances(family, familyElement, _builder); }); } + private void attachInstances(PluginFamily family, XmlElement familyElement, IGraphBuilder builder) + { + familyElement.ForEachChild(INSTANCE_NODE).Do(element => + { + InstanceMemento memento = _mementoCreator.CreateMemento(element); + family.AddInstance(memento); + }); + } + public void ParseDefaultElement(XmlElement element) { - TypePath pluginTypePath = new TypePath(element.GetAttribute(XmlConstants.PLUGIN_TYPE)); + TypePath pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE)); - _builder.ConfigureFamily(pluginTypePath, delegate(PluginFamily family) + _builder.ConfigureFamily(pluginTypePath, family => { InstanceScope scope = findScope(element); family.SetScopeTo(scope); @@ -52,9 +62,9 @@ public void ParseInstanceElement(XmlElement element) { - TypePath pluginTypePath = new TypePath(element.GetAttribute(XmlConstants.PLUGIN_TYPE)); + TypePath pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE)); - _builder.ConfigureFamily(pluginTypePath, delegate(PluginFamily family) + _builder.ConfigureFamily(pluginTypePath, family => { InstanceMemento memento = _mementoCreator.CreateMemento(element); @@ -66,79 +76,52 @@ { InstanceScope returnValue = InstanceScope.PerRequest; - string scopeString = familyElement.GetAttribute(XmlConstants.SCOPE_ATTRIBUTE); - if (!string.IsNullOrEmpty(scopeString)) + familyElement.ForAttributeValue(SCOPE, scope => { - returnValue = (InstanceScope) Enum.Parse(typeof (InstanceScope), scopeString); - } + returnValue = (InstanceScope)Enum.Parse(typeof(InstanceScope), scope); + }); return returnValue; } private void attachMementoSource(PluginFamily family, XmlElement familyElement) { - XmlNode sourceNode = familyElement[XmlConstants.MEMENTO_SOURCE_NODE]; - if (sourceNode != null) + familyElement.IfHasNode(MEMENTO_SOURCE_NODE).Do(node => { - InstanceMemento sourceMemento = new XmlAttributeInstanceMemento(sourceNode); + InstanceMemento sourceMemento = new XmlAttributeInstanceMemento(node); - string context = "MementoSource for " + TypePath.GetAssemblyQualifiedName(family.PluginType) + "\n" + - sourceNode.OuterXml; + string context = string.Format("MementoSource for {0}\n{1}", TypePath.GetAssemblyQualifiedName(family.PluginType), node.OuterXml); _builder.WithSystemObject<MementoSource>(sourceMemento, context, - delegate(MementoSource source) { family.AddMementoSource(source); }); - } + source => family.AddMementoSource(source)); + }); } - private void attachPlugins(PluginFamily family, XmlElement familyElement) - { - // TODO: 3.5 lambda cleanup - XmlNodeList pluginNodes = familyElement.SelectNodes(XmlConstants.PLUGIN_NODE); - foreach (XmlElement pluginElement in pluginNodes) - { - attachPlugin(pluginElement, family); - } - } - private void attachPlugin(XmlElement pluginElement, PluginFamily family) { TypePath pluginPath = TypePath.CreateFromXmlNode(pluginElement); - string concreteKey = pluginElement.GetAttribute(XmlConstants.CONCRETE_KEY_ATTRIBUTE); + string concreteKey = pluginElement.GetAttribute(CONCRETE_KEY_ATTRIBUTE); string context = "creating a Plugin for " + family.PluginType.AssemblyQualifiedName; - _builder.WithType(pluginPath, context, delegate(Type pluggedType) + _builder.WithType(pluginPath, context, pluggedType => { Plugin plugin = new Plugin(pluggedType, concreteKey); family.AddPlugin(plugin); - foreach ( - XmlElement setterElement in pluginElement.ChildNodes) - { - string setterName = - setterElement.GetAttribute("Name"); - plugin.Setters.Add(setterName); - } + pluginElement.ForTextInChild("Setter/@Name").Do(prop => plugin.Setters.Add(prop)); + }); } - // TODO: 3.5 lambda cleanup private void attachInterceptors(PluginFamily family, XmlElement familyElement) { - XmlNode interceptorChainNode = familyElement[XmlConstants.INTERCEPTORS_NODE]; - if (interceptorChainNode == null) + string contextBase = string.Format("creating an InstanceInterceptor for {0}\n", TypePath.GetAssemblyQualifiedName(family.PluginType)); + familyElement.ForEachChild("*/Interceptor").Do(element => { - return; - } - - string contextBase = "creating an InstanceInterceptor for " + - TypePath.GetAssemblyQualifiedName(family.PluginType) + "\n"; - foreach (XmlNode interceptorNode in interceptorChainNode.ChildNodes) - { - XmlAttributeInstanceMemento interceptorMemento = new XmlAttributeInstanceMemento(interceptorNode); - - string context = contextBase + interceptorNode.OuterXml; + var interceptorMemento = new XmlAttributeInstanceMemento(element); + string context = contextBase + element.OuterXml; _builder.WithSystemObject<IBuildInterceptor>(interceptorMemento, context, - delegate(IBuildInterceptor interceptor) { family.AddInterceptor(interceptor); }); - } + interceptor => family.AddInterceptor(interceptor)); + }); } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2008-06-07 22:48:46 UTC (rev 120) +++ trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2008-06-15 01:49:31 UTC (rev 121) @@ -1,3 +1,4 @@ +using System; using System.Xml; using StructureMap.Graph; using StructureMap.Pipeline; @@ -5,8 +6,7 @@ namespace StructureMap.Configuration { - // TODO: 3.5 cleanup - public class ProfileAndMachineParser + public class ProfileAndMachineParser : XmlConstants { private readonly XmlMementoCreator _creator; private readonly IGraphBuilder _graphBuilder; @@ -23,57 +23,47 @@ public void Parse() { - // TODO: 3.5 cleanup - XmlNode defaultProfileNode = _structureMapNode.Attributes.GetNamedItem(XmlConstants.DEFAULT_PROFILE); - if (defaultProfileNode != null) - { - _profileBuilder.SetDefaultProfileName(defaultProfileNode.InnerText); - } + _structureMapNode.ForAttributeValue(DEFAULT_PROFILE, profileName => _profileBuilder.SetDefaultProfileName(profileName)); - foreach (XmlElement profileElement in findNodes(XmlConstants.PROFILE_NODE)) + forEachNode(PROFILE_NODE).Do(element => { - string profileName = profileElement.GetAttribute(XmlConstants.NAME); + string profileName = element.GetAttribute(NAME); _profileBuilder.AddProfile(profileName); - writeOverrides(profileElement, - delegate(string fullName, string defaultKey) { _profileBuilder.OverrideProfile(new TypePath(fullName), defaultKey); }, profileName); - } + writeOverrides(element, + (fullName, defaultKey) => _profileBuilder.OverrideProfile(new TypePath(fullName), defaultKey), profileName); + }); - foreach (XmlElement machineElement in findNodes(XmlConstants.MACHINE_NODE)) + + forEachNode(MACHINE_NODE).Do(element => { - string machineName = machineElement.GetAttribute(XmlConstants.NAME); - string profileName = machineElement.GetAttribute(XmlConstants.PROFILE_NODE); + string machineName = element.GetAttribute(NAME); + string profileName = element.GetAttribute(PROFILE_NODE); _profileBuilder.AddMachine(machineName, profileName); - writeOverrides(machineElement, - delegate(string fullName, string defaultKey) { _profileBuilder.OverrideMachine(new TypePath(fullName), defaultKey); }, machineName); - } + writeOverrides(element, + (fullName, defaultKey) => _profileBuilder.OverrideMachine(new TypePath(fullName), defaultKey), machineName); + }); } private void writeOverrides(XmlElement parentElement, WriteOverride function, string profileName) { - foreach (XmlElement overrideElement in parentElement.SelectNodes(XmlConstants.OVERRIDE)) - { - processOverrideElement(function, overrideElement, profileName); - } + parentElement.ForEachChild(OVERRIDE).Do(element => processOverrideElement(function, element, profileName)); } private void processOverrideElement(WriteOverride function, XmlElement overrideElement, string profileName) { - string fullName = overrideElement.GetAttribute(XmlConstants.TYPE_ATTRIBUTE); + string fullName = overrideElement.GetAttribute(TYPE_ATTRIBUTE); - XmlElement instanceElement = (XmlElement) overrideElement.SelectSingleNode(XmlConstants.INSTANCE_NODE); - if (instanceElement == null) - { - string defaultKey = overrideElement.GetAttribute(XmlConstants.DEFAULT_KEY_ATTRIBUTE); - function(fullName, defaultKey); - } - else - { - createOverrideInstance(fullName, instanceElement, function, profileName); - } + overrideElement.IfHasNode(INSTANCE_NODE) + .Do(element => createOverrideInstance(fullName, element, function, profileName)) + .Else(() => + { + string defaultKey = overrideElement.GetAttribute(DEFAULT_KEY_ATTRIBUTE); + function(fullName, defaultKey); + }); } private void createOverrideInstance(string fullName, XmlElement instanceElement, WriteOverride function, @@ -85,16 +75,16 @@ TypePath familyPath = new TypePath(fullName); - _graphBuilder.ConfigureFamily(familyPath, delegate(PluginFamily family) - { - family.AddInstance(memento); - function(fullName, key); - }); + _graphBuilder.ConfigureFamily(familyPath, family => + { + family.AddInstance(memento); + function(fullName, key); + }); } - private XmlNodeList findNodes(string nodeName) + private XmlExtensions.XmlNodeExpression forEachNode(string xpath) { - return _structureMapNode.SelectNodes(nodeName); + return _structureMapNode.ForEachChild(xpath); } #region Nested type: WriteOverride Modified: trunk/Source/StructureMap/Configuration/ProfileBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ProfileBuilder.cs 2008-06-07 22:48:46 UTC (rev 120) +++ trunk/Source/StructureMap/Configuration/ProfileBuilder.cs 2008-06-15 01:49:31 UTC (rev 121) @@ -47,10 +47,10 @@ public void OverrideProfile(TypePath typePath, string instanceKey) { - _pluginGraph.Log.WithType(typePath, "while trying to add an override for a Profile", delegate(Type pluginType) + _pluginGraph.Log.WithType(typePath, "while trying to add an override for a Profile", pluginType => { ReferencedInstance instance = new ReferencedInstance(instanceKey); - _pluginGraph.SetDefault(_lastProfile, pluginType, instance); + _pluginGraph.SetDefault(_lastProfile, pluginType, instance); }); } @@ -72,12 +72,12 @@ } _pluginGraph.Log.WithType(typePath, - "trying to configure a Machine Override", - delegate(Type pluginType) - { - ReferencedInstance instance = new ReferencedInstance(instanceKey); - _profileManager.SetMachineDefault(pluginType, instance); - }); + "trying to configure a Machine Override", + pluginType => + { + ReferencedInstance instance = new ReferencedInstance(instanceKey); + _profileManager.SetMachineDefault(pluginType, instance); + }); } public void SetDefaultProfileName(string profileName) Modified: trunk/Source/StructureMap/Configuration/XmlConstants.cs =================================================================== --- trunk/Source/StructureMap/Configuration/XmlConstants.cs 2008-06-07 22:48:46 UTC (rev 120) +++ trunk/Source/StructureMap/Configuration/XmlConstants.cs 2008-06-15 01:49:31 UTC (rev 121) @@ -29,13 +29,8 @@ public const string PLUGIN_NODE = "Plugin"; public const string PLUGIN_TYPE = "PluginType"; public const string PROFILE_NODE = "Profile"; - public const string SCOPE_ATTRIBUTE = "Scope"; + public const string SCOPE = "Scope"; public const string STRUCTUREMAP = "StructureMap"; public const string TYPE_ATTRIBUTE = "Type"; - - - private XmlConstants() - { - } } } \ No newline at end of file Added: trunk/Source/StructureMap/Configuration/XmlExtensions.cs =================================================================== --- trunk/Source/StructureMap/Configuration/XmlExtensions.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/XmlExtensions.cs 2008-06-15 01:49:31 UTC (rev 121) @@ -0,0 +1,103 @@ +using System; +using System.Xml; + +namespace StructureMap.Configuration +{ + public static class XmlExtensions + { + public static XmlTextExpression ForTextInChild(this XmlNode node, string xpath) + { + return new XmlTextExpression(node, xpath); + } + + public static XmlNodeExpression ForEachChild(this XmlNode node, string xpath) + { + return new XmlNodeExpression(node, xpath); + } + + public static void ForAttributeValue(this XmlNode node, string attributeName, Action<string> action) + { + XmlNode attNode = node.Attributes.GetNamedItem(attributeName); + if (attNode != null) + { + action(attNode.InnerText); + } + } + + public static HasXmlElementExpression IfHasNode(this XmlNode node, string xpath) + { + return new HasXmlElementExpression(node, xpath); + } + + public class HasXmlElementExpression + { + private XmlElement _element; + + internal HasXmlElementExpression(XmlNode parent, string xpath) + { + _element = (XmlElement)parent.SelectSingleNode(xpath); + } + + public HasXmlElementExpression Do(Action<XmlElement> action) + { + if (_element != null) + { + action(_element); + } + + return this; + } + + public void Else(Action action) + { + if (_element == null) + { + action(); + } + } + } + + + public class XmlNodeExpression + { + private XmlNodeList _list; + + internal XmlNodeExpression(XmlNode parent, string xpath) + { + _list = parent.SelectNodes(xpath); + } + + public void Do(Action<XmlElement> action) + { + if (_list == null) return; + + foreach (XmlNode node in _list) + { + action((XmlElement)node); + } + } + } + + public class XmlTextExpression + { + private readonly XmlNodeList _list; + + internal XmlTextExpression(XmlNode parent, string attributePath) + { + _list = parent.SelectNodes(attributePath); + } + + public void Do(Action<string> action) + { + if (_list == null) return; + + foreach (XmlNode node in _list) + { + action(node.InnerText); + } + } + } + + + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Diagnostics/BuildError.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/BuildError.cs 2008-06-07 22:48:46 UTC (rev 120) +++ trunk/Source/StructureMap/Diagnostics/BuildError.cs 2008-06-15 01:49:31 UTC (rev 121) @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.IO; +using StructureMap.Graph; using StructureMap.Pipeline; namespace StructureMap.Diagnostics @@ -76,5 +78,16 @@ get { return _exception; } set { _exception = value; } } + + public void Write(StringWriter writer) + { + string description = ((IDiagnosticInstance)Instance).CreateToken().Description; + + writer.WriteLine(); + writer.WriteLine("-----------------------------------------------------------------------------------------------------"); + writer.WriteLine("Build Error on Instance '{0}' ({1}) in PluginType {2}", Instance.Name, description, TypePath.GetAssemblyQualifiedName(PluginType)); + if (Exception != null) writer.WriteLine(Exception.ToString()); + writer.WriteLine(); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Diagnostics/Doctor.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/Doctor.cs 2008-06-07 22:48:46 UTC (rev 120) +++ trunk/Source/StructureMap/Diagnostics/Doctor.cs 2008-06-15 01:49:31 UTC (rev 121) @@ -1,48 +1,88 @@ using System; using System.Collections.Generic; +using System.Diagnostics; +using System.IO; using System.Text; -using StructureMap.Graph; namespace StructureMap.Diagnostics { - - - public class DoctorReport + public class... [truncated message content] |
From: <jer...@us...> - 2008-06-07 22:48:48
|
Revision: 120 http://structuremap.svn.sourceforge.net/structuremap/?rev=120&view=rev Author: jeremydmiller Date: 2008-06-07 15:48:46 -0700 (Sat, 07 Jun 2008) Log Message: ----------- missed a file or two Added Paths: ----------- trunk/Source/StructureMap/Diagnostics/Doctor.cs trunk/Source/StructureMap/IBootstrapper.cs Added: trunk/Source/StructureMap/Diagnostics/Doctor.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/Doctor.cs (rev 0) +++ trunk/Source/StructureMap/Diagnostics/Doctor.cs 2008-06-07 22:48:46 UTC (rev 120) @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Text; +using StructureMap.Graph; + +namespace StructureMap.Diagnostics +{ + + + public class DoctorReport + { + public string Message; + public bool Failure; + } + + public class DoctorRunner : MarshalByRefObject + { + public override object InitializeLifetimeService() + { + return null; + } + + public DoctorReport RunReport(string bootstrapperTypeName) + { + // TODO: bootstrapperType cannot be found + // TODO: bootstrapperType blows up + TypePath path = new TypePath(bootstrapperTypeName); + Type bootstrapperType = path.FindType(); + + IBootstrapper bootstrapper = (IBootstrapper) Activator.CreateInstance(bootstrapperType); + + // TODO - random error + PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); + + // TODO -- Fails on constructor + if (graph.Log.ErrorCount > 0) + { + + } + + + } + } + + public class Doctor + { + } +} Added: trunk/Source/StructureMap/IBootstrapper.cs =================================================================== --- trunk/Source/StructureMap/IBootstrapper.cs (rev 0) +++ trunk/Source/StructureMap/IBootstrapper.cs 2008-06-07 22:48:46 UTC (rev 120) @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace StructureMap +{ + public interface IBootstrapper + { + void BootstrapStructureMap(); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-06-07 22:28:54
|
Revision: 119 http://structuremap.svn.sourceforge.net/structuremap/?rev=119&view=rev Author: jeremydmiller Date: 2008-06-07 15:28:52 -0700 (Sat, 07 Jun 2008) Log Message: ----------- diagnostics - wip Modified Paths: -------------- trunk/Source/StructureMap/Diagnostics/GraphLog.cs trunk/Source/StructureMap/StructureMap.csproj Modified: trunk/Source/StructureMap/Diagnostics/GraphLog.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/GraphLog.cs 2008-06-05 13:32:32 UTC (rev 118) +++ trunk/Source/StructureMap/Diagnostics/GraphLog.cs 2008-06-07 22:28:52 UTC (rev 119) @@ -63,12 +63,12 @@ return; } - string message = WriteFailures(); + string message = BuildFailureMessage(); throw new StructureMapConfigurationException(message); } - private string WriteFailures() + public string BuildFailureMessage() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-06-05 13:32:32 UTC (rev 118) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-06-07 22:28:52 UTC (rev 119) @@ -373,8 +373,10 @@ <None Include="..\structuremap.snk"> <Link>Properties\structuremap.snk</Link> </None> + <Compile Include="Diagnostics\Doctor.cs" /> <Compile Include="ErrorMessages.cs" /> <Compile Include="Graph\ITypeScanner.cs" /> + <Compile Include="IBootstrapper.cs" /> <Compile Include="Pipeline\ConfiguredInstance.Building.cs" /> <Compile Include="Pipeline\IStructuredInstance.cs" /> <Compile Include="Util\Cache.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-06-05 13:32:35
|
Revision: 118 http://structuremap.svn.sourceforge.net/structuremap/?rev=118&view=rev Author: jeremydmiller Date: 2008-06-05 06:32:32 -0700 (Thu, 05 Jun 2008) Log Message: ----------- missed checkin stuff Modified Paths: -------------- trunk/Source/StructureMap/ObjectFactory.cs Added Paths: ----------- trunk/Source/StructureMap.Testing/Graph/ExceptionHandling/ trunk/Source/StructureMap.Testing/Graph/ExceptionHandling/StructureMapExceptionTester.cs trunk/Source/StructureMap.Testing/Graph/Interceptors/ trunk/Source/StructureMap.Testing/Graph/Interceptors/CompoundInterceptorTester.cs trunk/Source/StructureMap.Testing/Graph/Interceptors/InterceptorLibraryTester.cs trunk/Source/StructureMap.Testing/Graph/Interceptors/MockTypeInterceptor.cs trunk/Source/StructureMap.Testing/Graph/Interceptors/TypeInterceptionTester.cs Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-06-02 16:28:50 UTC (rev 117) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-06-05 13:32:32 UTC (rev 118) @@ -33,6 +33,19 @@ } /// <summary> + /// Restarts ObjectFactory and blows away all Singleton's and cached instances. Use with caution. + /// </summary> + public static void Reset() + { + _manager = buildManager(); + + if (_notify != null) + { + _notify(); + } + } + + /// <summary> /// Attempts to create a new instance of the requested type. Automatically inserts the default /// configured instance for each dependency in the StructureMap constructor function. /// </summary> @@ -70,7 +83,12 @@ manager.InjectStub(typeof (PLUGINTYPE), stub); } + public static void InjectStub<PLUGINTYPE>(string name, PLUGINTYPE stub) + { + manager.InjectStub<PLUGINTYPE>(name, stub); + } + public static string WhatDoIHave() { return manager.WhatDoIHave(); @@ -124,18 +142,7 @@ get { return _profile; } } - /// <summary> - /// Restarts ObjectFactory. Use with caution. - /// </summary> - public static void Reset() - { - _manager = buildManager(); - if (_notify != null) - { - _notify(); - } - } /// <summary> /// Strictly used for testing scenarios @@ -178,7 +185,8 @@ /// <summary> - /// Restores all default instance settings according to the StructureMap.config files + /// Restores all default instance settings and removes any Profile settings applied + /// at runtime /// </summary> public static void ResetDefaults() { Added: trunk/Source/StructureMap.Testing/Graph/ExceptionHandling/StructureMapExceptionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/ExceptionHandling/StructureMapExceptionTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/ExceptionHandling/StructureMapExceptionTester.cs 2008-06-05 13:32:32 UTC (rev 118) @@ -0,0 +1,237 @@ +using System; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; +using System.Xml; +using NUnit.Framework; +using StructureMap.Configuration; +using StructureMap.Graph; +using StructureMap.Testing.TestData; +using StructureMap.Testing.Widget; + +namespace StructureMap.Testing.Graph.ExceptionHandling +{ + [TestFixture] + public class StructureMapExceptionTester + { + private void assertErrorIsLogged(int errorCode, string xml) + { + PluginGraph graph = DataMother.BuildPluginGraphFromXml(xml); + graph.Log.AssertHasError(errorCode); + } + + + private void assertErrorIsThrown(int errorCode, string xml, Action<Container> action) + { + XmlDocument document = new XmlDocument(); + document.LoadXml(xml.Replace("\"", "'")); + + ConfigurationParser parser = new ConfigurationParser(document.DocumentElement); + PluginGraphBuilder builder = new PluginGraphBuilder(parser); + Container manager = new Container(builder.Build()); + + try + { + action(manager); + Assert.Fail("Should have thrown exception"); + } + catch (StructureMapException ex) + { + Assert.AreEqual(errorCode, ex.ErrorCode, "Expected error code"); + } + } + + [Test] + public void CanSerialize() + { + ApplicationException ex = new ApplicationException("Oh no!"); + StructureMapException smapEx = new StructureMapException(200, ex, "a", "b"); + + BinaryFormatter formatter = new BinaryFormatter(); + MemoryStream stream = new MemoryStream(); + formatter.Serialize(stream, smapEx); + + stream.Position = 0; + + StructureMapException smapEx2 = (StructureMapException) formatter.Deserialize(stream); + Assert.AreNotSame(smapEx, smapEx2); + + Assert.AreEqual(smapEx.Message, smapEx2.Message); + } + + [Test] + public void CouldNotFindConcreteKey() + { + assertErrorIsLogged(201, + @" + <StructureMap> + <Assembly Name='StructureMap.Testing.Widget'/> + + <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''> + <Instance Key='BadConcreteKey' Type='NotARealConcreteKey'></Instance> + </PluginFamily> + </StructureMap> + "); + } + + [Test] + public void CouldNotFindInstanceKey() + { + assertErrorIsThrown(200, + @" + <StructureMap> + <Assembly Name='StructureMap.Testing.Widget'/> + + <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''> </PluginFamily> + </StructureMap> + ", + delegate(Container manager) { manager.GetInstance<IWidget>("NotAnActualInstanceName"); } + ); + } + + [Test] + public void CouldNotUpcastDesignatedPluggedTypeIntoPluginType() + { + assertErrorIsLogged(104, + @" + <StructureMap> + <Assembly Name='StructureMap.Testing.Widget'/> + + <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''> + <Plugin Assembly='StructureMap.Testing.Widget' Type='StructureMap.Testing.Widget.ComplexRule' ConcreteKey='Rule'/> + </PluginFamily> + </StructureMap> + "); + } + + [Test] + public void ExceptionMessage() + { + StructureMapException exception = new StructureMapException(100, "StructureMap.config"); + string expected = + "StructureMap Exception Code: 100\nExpected file \"StructureMap.config\" cannot be opened at StructureMap.config"; + + string actual = exception.Message; + + Assert.AreEqual(expected, actual); + } + + [Test] + public void Log_101_if_CannotLoadAssemblyInAssemblyNode() + { + assertErrorIsLogged(101, + @" + <StructureMap> + <Assembly Name='StructureMap.NonExistent'/> + </StructureMap> + "); + } + + + [Test] + public void Log_103_CannotLoadTypeFromPluginFamilyNode() + { + assertErrorIsLogged(103, + @" + <StructureMap> + <PluginFamily Assembly='StructureMap.Testing.Widget' Type='StructureMap.Testing.Widget.NotARealType'/> + </StructureMap> + "); + } + + [Test] + public void Log_112_if_MissingConcreteKeyOnPluginNode() + { + assertErrorIsLogged(112, + @" + <StructureMap> + <Assembly Name='StructureMap.Testing.Widget'/> + + <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''> + <Plugin Assembly='StructureMap.Testing.Widget' Type='StructureMap.Testing.Widget.NotPluggableWidget' ConcreteKey=''/> + </PluginFamily> + </StructureMap> +"); + } + + [Test] + public void Log_113_if_a_duplicate_Plugin_ConcreteKey_is_detected() + { + assertErrorIsLogged(113, + @" + + <StructureMap> + <Assembly Name='StructureMap.Testing.Widget'/> + + <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''> + <Plugin Assembly='StructureMap.Testing.Widget' Type='StructureMap.Testing.Widget.NotPluggableWidget' ConcreteKey='Dup'/> + <Plugin Assembly='StructureMap.Testing.Widget' Type='StructureMap.Testing.Widget.NotPluggableWidget' ConcreteKey='Dup'/> + </PluginFamily> + </StructureMap> + +"); + } + + [Test] + public void Log_130_if_an_error_occurs_when_trying_to_create_an_interceptor_configured_in_xml() + { + assertErrorIsLogged(130, + @" + <StructureMap> + <Assembly Name='StructureMap.Testing.Widget'/> + + <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''> + <Interceptors> + <Interceptor Type='NotARealType'></Interceptor> + </Interceptors> + </PluginFamily> + </StructureMap> +"); + } + + [Test] + public void Log_130_if_there_is_an_error_while_creating_TheDesignatedMementoSourceForAPluginFamily() + { + assertErrorIsLogged(130, + @" + <StructureMap> + <Assembly Name='StructureMap.Testing.Widget'/> + + <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''> + <Plugin Assembly='StructureMap.Testing.Widget' Type='StructureMap.Testing.Widget.NotPluggableWidget' ConcreteKey='Dup'/> + <Source Type='Nonexistent'/> + </PluginFamily> + </StructureMap> +"); + } + + [Test] + public void Log_131_if_Plugin_type_could_not_be_loaded_from_Xml_configuration() + { + assertErrorIsLogged(131, + @" + <StructureMap> + <Assembly Name='StructureMap.Testing.Widget'/> + + <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''> + <Plugin Assembly='StructureMap.Testing' Type='StructureMap.Testing.Widget.NotARealClass' ConcreteKey='NotReal'/> + </PluginFamily> + </StructureMap> + "); + } + + [Test] + public void Throw_202_when_DefaultKeyDoesNotExist() + { + assertErrorIsThrown(202, + @" + <StructureMap> + <Assembly Name='StructureMap.Testing.Widget'/> + + <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''></PluginFamily> + </StructureMap> + ", + delegate(Container manager) { manager.GetInstance<IWidget>(); } + ); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Interceptors/CompoundInterceptorTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Interceptors/CompoundInterceptorTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Interceptors/CompoundInterceptorTester.cs 2008-06-05 13:32:32 UTC (rev 118) @@ -0,0 +1,46 @@ +using NUnit.Framework; +using Rhino.Mocks; +using StructureMap.Interceptors; + +namespace StructureMap.Testing.Graph.Interceptors +{ + [TestFixture] + public class CompoundInterceptorTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + } + + #endregion + + [Test] + public void CallAllTheInterceptors() + { + MockRepository mocks = new MockRepository(); + InstanceInterceptor interceptor1 = mocks.CreateMock<InstanceInterceptor>(); + InstanceInterceptor interceptor2 = mocks.CreateMock<InstanceInterceptor>(); + InstanceInterceptor interceptor3 = mocks.CreateMock<InstanceInterceptor>(); + InstanceInterceptor interceptor4 = mocks.CreateMock<InstanceInterceptor>(); + + Expect.Call(interceptor1.Process("0")).Return("1"); + Expect.Call(interceptor2.Process("1")).Return("2"); + Expect.Call(interceptor3.Process("2")).Return("3"); + Expect.Call(interceptor4.Process("3")).Return("4"); + + mocks.ReplayAll(); + CompoundInterceptor compoundInterceptor = new CompoundInterceptor(new InstanceInterceptor[] + { + interceptor1, + interceptor2, + interceptor3, + interceptor4 + }); + + Assert.AreEqual("4", compoundInterceptor.Process("0")); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Interceptors/InterceptorLibraryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Interceptors/InterceptorLibraryTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Interceptors/InterceptorLibraryTester.cs 2008-06-05 13:32:32 UTC (rev 118) @@ -0,0 +1,156 @@ +using System; +using NUnit.Framework; +using Rhino.Mocks; +using StructureMap.Interceptors; + +namespace StructureMap.Testing.Graph.Interceptors +{ + [TestFixture] + public class InterceptorLibraryTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + _interceptor1 = new MockTypeInterceptor(typeof (string)); + _interceptor2 = new MockTypeInterceptor(typeof (int), typeof (double)); + _interceptor3 = new MockTypeInterceptor(typeof (string), typeof (bool)); + _interceptor4 = new MockTypeInterceptor(typeof (string), typeof (double)); + + _library = new InterceptorLibrary(); + _library.AddInterceptor(_interceptor1); + _library.AddInterceptor(_interceptor2); + _library.AddInterceptor(_interceptor3); + _library.AddInterceptor(_interceptor4); + } + + #endregion + + private MockTypeInterceptor _interceptor1; + private MockTypeInterceptor _interceptor2; + private MockTypeInterceptor _interceptor3; + private MockTypeInterceptor _interceptor4; + private InterceptorLibrary _library; + + [Test] + public void Find_All_Of_The_Interceptors_For_A_Type_On_Multiple_Passes() + { + Assert.AreEqual(new TypeInterceptor[] {_interceptor1, _interceptor3, _interceptor4}, + _library.FindInterceptors(typeof (string))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2, _interceptor4}, + _library.FindInterceptors(typeof (double))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2}, _library.FindInterceptors(typeof (int))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor3}, _library.FindInterceptors(typeof (bool))); + + Assert.AreEqual(new TypeInterceptor[] {_interceptor1, _interceptor3, _interceptor4}, + _library.FindInterceptors(typeof (string))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2, _interceptor4}, + _library.FindInterceptors(typeof (double))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2}, _library.FindInterceptors(typeof (int))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor3}, _library.FindInterceptors(typeof (bool))); + + Assert.AreEqual(new TypeInterceptor[] {_interceptor1, _interceptor3, _interceptor4}, + _library.FindInterceptors(typeof (string))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2, _interceptor4}, + _library.FindInterceptors(typeof (double))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2}, _library.FindInterceptors(typeof (int))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor3}, _library.FindInterceptors(typeof (bool))); + + Assert.AreEqual(new TypeInterceptor[] {_interceptor1, _interceptor3, _interceptor4}, + _library.FindInterceptors(typeof (string))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2, _interceptor4}, + _library.FindInterceptors(typeof (double))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2}, _library.FindInterceptors(typeof (int))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor3}, _library.FindInterceptors(typeof (bool))); + } + + [Test] + public void Find_All_Of_The_Interceptors_For_A_Type_On_The_First_Pass() + { + Assert.AreEqual(new TypeInterceptor[] {_interceptor1, _interceptor3, _interceptor4}, + _library.FindInterceptors(typeof (string))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2, _interceptor4}, + _library.FindInterceptors(typeof (double))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2}, _library.FindInterceptors(typeof (int))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor3}, _library.FindInterceptors(typeof (bool))); + } + + [Test] + public void Find_CompoundInterceptor_For_A_Type_On_The_First_Pass() + { + Assert.AreEqual(new TypeInterceptor[] {_interceptor1, _interceptor3, _interceptor4}, + _library.FindInterceptor(typeof (string)).Interceptors); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2, _interceptor4}, + _library.FindInterceptor(typeof (double)).Interceptors); + } + + [Test] + public void Import_from_gets_all_interceptors_and_resets_the_type_filter() + { + InterceptorLibrary sourceLibrary = new InterceptorLibrary(); + sourceLibrary.AddInterceptor(new MockTypeInterceptor(typeof (string))); + sourceLibrary.FindInterceptor(typeof (string)); + + InterceptorLibrary destinationLibrary = new InterceptorLibrary(); + destinationLibrary.AddInterceptor(new MockTypeInterceptor(typeof (string))); + + destinationLibrary.ImportFrom(sourceLibrary); + + InstanceInterceptor[] interceptors = destinationLibrary.FindInterceptors(typeof (string)); + Assert.AreEqual(2, interceptors.Length); + } + + + [Test] + public void + When_Interceptors_Are_Requested_For_A_Type_For_The_First_Time_The_Library_Will_Scan_All_The_TypeInterceptors + () + { + MockRepository mocks = new MockRepository(); + TypeInterceptor interceptor1 = mocks.CreateMock<TypeInterceptor>(); + TypeInterceptor interceptor2 = mocks.CreateMock<TypeInterceptor>(); + TypeInterceptor interceptor3 = mocks.CreateMock<TypeInterceptor>(); + + _library.AddInterceptor(interceptor1); + _library.AddInterceptor(interceptor2); + _library.AddInterceptor(interceptor3); + + Type type = typeof (string); + Expect.Call(interceptor1.MatchesType(type)).Return(true); + Expect.Call(interceptor2.MatchesType(type)).Return(true); + Expect.Call(interceptor3.MatchesType(type)).Return(true); + + mocks.ReplayAll(); + _library.FindInterceptors(type); + mocks.VerifyAll(); + } + + [Test] + public void When_Interceptors_Are_Requested_For_The_Second_Time_The_Library_Will_NOT_Scan_The_Interceptors_Again + () + { + MockRepository mocks = new MockRepository(); + TypeInterceptor interceptor1 = mocks.CreateMock<TypeInterceptor>(); + TypeInterceptor interceptor2 = mocks.CreateMock<TypeInterceptor>(); + TypeInterceptor interceptor3 = mocks.CreateMock<TypeInterceptor>(); + + _library.AddInterceptor(interceptor1); + _library.AddInterceptor(interceptor2); + _library.AddInterceptor(interceptor3); + + Type type = typeof (string); + Expect.Call(interceptor1.MatchesType(type)).Return(true); + Expect.Call(interceptor2.MatchesType(type)).Return(true); + Expect.Call(interceptor3.MatchesType(type)).Return(true); + + mocks.ReplayAll(); + _library.FindInterceptors(type); + _library.FindInterceptors(type); + _library.FindInterceptors(type); + _library.FindInterceptors(type); + _library.FindInterceptors(type); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Interceptors/MockTypeInterceptor.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Interceptors/MockTypeInterceptor.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Interceptors/MockTypeInterceptor.cs 2008-06-05 13:32:32 UTC (rev 118) @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using StructureMap.Interceptors; + +namespace StructureMap.Testing.Graph.Interceptors +{ + public class MockTypeInterceptor : TypeInterceptor + { + #region Delegates + + public delegate object InterceptionDelegate<T>(T target); + + #endregion + + private readonly Dictionary<Type, InstanceInterceptor> _innerInterceptors + = new Dictionary<Type, InstanceInterceptor>(); + + private readonly List<Type> _types = new List<Type>(); + + public MockTypeInterceptor(params Type[] types) + { + _types.AddRange(types); + } + + #region TypeInterceptor Members + + public bool MatchesType(Type type) + { + return _types.Contains(type); + } + + public object Process(object target) + { + return _innerInterceptors[target.GetType()].Process(target); + } + + #endregion + + public void SetToMatch<T>() + { + _types.Add(typeof (T)); + } + + public void AddHandler<T>(InterceptionDelegate<T> handler) + { + _types.Add(typeof (T)); + _innerInterceptors.Add(typeof (T), new CommonInterceptor<T>(handler)); + } + + #region Nested type: CommonInterceptor + + public class CommonInterceptor<T> : InstanceInterceptor + { + private readonly InterceptionDelegate<T> _handler; + + public CommonInterceptor(InterceptionDelegate<T> handler) + { + _handler = handler; + } + + #region InstanceInterceptor Members + + public object Process(object target) + { + return _handler((T) target); + } + + #endregion + } + + #endregion + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Interceptors/TypeInterceptionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Interceptors/TypeInterceptionTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Interceptors/TypeInterceptionTester.cs 2008-06-05 13:32:32 UTC (rev 118) @@ -0,0 +1,119 @@ +using System; +using NUnit.Framework; +using StructureMap.Configuration.DSL; + +namespace StructureMap.Testing.Graph.Interceptors +{ + [TestFixture] + public class TypeInterceptionTester : Registry + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + manager = null; + + registry = new Registry(); + registry.ForRequestedType<IAnInterfaceOfSomeSort>() + .AddInstance(Instance<RedSomething>().WithName("Red")) + .AddInstance(Instance<GreenSomething>().WithName("Green")) + .AddInstance(Instance<BlueSomething>().WithName("Blue")); + } + + #endregion + + private Registry registry; + private IContainer manager; + + private void assertThisIsType<T>(string name) + { + if (manager == null) + { + manager = new Container(registry); + } + + Assert.IsInstanceOfType(typeof (T), manager.GetInstance<IAnInterfaceOfSomeSort>(name)); + } + + private void assertThatThisIsWrappedSomething<OUTERTYPE, INNERTYPE>(string name) + where OUTERTYPE : WrappedSomething + { + if (manager == null) + { + manager = new Container(registry); + } + + OUTERTYPE something = (OUTERTYPE) manager.GetInstance<IAnInterfaceOfSomeSort>(name); + Assert.IsInstanceOfType(typeof (INNERTYPE), something.Inner); + } + + public interface IAnInterfaceOfSomeSort + { + } + + public class RedSomething : IAnInterfaceOfSomeSort + { + } + + public class GreenSomething : IAnInterfaceOfSomeSort + { + } + + public class BlueSomething : IAnInterfaceOfSomeSort + { + } + + public class WrappedSomething : IAnInterfaceOfSomeSort + { + private readonly IAnInterfaceOfSomeSort _inner; + + public WrappedSomething(IAnInterfaceOfSomeSort inner) + { + _inner = inner; + } + + + public IAnInterfaceOfSomeSort Inner + { + get { return _inner; } + } + } + + public class WrappedSomething2 : WrappedSomething + { + public WrappedSomething2(IAnInterfaceOfSomeSort inner) : base(inner) + { + } + } + + [Test] + public void If_An_Interceptor_Is_Registered_At_The_PluginGraph_It_Will_Be_Used_To_Construct_An_Instance() + { + MockTypeInterceptor interceptor = new MockTypeInterceptor(); + interceptor.AddHandler<RedSomething>( + delegate(RedSomething something) { return new WrappedSomething(something); }); + + interceptor.AddHandler<GreenSomething>( + delegate(GreenSomething something) { return new WrappedSomething2(something); }); + + registry.RegisterInterceptor(interceptor); + + assertThisIsType<BlueSomething>("Blue"); + assertThatThisIsWrappedSomething<WrappedSomething, RedSomething>("Red"); + assertThatThisIsWrappedSomething<WrappedSomething2, GreenSomething>("Green"); + } + + [Test] + public void Register_A_Type_Interceptor_By_The_Fluent_Interface() + { + registry.IfTypeMatches(delegate(Type type) { return type.Equals(typeof (BlueSomething)); }) + .InterceptWith( + delegate(object rawInstance) { return new WrappedSomething((IAnInterfaceOfSomeSort) rawInstance); }); + + assertThisIsType<RedSomething>("Red"); + assertThisIsType<GreenSomething>("Green"); + assertThatThisIsWrappedSomething<WrappedSomething, BlueSomething>("Blue"); + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-06-02 16:28:53
|
Revision: 117 http://structuremap.svn.sourceforge.net/structuremap/?rev=117&view=rev Author: jeremydmiller Date: 2008-06-02 09:28:50 -0700 (Mon, 02 Jun 2008) Log Message: ----------- fixed svn move Added Paths: ----------- trunk/Source/StructureMap.Testing/Graph/Source/ trunk/Source/StructureMap.Testing/Graph/Source/DirectoryXmlMementoSourceTester.cs trunk/Source/StructureMap.Testing/Graph/Source/EmbeddedFolderXmlMementoSourceTester.cs trunk/Source/StructureMap.Testing/Graph/Source/EmbeddedMementoFile.xml trunk/Source/StructureMap.Testing/Graph/Source/MachineXmlMementoSourceTester.cs trunk/Source/StructureMap.Testing/Graph/Source/Mementos/ trunk/Source/StructureMap.Testing/Graph/Source/Mementos/Instance1.xml trunk/Source/StructureMap.Testing/Graph/Source/Mementos/Instance2.xml trunk/Source/StructureMap.Testing/Graph/Source/SingleEmbeddedXmlMementoSourceTester.cs trunk/Source/StructureMap.Testing/Graph/Source/TemplatingTester.cs trunk/Source/StructureMap.Testing/Graph/Source/XmlAttributeInstanceMementoTester.cs trunk/Source/StructureMap.Testing/Graph/Source/XmlInstanceMementoTester.cs trunk/Source/StructureMap.Testing/Graph/Source/XmlMementoSourceTester.cs trunk/Source/StructureMap.Testing/Graph/Source/XmlTemplaterTester.cs Added: trunk/Source/StructureMap.Testing/Graph/Source/DirectoryXmlMementoSourceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/DirectoryXmlMementoSourceTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/DirectoryXmlMementoSourceTester.cs 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,72 @@ +using System; +using System.IO; +using NUnit.Framework; +using StructureMap.Source; + +namespace StructureMap.Testing.Graph.Source +{ + [TestFixture] + public class DirectoryXmlMementoSourceTester + { + private DirectoryXmlMementoSource _source; + + + [TestFixtureSetUp] + public void TestFixtureSetUp() + { + Directory.CreateDirectory("MementoDirectory"); + + string instance1 = + "<Instance Key=\"Red\" Type=\"Color\"><Property Name=\"Color\" Value=\"Red\" /></Instance>"; + string instance2 = + "<Instance Key=\"Blue\" Type=\"Color\"><Property Name=\"Color\" Value=\"Blue\" /></Instance>"; + string instance3 = + "<Instance Key=\"Bigger\" Type=\"GreaterThan\"><Property Name=\"Attribute\" Value=\"MyDad\" /><Property Name=\"Value\" Value=\"10\" /></Instance>"; + + writeFile(instance1, @"MementoDirectory\Red.xml"); + writeFile(instance2, @"MementoDirectory\Blue.xml"); + writeFile(instance3, @"MementoDirectory\Bigger.xml"); + + _source = new DirectoryXmlMementoSource("MementoDirectory", "xml", XmlMementoStyle.NodeNormalized); + } + + private void writeFile(string text, string path) + { + FileInfo fileInfo = new FileInfo(path); + StreamWriter writer = fileInfo.CreateText(); + writer.Write(text); + + writer.Close(); + } + + [Test] + public void CanGetAllMementos() + { + InstanceMemento[] mementos = _source.GetAllMementos(); + Assert.IsNotNull(mementos); + Assert.AreEqual(3, mementos.Length); + } + + [Test] + public void GetRedInstance() + { + InstanceMemento memento = _source.GetMemento("Red"); + Assert.IsNotNull(memento); + Assert.AreEqual("Red", memento.GetProperty("Color")); + } + + [Test, ExpectedException(typeof (ApplicationException))] + public void ValidateIsNotSuccessfulWithADirectoryItCannotFind() + { + DirectoryXmlMementoSource source = + new DirectoryXmlMementoSource("NotARealDirectory", "xml", XmlMementoStyle.NodeNormalized); + source.Validate(); + } + + [Test] + public void ValidateIsSuccessfulWithAnExistingDirectory() + { + _source.Validate(); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Source/EmbeddedFolderXmlMementoSourceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/EmbeddedFolderXmlMementoSourceTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/EmbeddedFolderXmlMementoSourceTester.cs 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,45 @@ +using System.Reflection; +using NUnit.Framework; +using StructureMap.Source; + +namespace StructureMap.Testing.Graph.Source +{ + [TestFixture] + public class EmbeddedFolderXmlMementoSourceTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + string folderPath = GetType().FullName.Replace(GetType().Name, "Mementos"); + string assemblyName = Assembly.GetExecutingAssembly().FullName; + _source = + new EmbeddedFolderXmlMementoSource(XmlMementoStyle.AttributeNormalized, assemblyName, folderPath, "xml"); + } + + #endregion + + private EmbeddedFolderXmlMementoSource _source; + + /* + <Instance Type="Type1" Key="Instance1" color="red" state="Texas"/> + <Instance Type="Type2" Key="Instance2" color="green" state="Missouri"/> + */ + + + [Test] + public void FetchAllMementos() + { + Assert.AreEqual(2, _source.GetAllMementos().Length); + } + + [Test] + public void FetchOneMemento() + { + InstanceMemento memento = _source.GetMemento("Instance1"); + Assert.AreEqual("red", memento.GetProperty("color")); + Assert.AreEqual("Instance1", memento.InstanceKey); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Source/EmbeddedMementoFile.xml =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/EmbeddedMementoFile.xml (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/EmbeddedMementoFile.xml 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8" ?> +<Instances> + + <Instance Type="Type1" Key="Instance1" color="red" state="Texas"/> + <Instance Type="Type2" Key="Instance2" color="green" state="Missouri"/> + +</Instances> \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Source/MachineXmlMementoSourceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/MachineXmlMementoSourceTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/MachineXmlMementoSourceTester.cs 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,63 @@ +using System; +using StructureMap; +using StructureMap.Source; +using NUnit.Framework; + +namespace StructureMap.Testing.Container.Source +{ + [TestFixture] + public class MachineXmlMementoSourceTester + { + private MachineXmlMementoSource source; + + [SetUp] + public void SetUp() + { + source = new MachineXmlMementoSource("Machine.XML", string.Empty, "Rule"); + } + + [Test] + public void Fetch1() + { + source.SetMachineName("server"); + InstanceMemento memento = source.GetMemento("FavoriteColor"); + + Assertion.AssertNotNull(memento); + Assertion.AssertEquals("Server's favorite color is blue", "Blue", memento.GetProperty("Color")); + } + + [Test] + public void Fetch2() + { + source.SetMachineName("localhost"); + InstanceMemento memento = source.GetMemento("FavoriteColor"); + + Assertion.AssertNotNull(memento); + Assertion.AssertEquals("Localhost's favorite color is red", "Red", memento.GetProperty("Color")); + } + + + + [Test] + public void FetchMachineNotFound() + { + source.SetMachineName("fake-machine"); + InstanceMemento memento = source.GetMemento("FavoriteColor"); + + Assertion.AssertNotNull(memento); + Assertion.AssertEquals("Default's favorite color is red", "Orange", memento.GetProperty("Color")); + } + + /* + [Test, Ignore("Only works on Jeremy's MILLERJ box")] + public void JeremysBox() + { + InstanceMemento memento = source.GetMemento("FavoriteColor"); + + Assertion.AssertNotNull(memento); + Assertion.AssertEquals("Jeremy's favorite color is green", "Green", memento.GetProperty("Color")); + } + */ + + } +} Added: trunk/Source/StructureMap.Testing/Graph/Source/Mementos/Instance1.xml =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/Mementos/Instance1.xml (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/Mementos/Instance1.xml 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="utf-8" ?> +<Instance Type="Type1" Key="Instance1" color="red" state="Texas"/> \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Source/Mementos/Instance2.xml =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/Mementos/Instance2.xml (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/Mementos/Instance2.xml 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="utf-8" ?> +<Instance Type="Type2" Key="Instance2" color="green" state="Missouri"/> \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Source/SingleEmbeddedXmlMementoSourceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/SingleEmbeddedXmlMementoSourceTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/SingleEmbeddedXmlMementoSourceTester.cs 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,45 @@ +using System.Reflection; +using NUnit.Framework; +using StructureMap.Source; + +namespace StructureMap.Testing.Graph.Source +{ + [TestFixture] + public class SingleEmbeddedXmlMementoSourceTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + string pathName = GetType().FullName.Replace(GetType().Name, "EmbeddedMementoFile.xml"); + _source = + new SingleEmbeddedXmlMementoSource("Instance", XmlMementoStyle.AttributeNormalized, + Assembly.GetExecutingAssembly(), pathName); + } + + #endregion + + private SingleEmbeddedXmlMementoSource _source; + +/* + <Instance Type="Type1" Key="Instance1" color="red" state="Texas"/> + <Instance Type="Type2" Key="Instance2" color="green" state="Missouri"/> + */ + + + [Test] + public void FetchAllMementos() + { + Assert.AreEqual(2, _source.GetAllMementos().Length); + } + + [Test] + public void FetchOneMemento() + { + InstanceMemento memento = _source.GetMemento("Instance1"); + Assert.AreEqual("red", memento.GetProperty("color")); + Assert.AreEqual("Instance1", memento.InstanceKey); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Source/TemplatingTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/TemplatingTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/TemplatingTester.cs 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,95 @@ +using NUnit.Framework; +using StructureMap.Source; +using StructureMap.Testing.TestData; + +namespace StructureMap.Testing.Graph.Source +{ + [TestFixture] + public class TemplatingTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + DataMother.WriteDocument(FILE_NAME); + + _nodeTemplateSource = new XmlFileMementoSource(FILE_NAME, "NodeTemplates", "Parent"); + _attTemplateSource = new XmlAttributeFileMementoSource(FILE_NAME, "AttTemplates", "Parent"); + _source = new XmlAttributeFileMementoSource(FILE_NAME, "Parents", "Parent"); + + _referringMemento = _source.GetMemento("Jackie"); + + _templatedSource = new TemplatedMementoSource(_source, _attTemplateSource); + } + + #endregion + + private const string FILE_NAME = "InstanceMementoTemplating.xml"; + private MementoSource _nodeTemplateSource; + private MementoSource _attTemplateSource; + private MementoSource _source; + private InstanceMemento _referringMemento; + private TemplatedMementoSource _templatedSource; + + private void validateCombinedMemento(InstanceMemento combinedMemento) + { + Assert.AreEqual("70", combinedMemento.GetProperty("Age")); + Assert.AreEqual("Green", combinedMemento.GetProperty("EyeColor")); + + InstanceMemento grandChildMemeto = + combinedMemento.GetChildMemento("MyChild").GetChildMemento("MyGrandChild"); + Assert.AreEqual("1992", grandChildMemeto.GetProperty("BirthYear")); + } + + + [Test] + public void GetAllMementos() + { + InstanceMemento[] mementos = _templatedSource.GetAllMementos(); + + Assert.IsNotNull(mementos); + Assert.AreEqual(4, mementos.Length); + + foreach (InstanceMemento memento in mementos) + { + Assert.IsNotNull(memento); + } + } + + [Test] + public void GetNonTemplatedInstance() + { + InstanceMemento memento = _templatedSource.GetMemento("Nadine"); + Assert.AreEqual("80", memento.GetProperty("Age")); + Assert.AreEqual("Blue", memento.GetProperty("EyeColor")); + } + + [Test] + public void GetTemplatedMementoFromAttributeNormalizedTemplate() + { + InstanceMemento templateMemento = _attTemplateSource.GetMemento("Grandmother"); + Assert.IsNotNull(templateMemento); + InstanceMemento combinedMemento = templateMemento.Substitute(_referringMemento); + + validateCombinedMemento(combinedMemento); + } + + [Test] + public void GetTemplatedMementoFromNodeNormalizedTemplate() + { + InstanceMemento templateMemento = _nodeTemplateSource.GetMemento("Grandmother"); + Assert.IsNotNull(templateMemento); + InstanceMemento combinedMemento = templateMemento.Substitute(_referringMemento); + + validateCombinedMemento(combinedMemento); + } + + [Test] + public void GetTheTemplatedInstance() + { + InstanceMemento memento = _templatedSource.GetMemento("Jackie"); + validateCombinedMemento(memento); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Source/XmlAttributeInstanceMementoTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/XmlAttributeInstanceMementoTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/XmlAttributeInstanceMementoTester.cs 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,129 @@ +using System.Xml; +using NUnit.Framework; +using StructureMap.Source; + +namespace StructureMap.Testing.Graph.Source +{ + [TestFixture] + public class XmlAttributeInstanceMementoTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + string xml = "<Instance Type=\"Color\" Key=\"Red\" color=\"red\"/>"; + _memento = buildMemento(xml); + } + + #endregion + + private XmlAttributeInstanceMemento _memento; + + + private XmlAttributeInstanceMemento buildMemento(string xml) + { + XmlDocument doc = new XmlDocument(); + doc.LoadXml(xml); + + return new XmlAttributeInstanceMemento(doc.DocumentElement); + } + + [Test] + public void ConcreteKey() + { + Assert.AreEqual("Color", _memento.ConcreteKey); + } + + [Test] + public void GetChildIsNotNull() + { + XmlElement element = _memento.InnerElement; + XmlElement childElement = element.OwnerDocument.CreateElement("rule"); + element.AppendChild(childElement); + childElement.SetAttribute("Type", "theConcreteKey"); + childElement.SetAttribute("Key", "theInstanceKey"); + childElement.SetAttribute("prop1", "thePropertyValue"); + + InstanceMemento memento = _memento.GetChildMemento("rule"); + Assert.IsNotNull(memento); + Assert.AreEqual("theInstanceKey", memento.InstanceKey); + Assert.AreEqual("theConcreteKey", memento.ConcreteKey); + Assert.AreEqual("thePropertyValue", memento.GetProperty("prop1")); + Assert.IsFalse(memento.IsDefault); + Assert.IsFalse(memento.IsReference); + } + + [Test] + public void GetChildrenArray() + { + XmlElement element = _memento.InnerElement; + + XmlElement rulesElement = element.OwnerDocument.CreateElement("rules"); + element.AppendChild(rulesElement); + + XmlElement childElement1 = element.OwnerDocument.CreateElement("rule"); + rulesElement.AppendChild(childElement1); + childElement1.SetAttribute("Type", "theConcreteKey"); + childElement1.SetAttribute("Key", "theInstanceKey"); + childElement1.SetAttribute("prop1", "thePropertyValue"); + + XmlElement childElement2 = (XmlElement) childElement1.CloneNode(true); + childElement2.SetAttribute("prop1", "different"); + rulesElement.AppendChild(childElement2); + + InstanceMemento[] mementoArray = _memento.GetChildrenArray("rules"); + Assert.AreEqual(2, mementoArray.Length); + + Assert.AreEqual("different", mementoArray[1].GetProperty("prop1")); + } + + [Test] + public void GetChildReturnsNullIfItDoesNotExist() + { + InstanceMemento memento = _memento.GetChildMemento("rule"); + Assert.IsNull(memento); + } + + [Test] + public void GetProperty() + { + Assert.AreEqual("red", _memento.GetProperty("color")); + } + + [Test] + public void IfNoChildrenReturnNull() + { + InstanceMemento[] mementoArray = _memento.GetChildrenArray("rules"); + Assert.IsNull(mementoArray); + } + + [Test] + public void InstanceKey() + { + Assert.AreEqual("Red", _memento.InstanceKey); + } + + [Test] + public void IsDefaultIsFalse() + { + Assert.IsFalse(_memento.IsDefault); + } + + [Test] + public void IsReferenceIsFalse() + { + Assert.IsFalse(_memento.IsReference); + } + + [Test] + public void ReferencedMemento() + { + _memento.InnerElement.SetAttribute("Type", string.Empty); + + Assert.IsTrue(_memento.IsReference); + Assert.IsFalse(_memento.IsDefault); + Assert.AreEqual("Red", _memento.ReferenceKey); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Source/XmlInstanceMementoTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/XmlInstanceMementoTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/XmlInstanceMementoTester.cs 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,56 @@ +using System.Xml; +using NUnit.Framework; +using StructureMap.Source; +using StructureMap.Testing.TestData; + +namespace StructureMap.Testing.Graph.Source +{ + [TestFixture] + public class XmlInstanceMementoTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + XmlDocument doc = DataMother.GetXmlDocument("XmlInstanceMemento.xml"); + + memento = new XmlNodeInstanceMemento(doc.DocumentElement, "Type", "Key"); + } + + #endregion + + private XmlNodeInstanceMemento memento; + + + [Test] + public void GetChildMemento() + { + InstanceMemento child = memento.GetChildMemento("Child1"); + Assert.IsNotNull(child); + + Assert.AreEqual("Child1", child.ConcreteKey, "Type is Child1"); + Assert.AreEqual("D", child.GetProperty("Prop4"), "Prop4"); + } + + [Test] + public void GetLargeStringInAttributeMemento() + { + XmlDocument document = DataMother.GetXmlDocument("CDataTest.xml"); + XmlNode node = document.DocumentElement.LastChild; + + XmlAttributeInstanceMemento memento = new XmlAttributeInstanceMemento(node); + Assert.AreEqual("select * from table", memento.GetProperty("bigProp")); + } + + [Test] + public void GetLargeStringInNodeMemento() + { + XmlDocument document = DataMother.GetXmlDocument("CDataTest.xml"); + XmlNode node = document.DocumentElement.FirstChild; + + XmlNodeInstanceMemento memento = new XmlNodeInstanceMemento(node, "Type", "Key"); + Assert.AreEqual("select * from table", memento.GetProperty("bigProp")); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Source/XmlMementoSourceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/XmlMementoSourceTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/XmlMementoSourceTester.cs 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,58 @@ +using NUnit.Framework; +using StructureMap.Source; +using StructureMap.Testing.TestData; + +namespace StructureMap.Testing.Graph.Source +{ + [TestFixture] + public class XmlMementoSourceTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + DataMother.WriteDocument("RuleSource.xml"); + source = new XmlFileMementoSource("RuleSource.XML", "", "Rule"); + } + + #endregion + + private MementoSource source; + + + [Test] + public void GetAll() + { + // There are 4 Rules defined in the XML file + InstanceMemento[] mementos = source.GetAllMementos(); + + Assert.IsNotNull(mementos); + Assert.AreEqual(4, mementos.Length, "4 mementos from 4 XML nodes"); + + foreach (InstanceMemento memento in mementos) + { + Assert.IsNotNull(memento); + } + } + + [Test] + public void GetComplex1() + { + InstanceMemento memento = source.GetMemento("Complex1"); + + Assert.IsNotNull(memento); + + + Assert.AreEqual("Complex1", memento.InstanceKey, "InstanceKey"); + Assert.AreEqual("Complex", memento.ConcreteKey, "ConcreteTypeKey"); + Assert.AreEqual("Red", memento.GetProperty("String"), "String"); + Assert.AreEqual("Green", memento.GetProperty("String2"), "String2"); + Assert.AreEqual("1", memento.GetProperty("Int"), "Int"); + Assert.AreEqual("2", memento.GetProperty("Long"), "Long"); + Assert.AreEqual("3", memento.GetProperty("Byte"), "Byte"); + Assert.AreEqual("4.5", memento.GetProperty("Double"), "Double"); + Assert.AreEqual("true", memento.GetProperty("Bool"), "Bool"); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Source/XmlTemplaterTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/XmlTemplaterTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/XmlTemplaterTester.cs 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,97 @@ +using System.Collections; +using System.Xml; +using NUnit.Framework; +using StructureMap.Source; +using StructureMap.Testing.TestData; +using StructureMap.Testing.XmlWriting; + +namespace StructureMap.Testing.Graph.Source +{ + [TestFixture] + public class XmlTemplaterTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + _document = DataMother.GetXmlDocument("Templater.xml"); + } + + #endregion + + private XmlDocument _document; + + [Test] + public void GetSubstititionsExplicitly() + { + XmlNode node = _document.DocumentElement.FirstChild; + XmlElement element = (XmlElement) node; + element.SetAttribute(InstanceMemento.SUBSTITUTIONS_ATTRIBUTE, "direction,color"); + + XmlTemplater templater = new XmlTemplater(node); + string[] substitutions = templater.Substitutions; + + Assert.AreEqual(2, substitutions.Length); + ArrayList list = new ArrayList(substitutions); + + Assert.IsTrue(list.Contains("color")); + Assert.IsTrue(list.Contains("direction")); + } + + [Test] + public void GetSubstitutionsImplicitly() + { + XmlNode node = _document.DocumentElement.FirstChild; + XmlTemplater templater = new XmlTemplater(node); + string[] substitutions = templater.Substitutions; + + Assert.AreEqual(4, substitutions.Length); + ArrayList list = new ArrayList(substitutions); + + Assert.IsTrue(list.Contains("color")); + Assert.IsTrue(list.Contains("name")); + Assert.IsTrue(list.Contains("state")); + Assert.IsTrue(list.Contains("direction")); + } + + + [Test] + public void HandleStringEmpty() + { + MemoryInstanceMemento memento = new MemoryInstanceMemento("", ""); + memento.SetProperty("color", ""); + + XmlDocument doc = new XmlDocument(); + XmlElement element = doc.CreateElement("top"); + doc.AppendChild(element); + element.SetAttribute("Color", "{color}"); + + XmlTemplater templater = new XmlTemplater(element); + + XmlElement result = (XmlElement) templater.SubstituteTemplates(element, memento); + Assert.AreEqual(InstanceMemento.EMPTY_STRING, result.GetAttribute("Color")); + } + + [Test] + public void MakeSubstitutionsInXmlNode() + { + MemoryInstanceMemento memento = new MemoryInstanceMemento("", ""); + memento.SetProperty("color", "blue"); + memento.SetProperty("name", "ObiWan"); + memento.SetProperty("state", "New York"); + memento.SetProperty("direction", "North"); + + XmlNode templateNode = _document.DocumentElement.FirstChild; + XmlTemplater templater = new XmlTemplater(templateNode); + + XmlNode expectedNode = _document.DocumentElement.LastChild; + ElementChecker checker = new ElementChecker((XmlElement) expectedNode); + + XmlElement actualElement = (XmlElement) templater.SubstituteTemplates(templateNode, memento); + + Assert.IsFalse(ReferenceEquals(templateNode, actualElement)); + checker.Check(actualElement); + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-06-02 16:27:39
|
Revision: 116 http://structuremap.svn.sourceforge.net/structuremap/?rev=116&view=rev Author: jeremydmiller Date: 2008-06-02 09:27:28 -0700 (Mon, 02 Jun 2008) Log Message: ----------- explicited a test Modified Paths: -------------- trunk/Source/CommonAssemblyInfo.cs trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs trunk/Source/StructureMap.Testing/Graph/FullStackFacadeTester.cs trunk/Source/StructureMap.sln Modified: trunk/Source/CommonAssemblyInfo.cs =================================================================== --- trunk/Source/CommonAssemblyInfo.cs 2008-06-02 03:02:16 UTC (rev 115) +++ trunk/Source/CommonAssemblyInfo.cs 2008-06-02 16:27:28 UTC (rev 116) @@ -1,3 +1,4 @@ +using System; using System.Reflection; using System.Runtime.InteropServices; @@ -11,10 +12,11 @@ // </auto-generated> //------------------------------------------------------------------------------ -[assembly : ComVisible(false)] -[assembly : AssemblyVersion("2.5.0.0000")] -[assembly : AssemblyCopyright("Copyright (c) 2007, Jeremy D. Miller")] -[assembly : AssemblyProduct("StructureMap")] -[assembly : AssemblyCompany("")] -[assembly : AssemblyConfiguration("release")] -[assembly : AssemblyInformationalVersion("2.5.0.0000")] \ No newline at end of file +[assembly: ComVisibleAttribute(false)] +[assembly: AssemblyVersionAttribute("2.5.0.0000")] +[assembly: AssemblyCopyrightAttribute("Copyright (c) 2007, Jeremy D. Miller")] +[assembly: AssemblyProductAttribute("StructureMap")] +[assembly: AssemblyCompanyAttribute("")] +[assembly: AssemblyConfigurationAttribute("release")] +[assembly: AssemblyInformationalVersionAttribute("2.5.0.0000")] + Modified: trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs 2008-06-02 03:02:16 UTC (rev 115) +++ trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs 2008-06-02 16:27:28 UTC (rev 116) @@ -11,7 +11,11 @@ public ReferencedInstance(string referenceKey) { - // TODO: VALIDATION if referenceKey is null or empty + if (string.IsNullOrEmpty(referenceKey)) + { + throw new ArgumentNullException("referenceKey"); + } + _referenceKey = referenceKey; } Modified: trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs 2008-06-02 03:02:16 UTC (rev 115) +++ trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs 2008-06-02 16:27:28 UTC (rev 116) @@ -115,11 +115,8 @@ assertParserIdList("Generics", "Include1", "Include2", "Main", "Master"); } - [Test] - public void If_adding_a_node_directly_use_stacktrace_to_get_the_node() - { - } + [Test] public void Log_error_150_if_a_designated_Include_cannot_be_opened() { @@ -142,7 +139,7 @@ assertErrorIsLogged(156, delegate { builder.IncludeFile("MissingInclude.xml"); }); } - [Test] + [Test, Explicit] public void Log_exception_100_if_StructureMap_config_is_required_and_missing() { assertErrorIsLogged(100, delegate Modified: trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs 2008-06-02 03:02:16 UTC (rev 115) +++ trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs 2008-06-02 16:27:28 UTC (rev 116) @@ -240,5 +240,7 @@ Container manager = new Container(new PluginGraph()); manager.GetInstance<IService>(); } + + } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Graph/FullStackFacadeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/FullStackFacadeTester.cs 2008-06-02 03:02:16 UTC (rev 115) +++ trunk/Source/StructureMap.Testing/Graph/FullStackFacadeTester.cs 2008-06-02 16:27:28 UTC (rev 116) @@ -1,4 +1,5 @@ using NUnit.Framework; +using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Testing.TestData; using StructureMap.Testing.Widget; @@ -212,6 +213,36 @@ Assert.AreSame(rule1, rule2); Assert.AreSame(rule1, rule3); } + + [Test] + public void If_there_is_only_one_instance_of_a_type_use_that_as_default() + { + AClass target = new AClass("Me"); + + Container container = new Container(delegate(Registry registry) + { + registry.AddInstanceOf<AClass>(target); + }); + + + Assert.AreSame(target, container.GetInstance<AClass>()); + } + + public class AClass + { + private readonly string _name; + + public AClass(string name) + { + _name = name; + } + + public string Name + { + get { return _name; } + } + } + } Modified: trunk/Source/StructureMap.sln =================================================================== --- trunk/Source/StructureMap.sln 2008-06-02 03:02:16 UTC (rev 115) +++ trunk/Source/StructureMap.sln 2008-06-02 16:27:28 UTC (rev 116) @@ -49,8 +49,6 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StructureMap.AutoMocking", "StructureMap.AutoMocking\StructureMap.AutoMocking.csproj", "{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HTML", "HTML\HTML.csproj", "{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Build|.NET = Build|.NET @@ -229,20 +227,6 @@ {0ED1B206-A1C9-4A52-BA87-3BA416C8725C}.Release|Any CPU.Build.0 = Release|Any CPU {0ED1B206-A1C9-4A52-BA87-3BA416C8725C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {0ED1B206-A1C9-4A52-BA87-3BA416C8725C}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Build|.NET.ActiveCfg = Release|Any CPU - {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Build|Any CPU.ActiveCfg = Release|Any CPU - {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Build|Any CPU.Build.0 = Release|Any CPU - {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Build|Mixed Platforms.ActiveCfg = Release|Any CPU - {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Build|Mixed Platforms.Build.0 = Release|Any CPU - {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Debug|.NET.ActiveCfg = Debug|Any CPU - {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Release|.NET.ActiveCfg = Release|Any CPU - {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Release|Any CPU.Build.0 = Release|Any CPU - {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Release|Mixed Platforms.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-06-02 03:02:31
|
Revision: 115 http://structuremap.svn.sourceforge.net/structuremap/?rev=115&view=rev Author: jeremydmiller Date: 2008-06-01 20:02:16 -0700 (Sun, 01 Jun 2008) Log Message: ----------- mild refactoring of DefaultConventionScanner Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs trunk/Source/StructureMap/Graph/ITypeScanner.cs trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-06-01 23:59:11 UTC (rev 114) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-06-02 03:02:16 UTC (rev 115) @@ -96,5 +96,10 @@ return this; } + + public ScanAssembliesExpression With<T>() where T : ITypeScanner, new() + { + return With(new T()); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/ITypeScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/ITypeScanner.cs 2008-06-01 23:59:11 UTC (rev 114) +++ trunk/Source/StructureMap/Graph/ITypeScanner.cs 2008-06-02 03:02:16 UTC (rev 115) @@ -23,7 +23,7 @@ } } - public static Type FindPluginType(Type concreteType) + public virtual Type FindPluginType(Type concreteType) { string interfaceName = "I" + concreteType.Name; Type[] interfaces = concreteType.GetInterfaces(); Modified: trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs 2008-06-01 23:59:11 UTC (rev 114) +++ trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs 2008-06-02 03:02:16 UTC (rev 115) @@ -14,8 +14,8 @@ [Test] public void FindPluginType() { - Assert.AreEqual(typeof(IConvention), DefaultConventionScanner.FindPluginType(typeof(Convention))); - Assert.IsNull(DefaultConventionScanner.FindPluginType(this.GetType())); + Assert.AreEqual(typeof(IConvention), new DefaultConventionScanner().FindPluginType(typeof(Convention))); + Assert.IsNull(new DefaultConventionScanner().FindPluginType(this.GetType())); } @@ -46,6 +46,19 @@ Assert.IsInstanceOfType(typeof(Convention), container.GetInstance<IConvention>()); } + + + [Test] + public void Process_to_Container_2() + { + Container container = new Container(delegate(Registry registry) + { + registry.ScanAssemblies().IncludeTheCallingAssembly() + .With<DefaultConventionScanner>(); + }); + + Assert.IsInstanceOfType(typeof(Convention), container.GetInstance<IConvention>()); + } } public interface IConvention{} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-06-01 23:59:12
|
Revision: 114 http://structuremap.svn.sourceforge.net/structuremap/?rev=114&view=rev Author: jeremydmiller Date: 2008-06-01 16:59:11 -0700 (Sun, 01 Jun 2008) Log Message: ----------- Default convention scanning Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs trunk/Source/StructureMap/Graph/AssemblyScanner.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap/Graph/ITypeScanner.cs trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-06-01 14:33:12 UTC (rev 113) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-06-01 23:59:11 UTC (rev 114) @@ -85,5 +85,16 @@ return this; } + + public ScanAssembliesExpression With(ITypeScanner scanner) + { + _registry.addExpression(delegate(PluginGraph graph) + { + graph.Assemblies.AddScanner(scanner); + }); + + + return this; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/AssemblyScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2008-06-01 14:33:12 UTC (rev 113) +++ trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2008-06-01 23:59:11 UTC (rev 114) @@ -6,12 +6,12 @@ namespace StructureMap.Graph { - // TODO: redo in 3.5 w/ Lambdas public class AssemblyScanner { private readonly List<Assembly> _assemblies = new List<Assembly>(); private readonly GraphLog _log; + private readonly List<ITypeScanner> _scanners = new List<ITypeScanner>(); public AssemblyScanner(GraphLog log) { @@ -27,35 +27,49 @@ { // Don't do this for SystemScan scanTypes(delegate(Type type) - { - if (Registry.IsPublicRegistry(type)) - { - Registry registry = (Registry) Activator.CreateInstance(type); - registry.ConfigurePluginGraph(pluginGraph); - } - }); + { + if (!Registry.IsPublicRegistry(type)) return; + Registry registry = (Registry) Activator.CreateInstance(type); + registry.ConfigurePluginGraph(pluginGraph); + }); + findFamiliesAndPlugins(pluginGraph); + runScanners(pluginGraph); } + private void runScanners(PluginGraph graph) + { + Registry registry = new Registry(); + scanTypes(delegate(Type type) + { + foreach (ITypeScanner scanner in _scanners) + { + scanner.Process(type, registry); + } + }); + + registry.ConfigurePluginGraph(graph); + } + private void findFamiliesAndPlugins(PluginGraph pluginGraph) { scanTypes(delegate(Type type) - { - if (PluginFamilyAttribute.MarkedAsPluginFamily(type)) - { - pluginGraph.CreateFamily(type); - } - }); + { + if (PluginFamilyAttribute.MarkedAsPluginFamily(type)) + { + pluginGraph.CreateFamily(type); + } + }); scanTypes(delegate(Type type) - { - foreach (PluginFamily family in pluginGraph.PluginFamilies) - { - family.AnalyzeTypeForPlugin(type); - } - }); + { + foreach (PluginFamily family in pluginGraph.PluginFamilies) + { + family.AnalyzeTypeForPlugin(type); + } + }); } @@ -121,5 +135,10 @@ return false; } + + public void AddScanner(ITypeScanner scanner) + { + _scanners.Add(scanner); + } } } \ No newline at end of file Added: trunk/Source/StructureMap/Graph/ITypeScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/ITypeScanner.cs (rev 0) +++ trunk/Source/StructureMap/Graph/ITypeScanner.cs 2008-06-01 23:59:11 UTC (rev 114) @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Text; +using StructureMap.Configuration.DSL; + +namespace StructureMap.Graph +{ + public interface ITypeScanner + { + void Process(Type type, Registry registry); + } + + public class DefaultConventionScanner : TypeRules, ITypeScanner + { + public void Process(Type type, Registry registry) + { + if (!IsConcrete(type)) return; + + Type pluginType = FindPluginType(type); + if (pluginType != null) + { + registry.ForRequestedType(pluginType).TheDefaultIsConcreteType(type); + } + } + + public static Type FindPluginType(Type concreteType) + { + string interfaceName = "I" + concreteType.Name; + Type[] interfaces = concreteType.GetInterfaces(); + return Array.Find(interfaces, delegate(Type t) + { + return t.Name == interfaceName; + }); + } + } +} Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-06-01 14:33:12 UTC (rev 113) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-06-01 23:59:11 UTC (rev 114) @@ -374,6 +374,7 @@ <Link>Properties\structuremap.snk</Link> </None> <Compile Include="ErrorMessages.cs" /> + <Compile Include="Graph\ITypeScanner.cs" /> <Compile Include="Pipeline\ConfiguredInstance.Building.cs" /> <Compile Include="Pipeline\IStructuredInstance.cs" /> <Compile Include="Util\Cache.cs" /> Added: trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs 2008-06-01 23:59:11 UTC (rev 114) @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Text; +using NUnit.Framework; +using StructureMap.Configuration.DSL; +using StructureMap.Graph; +using StructureMap.Pipeline; + +namespace StructureMap.Testing.Graph +{ + [TestFixture] + public class DefaultConventionScanningTester + { + [Test] + public void FindPluginType() + { + Assert.AreEqual(typeof(IConvention), DefaultConventionScanner.FindPluginType(typeof(Convention))); + Assert.IsNull(DefaultConventionScanner.FindPluginType(this.GetType())); + } + + + [Test] + public void Process_to_PluginGraph() + { + Registry registry = new Registry(); + DefaultConventionScanner scanner = new DefaultConventionScanner(); + scanner.Process(typeof(Convention), registry); + + PluginGraph graph = registry.Build(); + + Assert.IsFalse(graph.PluginFamilies.Contains(typeof(IServer))); + Assert.IsTrue(graph.PluginFamilies.Contains(typeof(IConvention))); + + PluginFamily family = graph.FindFamily(typeof (IConvention)); + Assert.AreEqual(1, family.InstanceCount); + } + + [Test] + public void Process_to_Container() + { + Container container = new Container(delegate(Registry registry) + { + registry.ScanAssemblies().IncludeTheCallingAssembly() + .With(new DefaultConventionScanner()); + }); + + Assert.IsInstanceOfType(typeof(Convention), container.GetInstance<IConvention>()); + } + } + + public interface IConvention{} + public interface IServer{} + public class Convention : IConvention, IServer + { + public void Go() + { + throw new NotImplementedException(); + } + } + + public class Something : IConvention{} +} Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-06-01 14:33:12 UTC (rev 113) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-06-01 23:59:11 UTC (rev 114) @@ -191,6 +191,7 @@ <Compile Include="Graph\ContainerConstructorAttributeTester.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Graph\DefaultConventionScanningTester.cs" /> <Compile Include="Graph\DynamicInjectionTester.cs" /> <Compile Include="Graph\EmittingTester.cs"> <SubType>Code</SubType> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-06-01 14:33:19
|
Revision: 113 http://structuremap.svn.sourceforge.net/structuremap/?rev=113&view=rev Author: jeremydmiller Date: 2008-06-01 07:33:12 -0700 (Sun, 01 Jun 2008) Log Message: ----------- dynamic container expansion, InjectStub_by_name Modified Paths: -------------- trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap.Testing/BuildSessionTester.cs trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs trunk/Source/StructureMap.Testing/Graph/EnumerationTester.cs Modified: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs 2008-05-31 19:47:30 UTC (rev 112) +++ trunk/Source/StructureMap/Container.cs 2008-06-01 14:33:12 UTC (rev 113) @@ -105,9 +105,10 @@ Inject<T>(instance); } - public void InjectStub<T>(string name, T instance) + public void InjectStub<T>(string name, T stub) { - throw new NotImplementedException(); + LiteralInstance instance = new LiteralInstance(stub).WithName(name); + _pipelineGraph.AddInstance<T>(instance); } public IList<T> GetAllInstances<T>() Modified: trunk/Source/StructureMap.Testing/BuildSessionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-05-31 19:47:30 UTC (rev 112) +++ trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-06-01 14:33:12 UTC (rev 113) @@ -148,7 +148,7 @@ assertActionThrowsErrorCode(200, delegate { BuildSession session = new BuildSession(graph, null); - session.CreateInstance(typeof (IGateway), "A Name"); + session.CreateInstance(typeof (IGateway), "Gateway that is not configured"); }); } Modified: trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs 2008-05-31 19:47:30 UTC (rev 112) +++ trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs 2008-06-01 14:33:12 UTC (rev 113) @@ -33,14 +33,11 @@ private void addColorMemento(string Color) { - ConfiguredInstance instance = new ConfiguredInstance(Color).WithConcreteKey("Color").SetProperty("Color", - Color); - _manager.Configure(delegate(Registry registry) { - registry.AddInstanceOf<Rule>(instance); - registry.AddInstanceOf<IWidget>(instance); - registry.AddInstanceOf<WidgetMaker>(instance); + registry.AddInstanceOf<Rule>().UsingConcreteType<ColorRule>().SetProperty("Color", Color).WithName(Color); + registry.AddInstanceOf<IWidget>().UsingConcreteType<ColorWidget>().SetProperty("Color", Color).WithName(Color); + registry.AddInstanceOf<WidgetMaker>().UsingConcreteType<ColorWidgetMaker>().SetProperty("Color", Color).WithName(Color); }); } @@ -203,8 +200,16 @@ [Test] public void InjectStub_by_name() { - Assert.Fail("Do."); IContainer container = new Container(); + + ColorRule red = new ColorRule("Red"); + ColorRule blue = new ColorRule("Blue"); + + container.InjectStub<Rule>("Red", red); + container.InjectStub<Rule>("Blue", blue); + + Assert.AreSame(red, container.GetInstance<Rule>("Red")); + Assert.AreSame(blue, container.GetInstance<Rule>("Blue")); } Modified: trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs 2008-05-31 19:47:30 UTC (rev 112) +++ trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs 2008-06-01 14:33:12 UTC (rev 113) @@ -113,8 +113,13 @@ family.AddPlugin(typeof (SomethingOne), "One"); IContainer manager = new Container(pluginGraph); + manager.Configure( - delegate(Registry registry) { registry.AddInstanceOf<ISomething>().WithConcreteKey("One").WithName("One"); }); + delegate(Registry registry) + { + registry.ForRequestedType<ISomething>().AliasConcreteType<SomethingOne>("One"); + registry.AddInstanceOf<ISomething>().WithConcreteKey("One").WithName("One"); + }); IList<ISomething> list = manager.GetAllInstances<ISomething>(); Assert.AreEqual(1, list.Count); Modified: trunk/Source/StructureMap.Testing/Graph/EnumerationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/EnumerationTester.cs 2008-05-31 19:47:30 UTC (rev 112) +++ trunk/Source/StructureMap.Testing/Graph/EnumerationTester.cs 2008-06-01 14:33:12 UTC (rev 113) @@ -21,7 +21,7 @@ manager.Configure(delegate(Registry registry) { - registry.AddInstanceOf<Cow>().UsingConcreteTypeNamed("Default") + registry.AddInstanceOf<Cow>().UsingConcreteType<Cow>() .WithName("Angus") .WithProperty("Name").EqualTo("Bessie") .WithProperty("Breed").EqualTo("Angus") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-05-31 19:47:33
|
Revision: 112 http://structuremap.svn.sourceforge.net/structuremap/?rev=112&view=rev Author: jeremydmiller Date: 2008-05-31 12:47:30 -0700 (Sat, 31 May 2008) Log Message: ----------- The dynamic addition of assemblies at runtime Modified Paths: -------------- trunk/Source/CommonAssemblyInfo.cs trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs trunk/Source/StructureMap/Graph/PluginCollection.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/IContainer.cs trunk/Source/StructureMap/IInstanceFactory.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/Interceptors/InterceptorLibrary.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs trunk/Source/StructureMap.Testing/BuildSessionTester.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreateProfileTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ScanAssembliesTester.cs trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs trunk/Source/StructureMap.Testing/Configuration/FamilyParserTester.cs trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs trunk/Source/StructureMap.Testing/Configuration/ProfileBuilderTester.cs trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs trunk/Source/StructureMap.Testing/DataAccess/Commands/StoredProcedureCommandTester.cs trunk/Source/StructureMap.Testing/DataAccess/DataSessionTester.cs trunk/Source/StructureMap.Testing/DataAccess/DataSetMapping/ReaderToColumnMapTester.cs trunk/Source/StructureMap.Testing/DataAccess/DataSetMapping/ReaderToTableMapperTester.cs trunk/Source/StructureMap.Testing/DataAccess/Debugging.cs trunk/Source/StructureMap.Testing/DataAccess/StubbedCommand.cs trunk/Source/StructureMap.Testing/DataAccess/StubbedReaderSource.cs trunk/Source/StructureMap.Testing/DataAccess/TemplatedCommandTester.cs trunk/Source/StructureMap.Testing/DataAccess/Tools/TableDataReaderTester.cs trunk/Source/StructureMap.Testing/Diagnostics/IntegrationTester.cs trunk/Source/StructureMap.Testing/Diagnostics/TextReportWriterSmokeTester.cs trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs trunk/Source/StructureMap.Testing/Graph/ParameterInfoCollection.cs trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs trunk/Source/StructureMap.Testing/Graph/PluginTester.cs trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs trunk/Source/StructureMap.Testing/Graph/TypePathTester.cs trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs trunk/Source/StructureMap.Testing/InstanceBuilderListTester.cs trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs trunk/Source/StructureMap.Testing/MementoTester.cs trunk/Source/StructureMap.Testing/MergingTester.cs trunk/Source/StructureMap.Testing/ObjectFactoryTester.cs trunk/Source/StructureMap.Testing/ObjectMother.cs trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs trunk/Source/StructureMap.Testing/Pipeline/ConstructorInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/DefaultInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/LiteralInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerMergeTester.cs trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerTester.cs trunk/Source/StructureMap.Testing/Pipeline/ProfileTester.cs trunk/Source/StructureMap.Testing/Pipeline/PrototypeInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/StubBuildSession.cs trunk/Source/StructureMap.Testing/Pipeline/ThreadLocalStoragePolicyTester.cs trunk/Source/StructureMap.Testing/Pipeline/TypeRulesTester.cs trunk/Source/StructureMap.Testing/PipelineGraphTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing/StructureMapConfigCreator.cs trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs trunk/Source/StructureMap.Testing/TestData/DataMother.cs trunk/Source/StructureMap.Testing/TestUtility.cs trunk/Source/StructureMap.Testing/XmlWriting/ElementChecker.cs Added Paths: ----------- trunk/Source/StructureMap/Util/ trunk/Source/StructureMap/Util/Cache.cs trunk/Source/StructureMap.Testing/Graph/ArrayConstructorTester.cs trunk/Source/StructureMap.Testing/Graph/ContainerConstructorAttributeTester.cs trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs trunk/Source/StructureMap.Testing/Graph/EmittingTester.cs trunk/Source/StructureMap.Testing/Graph/EnumerationTester.cs trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs trunk/Source/StructureMap.Testing/Graph/FillDependenciesTester.cs trunk/Source/StructureMap.Testing/Graph/FullStackFacadeTester.cs trunk/Source/StructureMap.Testing/Graph/ImplicitDefaultTest.cs trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/Graph/IntegratedTester.cs trunk/Source/StructureMap.Testing/Graph/PluggableAttributeTester.cs trunk/Source/StructureMap.Testing/Graph/PluginFamilyMergeTester.cs trunk/Source/StructureMap.Testing/Graph/PluginGraphBuilderTester.cs trunk/Source/StructureMap.Testing/Graph/SetterInjectionEmittingTester.cs trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs Removed Paths: ------------- trunk/Source/StructureMap.Testing/Container/ Modified: trunk/Source/CommonAssemblyInfo.cs =================================================================== --- trunk/Source/CommonAssemblyInfo.cs 2008-05-30 16:36:24 UTC (rev 111) +++ trunk/Source/CommonAssemblyInfo.cs 2008-05-31 19:47:30 UTC (rev 112) @@ -1,4 +1,3 @@ -using System; using System.Reflection; using System.Runtime.InteropServices; @@ -12,11 +11,10 @@ // </auto-generated> //------------------------------------------------------------------------------ -[assembly: ComVisibleAttribute(false)] -[assembly: AssemblyVersionAttribute("2.5.0.0000")] -[assembly: AssemblyCopyrightAttribute("Copyright (c) 2007, Jeremy D. Miller")] -[assembly: AssemblyProductAttribute("StructureMap")] -[assembly: AssemblyCompanyAttribute("")] -[assembly: AssemblyConfigurationAttribute("release")] -[assembly: AssemblyInformationalVersionAttribute("2.5.0.0000")] - +[assembly : ComVisible(false)] +[assembly : AssemblyVersion("2.5.0.0000")] +[assembly : AssemblyCopyright("Copyright (c) 2007, Jeremy D. Miller")] +[assembly : AssemblyProduct("StructureMap")] +[assembly : AssemblyCompany("")] +[assembly : AssemblyConfiguration("release")] +[assembly : AssemblyInformationalVersion("2.5.0.0000")] \ No newline at end of file Modified: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs 2008-05-30 16:36:24 UTC (rev 111) +++ trunk/Source/StructureMap/Container.cs 2008-05-31 19:47:30 UTC (rev 112) @@ -90,22 +90,6 @@ _pipelineGraph.Inject(instance); } - public void InjectByName<PLUGINTYPE>(PLUGINTYPE instance, string instanceKey) - { - LiteralInstance literalInstance = new LiteralInstance(instance); - literalInstance.Name = instanceKey; - - AddInstance<PLUGINTYPE>(literalInstance); - } - - public void InjectByName<PLUGINTYPE, CONCRETETYPE>(string instanceKey) - { - ConfiguredInstance instance = new ConfiguredInstance(typeof(CONCRETETYPE)); - instance.Name = instanceKey; - - AddInstance<PLUGINTYPE>(instance); - } - public T GetInstance<T>() { return (T) GetInstance(typeof (T)); @@ -118,9 +102,14 @@ public void InjectStub<T>(T instance) { - InjectStub(typeof (T), instance); + Inject<T>(instance); } + public void InjectStub<T>(string name, T instance) + { + throw new NotImplementedException(); + } + public IList<T> GetAllInstances<T>() { List<T> list = new List<T>(); @@ -180,7 +169,7 @@ /// </summary> /// <param name="pluginType"></param> /// <param name="instance"></param> - public void SetDefault(Type pluginType, Instance instance) + public void Inject(Type pluginType, Instance instance) { _pipelineGraph.SetDefault(pluginType, instance); } @@ -196,7 +185,22 @@ _pipelineGraph.SetDefault(pluginType, reference); } + public void SetDefault(Type pluginType, Instance instance) + { + _pipelineGraph.SetDefault(pluginType, instance); + } + public void SetDefault<T>(Instance instance) + { + SetDefault(typeof(T), instance); + } + + public void SetDefault<PLUGINTYPE, CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE + { + SetDefault<PLUGINTYPE>(new ConfiguredInstance(typeof(CONCRETETYPE))); + } + + /// <summary> /// Attempts to create a new instance of the requested type. Automatically inserts the default /// configured instance for each dependency in the StructureMap constructor function. @@ -243,19 +247,20 @@ return forType(type).GetAllInstances(withNewSession()); } - public void AddInstance<T>(Instance instance) + public void Configure(Action<Registry> configure) { - _pipelineGraph.AddInstance<T>(instance); - } + lock (this) + { + Registry registry = new Registry(); + configure(registry); - public void AddInstance<PLUGINTYPE, CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE - { - _pipelineGraph.AddInstance<PLUGINTYPE, CONCRETETYPE>(); - } + PluginGraph graph = registry.Build(); - public void AddDefaultInstance<PLUGINTYPE, CONCRETETYPE>() - { - _pipelineGraph.AddDefaultInstance<PLUGINTYPE, CONCRETETYPE>(); + graph.Log.AssertFailures(); + + _interceptorLibrary.ImportFrom(graph.InterceptorLibrary); + _pipelineGraph.ImportFrom(graph); + } } public string WhatDoIHave() Modified: trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs =================================================================== --- trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs 2008-05-30 16:36:24 UTC (rev 111) +++ trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs 2008-05-31 19:47:30 UTC (rev 112) @@ -12,19 +12,9 @@ public class BuildInstanceMethod : Method { private readonly Plugin _plugin; - //private readonly ConstructorInfo _constructor; - //private readonly ParameterEmitter _parameterEmitter; public BuildInstanceMethod(Plugin plugin) : base() { - //_constructor = plugin.GetConstructor(); - - //_parameterEmitter = new StringParameterEmitter(); - - //_parameterEmitter.AttachNextSibling(new PrimitiveParameterEmitter()); - //_parameterEmitter.AttachNextSibling(new EnumParameterEmitter()); - //_parameterEmitter.AttachNextSibling(new ChildParameterEmitter()); - //_parameterEmitter.AttachNextSibling(new ChildArrayParameterEmitter()); _plugin = plugin; } Modified: trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-05-30 16:36:24 UTC (rev 111) +++ trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-05-31 19:47:30 UTC (rev 112) @@ -1,18 +1,27 @@ using System; using System.Collections.Generic; using StructureMap.Pipeline; +using StructureMap.Util; namespace StructureMap.Graph { public class GenericsPluginGraph { - private readonly Dictionary<Type, PluginFamily> _families; + private readonly Cache<Type, PluginFamily> _families; public GenericsPluginGraph() { - _families = new Dictionary<Type, PluginFamily>(); + _families = new Cache<Type, PluginFamily>(delegate(Type pluginType) + { + return new PluginFamily(pluginType); + }); } + public int FamilyCount + { + get { return _families.Count; } + } + public static bool CanBeCast(Type pluginType, Type pluggedType) { try @@ -64,7 +73,7 @@ public void AddFamily(PluginFamily family) { - _families.Add(family.PluginType, family); + _families.Store(family.PluginType, family); } @@ -72,9 +81,9 @@ { Type basicType = templatedType.GetGenericTypeDefinition(); - if (_families.ContainsKey(basicType)) + if (_families.Has(basicType)) { - PluginFamily basicFamily = _families[basicType]; + PluginFamily basicFamily = _families.Retrieve(basicType); Type[] templatedParameterTypes = templatedType.GetGenericArguments(); profileManager.CopyDefaults(basicType, templatedType); @@ -106,13 +115,14 @@ } // TODO -- Got a big problem here. Intances need to be copied over - foreach (IDiagnosticInstance instance in baseFamily.GetAllInstances()) + baseFamily.EachInstance(delegate(Instance i) { + IDiagnosticInstance instance = i; if (instance.CanBePartOfPluginFamily(templatedFamily)) { - templatedFamily.AddInstance((Instance) instance); + templatedFamily.AddInstance((Instance)instance); } - } + }); // Need to attach the new PluginFamily to the old PluginGraph baseFamily.Parent.PluginFamilies.Add(templatedFamily); @@ -169,5 +179,24 @@ } return isValid; } + + public void ImportFrom(GenericsPluginGraph source) + { + foreach (PluginFamily sourceFamily in source._families) + { + ImportFrom(sourceFamily); + } + } + + public void ImportFrom(PluginFamily sourceFamily) + { + PluginFamily destinationFamily = FindFamily(sourceFamily.PluginType); + destinationFamily.ImportFrom(sourceFamily); + } + + public PluginFamily FindFamily(Type pluginType) + { + return _families.Retrieve(pluginType); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginCollection.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginCollection.cs 2008-05-30 16:36:24 UTC (rev 111) +++ trunk/Source/StructureMap/Graph/PluginCollection.cs 2008-05-31 19:47:30 UTC (rev 112) @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using StructureMap.Util; namespace StructureMap.Graph { @@ -10,7 +11,7 @@ public class PluginCollection : IEnumerable<Plugin> { private readonly PluginFamily _family; - private readonly Dictionary<Type, Plugin> _plugins = new Dictionary<Type, Plugin>(); + private readonly Cache<Type, Plugin> _plugins = new Cache<Type, Plugin>(); public PluginCollection(PluginFamily family) { @@ -21,10 +22,7 @@ { get { - Plugin[] returnValue = new Plugin[_plugins.Count]; - _plugins.Values.CopyTo(returnValue, 0); - - return returnValue; + return _plugins.GetAll(); } } @@ -34,13 +32,13 @@ } /// <summary> - /// Gets a Plugin by its PluggedType + /// Gets a Plugin by its pluggedType /// </summary> - /// <param name="PluggedType"></param> + /// <param name="pluggedType"></param> /// <returns></returns> - public Plugin this[Type PluggedType] + public Plugin this[Type pluggedType] { - get { return _plugins[PluggedType]; } + get { return _plugins.Retrieve(pluggedType); } } /// <summary> @@ -52,15 +50,10 @@ { get { - foreach (KeyValuePair<Type, Plugin> pair in _plugins) + return _plugins.Find(delegate(Plugin plugin) { - if (pair.Value.ConcreteKey == concreteKey) - { - return pair.Value; - } - } - - return null; + return plugin.ConcreteKey == concreteKey; + }); } } @@ -68,7 +61,7 @@ IEnumerator<Plugin> IEnumerable<Plugin>.GetEnumerator() { - return _plugins.Values.GetEnumerator(); + return _plugins.GetEnumerator(); } public IEnumerator GetEnumerator() @@ -81,7 +74,7 @@ public void Add(Plugin plugin) { - if (_plugins.ContainsKey(plugin.PluggedType)) + if (_plugins.Has(plugin.PluggedType)) { Plugin peer = this[plugin.PluggedType]; peer.MergeSetters(plugin); @@ -99,7 +92,8 @@ throw new StructureMapException(104, plugin.PluggedType, _family.PluginType); } - _plugins.Add(plugin.PluggedType, plugin); + + _plugins.Store(plugin.PluggedType, plugin); } /// <summary> @@ -130,20 +124,25 @@ public List<Plugin> FindAutoFillablePlugins() { List<Plugin> list = new List<Plugin>(); - foreach (Plugin plugin in _plugins.Values) + _plugins.Each(delegate(Plugin plugin) { if (plugin.CanBeAutoFilled) { list.Add(plugin); } - } + }); return list; } public bool HasPlugin(Type pluggedType) { - return _plugins.ContainsKey(pluggedType); + return _plugins.Has(pluggedType); } + + public void Fill(Plugin plugin) + { + _plugins.Fill(plugin.PluggedType, plugin); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-30 16:36:24 UTC (rev 111) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-31 19:47:30 UTC (rev 112) @@ -2,6 +2,7 @@ using System.Collections.Generic; using StructureMap.Attributes; using StructureMap.Pipeline; +using StructureMap.Util; namespace StructureMap.Graph { @@ -14,7 +15,7 @@ { private readonly Predicate<Type> _explicitlyMarkedPluginFilter; private readonly Predicate<Type> _implicitPluginFilter; - private readonly List<Instance> _instances = new List<Instance>(); + private readonly Cache<string, Instance> _instances = new Cache<string, Instance>(delegate { return null; }); private readonly List<InstanceMemento> _mementoList = new List<InstanceMemento>(); private readonly PluginCollection _plugins; private readonly Type _pluginType; @@ -99,7 +100,7 @@ public void AddInstance(Instance instance) { - _instances.Add(instance); + _instances.Store(instance.Name, instance); } @@ -117,7 +118,7 @@ _parent.Log.Try(delegate() { Instance instance = memento.ReadInstance(Parent, _pluginType); - _instances.Add(instance); + AddInstance(instance); }).AndLogAnyErrors(); }); @@ -127,28 +128,28 @@ if (_instances.Count == 1) { - _defaultKey = _instances[0].Name; + _defaultKey = _instances.First.Name; } } private void validatePluggabilityOfInstances() { - foreach (Instance instance in _instances) + _instances.Each(delegate(Instance instance) { IDiagnosticInstance diagnosticInstance = instance; _parent.Log.Try(delegate() { - diagnosticInstance.Preprocess(this); + diagnosticInstance.Preprocess(this); }) .AndReportErrorAs(104, diagnosticInstance.CreateToken(), _pluginType); - + if (!diagnosticInstance.CanBePartOfPluginFamily(this)) { _parent.Log.RegisterError(104, diagnosticInstance.CreateToken(), _pluginType); } - } + }); } private void discoverImplicitInstances() @@ -164,14 +165,14 @@ } } - public Instance[] GetAllInstances() + public void EachInstance(Action<Instance> action) { - return _instances.ToArray(); + _instances.Each(action); } public Instance GetInstance(string name) { - return _instances.Find(delegate(Instance i) { return i.Name == name; }); + return _instances.Retrieve(name); } @@ -192,12 +193,17 @@ return _plugins.HasPlugin(pluggedType); } - public void AddPlugin(Type pluggedType) + public Plugin AddPlugin(Type pluggedType) { if (!HasPlugin(pluggedType)) { - AddPlugin(new Plugin(pluggedType)); + Plugin plugin = new Plugin(pluggedType); + AddPlugin(plugin); + + return plugin; } + + return Plugins[pluggedType]; } public Plugin AddPlugin(Type pluggedType, string key) @@ -270,6 +276,11 @@ set { _defaultKey = value ?? string.Empty; } } + public int InstanceCount + { + get { return _instances.Count; } + } + #endregion public Plugin FindPlugin(Type pluggedType) @@ -313,5 +324,23 @@ profile.FillTypeInto(PluginType, defaultInstance); } + + public void ImportFrom(PluginFamily source) + { + source.EachInstance(delegate(Instance instance) + { + _instances.Fill(instance.Name, instance); + }); + + foreach (Plugin plugin in source.Plugins) + { + Plugins.Fill(plugin); + } + } + + public Instance FirstInstance() + { + return _instances.First; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/IContainer.cs =================================================================== --- trunk/Source/StructureMap/IContainer.cs 2008-05-30 16:36:24 UTC (rev 111) +++ trunk/Source/StructureMap/IContainer.cs 2008-05-31 19:47:30 UTC (rev 112) @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using StructureMap.Configuration.DSL; using StructureMap.Pipeline; namespace StructureMap @@ -11,43 +12,30 @@ T GetInstance<T>(); T FillDependencies<T>(); object FillDependencies(Type type); - void InjectStub<T>(T instance); + IList<T> GetAllInstances<T>(); - void SetDefaultsToProfile(string profile); + T GetInstance<T>(Instance instance); - /// <summary> - /// Sets up the Container to return the object in the "stub" argument anytime - /// any instance of the PluginType is requested - /// </summary> - /// <param name="pluginType"></param> - /// <param name="stub"></param> - void InjectStub(Type pluginType, object stub); - IList GetAllInstances(Type type); - void AddInstance<T>(Instance instance); - void AddInstance<PLUGINTYPE, CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE; - void AddDefaultInstance<PLUGINTYPE, CONCRETETYPE>(); + + void Configure(Action<Registry> configure); void Inject<PLUGINTYPE>(PLUGINTYPE instance); - void InjectByName<PLUGINTYPE>(PLUGINTYPE instance, string instanceKey); - void InjectByName<PLUGINTYPE, CONCRETETYPE>(string instanceKey); + void InjectStub(Type pluginType, object stub); + void InjectStub<T>(T instance); + void InjectStub<T>(string name, T instance); + void SetDefault(Type pluginType, string instanceKey); + void SetDefault(Type pluginType, Instance instance); + void SetDefault<T>(Instance instance); + void SetDefault<PLUGINTYPE, CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE; + void SetDefaultsToProfile(string profile); + string WhatDoIHave(); - /// <summary> - /// Sets the default instance for the PluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instance"></param> - void SetDefault(Type pluginType, Instance instance); - /// <summary> - /// Sets the default instance for the PluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instanceKey"></param> - void SetDefault(Type pluginType, string instanceKey); + /// <summary> /// Creates a new object instance of the requested type Modified: trunk/Source/StructureMap/IInstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/IInstanceFactory.cs 2008-05-30 16:36:24 UTC (rev 111) +++ trunk/Source/StructureMap/IInstanceFactory.cs 2008-05-31 19:47:30 UTC (rev 112) @@ -1,5 +1,6 @@ using System; using System.Collections; +using StructureMap.Graph; using StructureMap.Pipeline; namespace StructureMap @@ -21,5 +22,6 @@ InstanceBuilder FindBuilderByType(Type pluggedType); InstanceBuilder FindBuilderByConcreteKey(string concreteKey); void ForEachInstance(Action<Instance> action); + void ImportFrom(PluginFamily family); } } \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-05-30 16:36:24 UTC (rev 111) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-05-31 19:47:30 UTC (rev 112) @@ -1,8 +1,8 @@ using System; using System.Collections; -using System.Collections.Generic; using StructureMap.Graph; using StructureMap.Pipeline; +using StructureMap.Util; namespace StructureMap { @@ -12,7 +12,10 @@ public class InstanceFactory : IInstanceFactory { private readonly InstanceBuilderList _instanceBuilders; - private readonly Dictionary<string, Instance> _instances = new Dictionary<string, Instance>(); + + private readonly Cache<string, Instance> _instances = + new Cache<string, Instance>(delegate { return null; }); + private readonly Type _pluginType; private readonly IBuildPolicy _policy = new BuildPolicy(); @@ -20,7 +23,6 @@ public InstanceFactory(Type pluginType) : this(new PluginFamily(pluginType)) { - } /// <summary> @@ -41,10 +43,8 @@ _pluginType = family.PluginType; _instanceBuilders = new InstanceBuilderList(family.PluginType, family.Plugins.All); - foreach (Instance instance in family.GetAllInstances()) - { - AddInstance(instance); - } + + family.EachInstance(delegate(Instance instance) { AddInstance(instance); }); } catch (StructureMapException) { @@ -93,29 +93,21 @@ public void ForEachInstance(Action<Instance> action) { - foreach (KeyValuePair<string, Instance> pair in _instances) - { - action(pair.Value); - } + _instances.Each(action); } public void AddInstance(Instance instance) { - if (_instances.ContainsKey(instance.Name)) - { - _instances[instance.Name] = instance; - } - else - { - _instances.Add(instance.Name, instance); - } + _instances.Store(instance.Name, instance); } - [Obsolete] public Instance AddType<T>() + [Obsolete] + public Instance AddType<T>() { InstanceBuilder builder = _instanceBuilders.FindByType(typeof (T)); - ConfiguredInstance instance = new ConfiguredInstance(typeof(T)).WithName(TypePath.GetAssemblyQualifiedName(typeof(T))); + ConfiguredInstance instance = + new ConfiguredInstance(typeof (T)).WithName(TypePath.GetAssemblyQualifiedName(typeof (T))); AddInstance(instance); @@ -126,11 +118,11 @@ { IList list = new ArrayList(); - foreach (KeyValuePair<string, Instance> pair in _instances) + _instances.Each(delegate(Instance instance) { - object instance = Build(session, pair.Value); - list.Add(instance); - } + object builtObject = Build(session, instance); + list.Add(builtObject); + }); return list; } @@ -142,28 +134,18 @@ public Instance FindInstance(string name) { - if (!_instances.ContainsKey(name)) - { - return null; - } - - return _instances[name]; + return _instances.Retrieve(name); } #endregion - public void Merge(PluginFamily family) + public void ImportFrom(PluginFamily family) { _instanceBuilders.Add(family.Plugins); - foreach (Instance instance in family.GetAllInstances()) + family.EachInstance(delegate(Instance instance) { - if (_instances.ContainsKey(instance.Name)) - { - continue; - } - - AddInstance(instance); - } + _instances.Fill(instance.Name, instance); + }); } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Interceptors/InterceptorLibrary.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/InterceptorLibrary.cs 2008-05-30 16:36:24 UTC (rev 111) +++ trunk/Source/StructureMap/Interceptors/InterceptorLibrary.cs 2008-05-31 19:47:30 UTC (rev 112) @@ -18,6 +18,15 @@ _interceptors.Add(interceptor); } + public void ImportFrom(InterceptorLibrary source) + { + lock (_locker) + { + _analyzedInterceptors.Clear(); + _interceptors.AddRange(source._interceptors); + } + } + public CompoundInterceptor FindInterceptor(Type type) { if (_analyzedInterceptors.ContainsKey(type)) Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-05-30 16:36:24 UTC (rev 111) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-05-31 19:47:30 UTC (rev 112) @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Security.Permissions; +using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Pipeline; @@ -85,50 +86,6 @@ manager.Inject<PLUGINTYPE>(instance); } - /// <summary> - /// Injects a new instance of PLUGINTYPE by name. - /// </summary> - /// <typeparam name="PLUGINTYPE"></typeparam> - /// <param name="instance"></param> - /// <param name="instanceKey"></param> - public static void InjectByName<PLUGINTYPE>(PLUGINTYPE instance, string instanceKey) - { - manager.InjectByName<PLUGINTYPE>(instance, instanceKey); - } - - /// <summary> - /// Injects a new instance of CONCRETETYPE to PLUGINTYPE by name. - /// </summary> - /// <typeparam name="PLUGINTYPE"></typeparam> - /// <typeparam name="CONCRETETYPE"></typeparam> - /// <param name="instanceKey"></param> - public static void InjectByName<PLUGINTYPE, CONCRETETYPE>(string instanceKey) - { - manager.InjectByName<PLUGINTYPE, CONCRETETYPE>(instanceKey); - } - - /// <summary> - /// StructureMap will return an instance of CONCRETETYPE whenever - /// a PLUGINTYPE is requested - /// </summary> - /// <typeparam name="PLUGINTYPE"></typeparam> - /// <typeparam name="CONCRETETYPE"></typeparam> - public static void InjectDefaultType<PLUGINTYPE, CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE - { - manager.AddDefaultInstance<PLUGINTYPE, CONCRETETYPE>(); - } - - /// <summary> - /// Adds a new CONCRETETYPE to StructureMap so that an instance of CONCRETETYPE - /// will be returned from a call to ObjectFactory.GetAllInstance<PLUGINTYPE>() - /// </summary> - /// <typeparam name="PLUGINTYPE"></typeparam> - /// <typeparam name="CONCRETETYPE"></typeparam> - public static void AddType<PLUGINTYPE, CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE - { - manager.AddInstance<PLUGINTYPE, CONCRETETYPE>(); - } - #region Container and setting defaults private static IContainer manager @@ -184,12 +141,32 @@ /// Strictly used for testing scenarios /// </summary> /// <param name="manager"></param> - internal static void ReplaceManager(IContainer manager) + internal static void ReplaceManager(IContainer container) { - _manager = manager; + _manager = container; } + public static void Configure(Action<Registry> configure) + { + manager.Configure(configure); + } + public static void SetDefault(Type pluginType, Instance instance) + { + manager.SetDefault(pluginType, instance); + } + + public static void SetDefault<PLUGINTYPE>(Instance instance) + { + manager.SetDefault<PLUGINTYPE>(instance); + } + + public static void SetDefault<PLUGINTYPE, CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE + { + manager.SetDefault<PLUGINTYPE, CONCRETETYPE>(); + } + + /// <summary> /// Fires when the ObjectFactory is refreshed /// </summary> Modified: trunk/Source/StructureMap/PipelineGraph.cs =================================================================== --- trunk/Source/StructureMap/PipelineGraph.cs 2008-05-30 16:36:24 UTC (rev 111) +++ trunk/Source/StructureMap/PipelineGraph.cs 2008-05-31 19:47:30 UTC (rev 112) @@ -42,6 +42,23 @@ } } + public void ImportFrom(PluginGraph graph) + { + foreach (PluginFamily family in graph.PluginFamilies) + { + if (family.IsGenericTemplate) + { + _genericsGraph.ImportFrom(family); + } + else + { + ForType(family.PluginType).ImportFrom(family); + } + } + + _profileManager.ImportFrom(graph.ProfileManager); + } + public MissingFactoryFunction OnMissingFactory { set { _missingFactory = value; } Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-05-30 16:36:24 UTC (rev 111) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-05-31 19:47:30 UTC (rev 112) @@ -376,6 +376,7 @@ <Compile Include="ErrorMessages.cs" /> <Compile Include="Pipeline\ConfiguredInstance.Building.cs" /> <Compile Include="Pipeline\IStructuredInstance.cs" /> + <Compile Include="Util\Cache.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <PropertyGroup> Added: trunk/Source/StructureMap/Util/Cache.cs =================================================================== --- trunk/Source/StructureMap/Util/Cache.cs (rev 0) +++ trunk/Source/StructureMap/Util/Cache.cs 2008-05-31 19:47:30 UTC (rev 112) @@ -0,0 +1,153 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using StructureMap.Graph; + +namespace StructureMap.Util +{ + public class Cache<KEY, VALUE> : IEnumerable<VALUE> where VALUE : class + { + private readonly Dictionary<KEY, VALUE> _values = new Dictionary<KEY, VALUE>(); + private readonly Func<KEY, VALUE> _onMissing = delegate(KEY key) + { + string message = string.Format("Key '{0}' could not be found", key); + throw new KeyNotFoundException(message); + }; + + private Func<VALUE, KEY> _getKey = delegate { throw new NotImplementedException(); }; + + public Cache() + { + } + + public Cache(Func<KEY, VALUE> onMissing) + { + _onMissing = onMissing; + } + + public Func<VALUE, KEY> GetKey + { + get { return _getKey; } + set { _getKey = value; } + } + + public int Count + { + get + { + return _values.Count; + } + } + + public VALUE First + { + get + { + foreach (KeyValuePair<KEY, VALUE> pair in _values) + { + return pair.Value; + } + + return null; + } + } + + public void Store(KEY key, VALUE value) + { + if (_values.ContainsKey(key)) + { + _values[key] = value; + } + else + { + _values.Add(key, value); + } + } + + public void Fill(KEY key, VALUE value) + { + if (_values.ContainsKey(key)) + { + return; + } + + _values.Add(key, value); + } + + public VALUE Retrieve(KEY key) + { + if (!_values.ContainsKey(key)) + { + VALUE value = _onMissing(key); + _values.Add(key, value); + } + + return _values[key]; + } + + public void Each(Action<VALUE> action) + { + foreach (KeyValuePair<KEY, VALUE> pair in _values) + { + action(pair.Value); + } + } + + public bool Has(KEY key) + { + return _values.ContainsKey(key); + } + + public bool Exists(Predicate<VALUE> predicate) + { + bool returnValue = false; + + Each(delegate(VALUE value) + { + returnValue |= predicate(value); + }); + + return returnValue; + } + + public VALUE Find(Predicate<VALUE> predicate) + { + foreach (KeyValuePair<KEY, VALUE> pair in _values) + { + if (predicate(pair.Value)) + { + return pair.Value; + } + } + + return null; + } + + public VALUE[] GetAll() + { + VALUE[] returnValue = new VALUE[Count]; + _values.Values.CopyTo(returnValue, 0); + + return returnValue; + } + + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable<VALUE>) this).GetEnumerator(); + } + + public IEnumerator<VALUE> GetEnumerator() + { + return _values.Values.GetEnumerator(); + } + + public void Remove(KEY key) + { + if (_values.ContainsKey(key)) + { + _values.Remove(key); + } + } + } +} Modified: trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs 2008-05-30 16:36:24 UTC (rev 111) +++ trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs 2008-05-31 19:47:30 UTC (rev 112) @@ -4,9 +4,7 @@ using Rhino.Mocks.Constraints; using StructureMap.Attributes; using StructureMap.Graph; -using StructureMap.Interceptors; using StructureMap.Pipeline; -using StructureMap.Source; namespace StructureMap.Testing.Attributes { @@ -18,9 +16,9 @@ PluginFamilyAttribute att = new PluginFamilyAttribute("something"); att.Scope = scope; - PluginFamily family = new PluginFamily(typeof(TypeThatDoesNotHaveCustomMementoSource)); + PluginFamily family = new PluginFamily(typeof (TypeThatDoesNotHaveCustomMementoSource)); att.Configure(family); - + Assert.IsInstanceOfType(interceptorType, family.Policy); } @@ -85,7 +83,7 @@ using (mocks.Record()) { - SetupResult.For(family.PluginType).Return(typeof(TypeThatDoesNotHaveCustomMementoSource)); + SetupResult.For(family.PluginType).Return(typeof (TypeThatDoesNotHaveCustomMementoSource)); family.AddMementoSource(null); LastCall.Repeat.Never(); @@ -97,7 +95,7 @@ } } - + [Test] public void PerRequest_DoesNot_call_SetScopeTo_on_family() { Modified: trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-05-30 16:36:24 UTC (rev 111) +++ trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-05-31 19:47:30 UTC (rev 112) @@ -137,7 +137,7 @@ IMockedService3 service3 = _container.GetInstance<IMockedService3>(); ConcreteClass concreteClass = _container.FillDependencies<ConcreteClass>(); - + Assert.AreSame(service, concreteClass.Service); Assert.AreSame(service2, concreteClass.Service2); Assert.AreSame(service3, concreteClass.Service3); Modified: trunk/Source/StructureMap.Testing/BuildSessionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-05-30 16:36:24 UTC (rev 111) +++ trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-05-31 19:47:30 UTC (rev 112) @@ -33,28 +33,58 @@ } } + public class WidgetHolder + { + private readonly IWidget[] _widgets; + + public WidgetHolder(IWidget[] widgets) + { + _widgets = widgets; + } + + public IWidget[] Widgets + { + get { return _widgets; } + } + } + [Test] - public void Throw_200_When_trying_to_build_an_instance_that_cannot_be_found() + public void Get_a_unique_value_for_each_individual_buildsession() { - PipelineGraph graph = new PipelineGraph(new PluginGraph()); + int count = 0; - assertActionThrowsErrorCode(200, delegate() + BuildSession session = new BuildSession(new PluginGraph()); + BuildSession session2 = new BuildSession(new PluginGraph()); + ConstructorInstance instance = new ConstructorInstance(delegate { - BuildSession session = new BuildSession(graph, null); - session.CreateInstance(typeof (IGateway), "A Name"); + count++; + return new ColorRule("Red"); }); + + object result1 = session.CreateInstance(typeof (ColorRule), instance); + object result2 = session.CreateInstance(typeof (ColorRule), instance); + object result3 = session2.CreateInstance(typeof (ColorRule), instance); + object result4 = session2.CreateInstance(typeof (ColorRule), instance); + + Assert.AreEqual(2, count); + + Assert.AreSame(result1, result2); + Assert.AreNotSame(result1, result3); + Assert.AreSame(result3, result4); } [Test] - public void When_calling_CreateInstance_if_no_default_can_be_found_throw_202() + public void If_no_child_array_is_explicitly_defined_return_all_instances() { - PipelineGraph graph = new PipelineGraph(new PluginGraph()); - - assertActionThrowsErrorCode(202, delegate() + IContainer manager = new Container(delegate(Registry registry) { - BuildSession session = new BuildSession(graph, null); - session.CreateInstance(typeof (IGateway)); + registry.AddInstanceOf<IWidget>(new ColorWidget("Red")); + registry.AddInstanceOf<IWidget>(new ColorWidget("Blue")); + registry.AddInstanceOf<IWidget>(new ColorWidget("Green")); }); + + WidgetHolder holder = manager.GetInstance<WidgetHolder>(); + Assert.AreEqual(3, holder.Widgets.Length); } [Test] @@ -63,7 +93,7 @@ int count = 0; BuildSession session = new BuildSession(new PluginGraph()); - ConstructorInstance instance = new ConstructorInstance(delegate() + ConstructorInstance instance = new ConstructorInstance(delegate { count++; return new ColorRule("Red"); @@ -73,7 +103,7 @@ object result2 = session.CreateInstance(typeof (ColorRule), instance); object result3 = session.CreateInstance(typeof (ColorRule), instance); object result4 = session.CreateInstance(typeof (ColorRule), instance); - + Assert.AreEqual(1, count); Assert.AreSame(result1, result2); @@ -86,7 +116,7 @@ { int count = 0; - ConstructorInstance instance = new ConstructorInstance(delegate() + ConstructorInstance instance = new ConstructorInstance(delegate { count++; return new ColorRule("Red"); @@ -98,10 +128,10 @@ BuildSession session = new BuildSession(graph); - object result1 = session.CreateInstance(typeof(ColorRule)); - object result2 = session.CreateInstance(typeof(ColorRule)); - object result3 = session.CreateInstance(typeof(ColorRule)); - object result4 = session.CreateInstance(typeof(ColorRule)); + object result1 = session.CreateInstance(typeof (ColorRule)); + object result2 = session.CreateInstance(typeof (ColorRule)); + object result3 = session.CreateInstance(typeof (ColorRule)); + object result4 = session.CreateInstance(typeof (ColorRule)); Assert.AreEqual(1, count); @@ -111,57 +141,27 @@ } [Test] - public void Get_a_unique_value_for_each_individual_buildsession() + public void Throw_200_When_trying_to_build_an_instance_that_cannot_be_found() { - int count = 0; + PipelineGraph graph = new PipelineGraph(new PluginGraph()); - BuildSession session = new BuildSession(new PluginGraph()); - BuildSession session2 = new BuildSession(new PluginGraph()); - ConstructorInstance instance = new ConstructorInstance(delegate() + assertActionThrowsErrorCode(200, delegate { - count++; - return new ColorRule("Red"); + BuildSession session = new BuildSession(graph, null); + session.CreateInstance(typeof (IGateway), "A Name"); }); - - object result1 = session.CreateInstance(typeof(ColorRule), instance); - object result2 = session.CreateInstance(typeof(ColorRule), instance); - object result3 = session2.CreateInstance(typeof(ColorRule), instance); - object result4 = session2.CreateInstance(typeof(ColorRule), instance); - - Assert.AreEqual(2, count); - - Assert.AreSame(result1, result2); - Assert.AreNotSame(result1, result3); - Assert.AreSame(result3, result4); } [Test] - public void If_no_child_array_is_explicitly_defined_return_all_instances() + public void When_calling_CreateInstance_if_no_default_can_be_found_throw_202() { - IContainer manager = new StructureMap.Container(delegate(Registry registry) + PipelineGraph graph = new PipelineGraph(new PluginGraph()); + + assertActionThrowsErrorCode(202, delegate { - registry.AddInstanceOf<IWidget>(new ColorWidget("Red")); - registry.AddInstanceOf<IWidget>(new ColorWidget("Blue")); - registry.AddInstanceOf<IWidget>(new ColorWidget("Green")); + BuildSession session = new BuildSession(graph, null); + session.CreateInstance(typeof (IGateway)); }); - - WidgetHolder holder = manager.GetInstance<WidgetHolder>(); - Assert.AreEqual(3, holder.Widgets.Length); } - - public class WidgetHolder - { - private readonly IWidget[] _widgets; - - public WidgetHolder(IWidget[] widgets) - { - _widgets = widgets; - } - - public IWidget[] Widgets - { - get { return _widgets; } - } - } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs 2008-05-30 16:36:24 UTC (rev 111) +++ trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs 2008-05-31 19:47:30 UTC (rev 112) @@ -53,13 +53,23 @@ Converter<ConfigurationParser, string> converter = delegate(ConfigurationParser parser) { return parser.Id; }; - string[] actuals = Array.ConvertAll<ConfigurationParser, string>(parsers, converter); + string[] actuals = Array.ConvertAll(parsers, converter); Array.Sort(actuals); Assert.AreEqual(expected, actuals); } [Test] + public void Do_NOT_Log_exception_100_if_StructureMap_config_is_required_and_missing() + { + assertNoErrorIsLogged(100, delegate + { + DataMother.RemoveStructureMapConfig(); + builder.UseAndEnforceExistenceOfDefaultFile = false; + }); + } + + [Test] public void DoNotUseDefaultAndUseADifferentFile() { DataMother.RemoveStructureMapConfig(); @@ -74,124 +84,107 @@ } [Test] - public void Put_the_file_name_onto_ConfigurationParser() + public void GetIncludes() { + DataMother.RemoveStructureMapConfig(); + + DataMother.WriteDocument("Include1.xml"); + DataMother.WriteDocument("Include2.xml"); + DataMother.WriteDocument("Master.xml"); + builder.UseAndEnforceExistenceOfDefaultFile = false; builder.IgnoreDefaultFile = true; + builder.IncludeFile("Master.xml"); + assertParserIdList("Include1", "Include2", "Master"); + } + + [Test] + public void GetMultiples() + { + DataMother.WriteDocument("Include1.xml"); + DataMother.WriteDocument("Include2.xml"); + DataMother.WriteDocument("Master.xml"); + DataMother.WriteDocument("GenericsTesting.xml"); builder.IncludeFile("GenericsTesting.xml"); + builder.UseAndEnforceExistenceOfDefaultFile = true; + builder.IncludeFile("Master.xml"); - ConfigurationParser[] parsers = builder.GetParsers(); - Assert.AreEqual("GenericsTesting.xml", parsers[0].Description); + assertParserIdList("Generics", "Include1", "Include2", "Main", "Master"); } [Test] public void If_adding_a_node_directly_use_stacktrace_to_get_the_node() { - } [Test] - public void Log_exception_100_if_StructureMap_config_is_required_and_missing() + public void Log_error_150_if_a_designated_Include_cannot_be_opened() { - assertErrorIsLogged(100, delegate() - { - DataMother.RemoveStructureMapConfig(); - builder.UseAndEnforceExistenceOfDefaultFile = true; - }); - } + assertErrorIsLogged(150, delegate + { + builder.IncludeFile("Master.xml"); - [Test] - public void Do_NOT_Log_exception_100_if_StructureMap_config_is_required_and_missing() - { - assertNoErrorIsLogged(100, delegate() - { - DataMother.RemoveStructureMapConfig(); - builder.UseAndEnforceExistenceOfDefaultFile = false; - }); + DataMother.WriteDocument("Include1.xml"); + File.Delete("Include2.xml"); + DataMother.WriteDocument("Master.xml"); + + builder.IgnoreDefaultFile = true; + }); } [Test] - public void Log_exception_160_if_additional_file_cannot_be_opened() + public void Log_error_156_if_Include_node_does_not_have_a_File() { - assertErrorIsLogged(160, delegate() - { - builder.IncludeFile("FileThatDoesNotExist.xml"); - }); + DataMother.WriteDocument("MissingInclude.xml", "<StructureMap><Include></Include></StructureMap>"); + assertErrorIsLogged(156, delegate { builder.IncludeFile("MissingInclude.xml"); }); } [Test] - public void Log_exception_160_if_file_is_malformed() + public void Log_exception_100_if_StructureMap_config_is_required_and_missing() { - assertErrorIsLogged(160, delegate() - { - XmlDocument doc = new XmlDocument(); - doc.LoadXml("<a></a>"); - doc.Save("Malformed.xml"); - builder.IncludeFile("Malformed.xml"); - }); + assertErrorIsLogged(100, delegate + { + DataMother.RemoveStructureMapConfig(); + builder.UseAndEnforceExistenceOfDefaultFile = true; + }); } - [Test] - public void Log_error_150_if_a_designated_Include_cannot_be_opened() + public void Log_exception_160_if_additional_file_cannot_be_opened() { - assertErrorIsLogged(150, delegate() - { - builder.IncludeFile("Master.xml"); - - DataMother.WriteDocument("Include1.xml"); - File.Delete("Include2.xml"); - DataMother.WriteDocument("Master.xml"); - - builder.IgnoreDefaultFile = true; - }); + assertErrorIsLogged(160, delegate { builder.IncludeFile("FileThatDoesNotExist.xml"); }); } [Test] - public void Log_error_156_if_Include_node_does_not_have_a_File() + public void Log_exception_160_if_file_is_malformed() { - DataMother.WriteDocument("MissingInclude.xml", "<StructureMap><Include></Include></StructureMap>"); - assertErrorIsLogged(156, delegate() - { - builder.IncludeFile("MissingInclude.xml"); - }); + assertErrorIsLogged(160, delegate + { + XmlDocument doc = new XmlDocument(); + doc.LoadXml("<a></a>"); + doc.Save("Malformed.xml"); + builder.IncludeFile("Malformed.xml"); + }); } [Test] - public void GetIncludes() + public void Put_the_file_name_onto_ConfigurationParser() { - DataMother.RemoveStructureMapConfig(); - - DataMother.WriteDocument("Include1.xml"); - DataMother.WriteDocument("Include2.xml"); - DataMother.WriteDocument("Master.xml"); - builder.... [truncated message content] |
From: <jer...@us...> - 2008-05-30 16:36:27
|
Revision: 111 http://structuremap.svn.sourceforge.net/structuremap/?rev=111&view=rev Author: jeremydmiller Date: 2008-05-30 09:36:24 -0700 (Fri, 30 May 2008) Log Message: ----------- ProfileManager.ImportFrom() behavior Modified Paths: -------------- trunk/Source/StructureMap/Pipeline/ProfileManager.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerMergeTester.cs Modified: trunk/Source/StructureMap/Pipeline/ProfileManager.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2008-05-29 03:11:55 UTC (rev 110) +++ trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2008-05-30 16:36:24 UTC (rev 111) @@ -182,5 +182,20 @@ pair.Value.CopyDefault(basicType, templatedType); } } + + public void ImportFrom(ProfileManager source) + { + foreach (KeyValuePair<string, Profile> pair in source._profiles) + { + Profile fromProfile = pair.Value; + Profile toProfile = getProfile(pair.Key); + + fromProfile.FillAllTypesInto(toProfile); + } + + source._default.FillAllTypesInto(_default); + + setProfileDefaults(new GraphLog()); + } } } \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerMergeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerMergeTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerMergeTester.cs 2008-05-30 16:36:24 UTC (rev 111) @@ -0,0 +1,116 @@ +using NUnit.Framework; +using StructureMap.Pipeline; +using StructureMap.Testing.Widget; + +namespace StructureMap.Testing.Pipeline +{ + [TestFixture] + public class ProfileManagerMergeTester + { + private const string PROFILE = "profile"; + + [Test] + public void Import_the_default_for_a_profile_that_is_not_in_the_destination() + { + ProfileManager source = new ProfileManager(); + ConfiguredInstance profileInstance = new ConfiguredInstance(typeof(AWidget)); + source.SetDefault(PROFILE, typeof(IWidget), profileInstance); + + ProfileManager destination = new ProfileManager(); + + destination.ImportFrom(source); + + Assert.AreSame(profileInstance, destination.GetDefault(typeof(IWidget), PROFILE)); + } + + [Test] + public void Import_the_default_for_a_profile_make_sure_overriding_the_destination_does_not_impact_the_source() + { + ProfileManager source = new ProfileManager(); + ConfiguredInstance profileInstance = new ConfiguredInstance(typeof(AWidget)); + source.SetDefault(PROFILE, typeof(IWidget), profileInstance); + + ProfileManager destination = new ProfileManager(); + + destination.ImportFrom(source); + + // Source should be unchanged when destination IS changed + destination.SetDefault(PROFILE, typeof(IWidget), new LiteralInstance(new AWidget())); + Assert.AreSame(profileInstance, source.GetDefault(typeof(IWidget), PROFILE)); + } + + [Test] + public void Import_a_default_for_a_profile_in_destination_does_not_override_existing_default_in_that_profile() + { + ProfileManager source = new ProfileManager(); + ConfiguredInstance sourceInstance = new ConfiguredInstance(typeof(AWidget)); + source.SetDefault(PROFILE, typeof(IWidget), sourceInstance); + + // Fill in value before the ImportFrom + ProfileManager destination = new ProfileManager(); + LiteralInstance destinationInstance = new LiteralInstance(new AWidget()); + destination.SetDefault(PROFILE, typeof(IWidget), destinationInstance); + + destination.ImportFrom(source); + + + Assert.AreSame(destinationInstance, destination.GetDefault(typeof(IWidget), PROFILE)); + } + + [Test] + public void Import_the_default_if_it_is_completely_missing() + { + ProfileManager source = new ProfileManager(); + ConfiguredInstance sourceInstance = new ConfiguredInstance(typeof(AWidget)); + source.SetDefault(typeof(IWidget), sourceInstance); + + ProfileManager destination = new ProfileManager(); + destination.ImportFrom(source); + + Assert.AreSame(sourceInstance, destination.GetDefault(typeof(IWidget))); + } + + [Test] + public void Import_the_default_does_not_impact_the_source() + { + ProfileManager source = new ProfileManager(); + ConfiguredInstance sourceInstance = new ConfiguredInstance(typeof(AWidget)); + source.SetDefault(typeof(IWidget), sourceInstance); + + ProfileManager destination = new ProfileManager(); + destination.ImportFrom(source); + destination.SetDefault(typeof(IWidget), new LiteralInstance(new AWidget())); + + Assert.AreSame(sourceInstance, source.GetDefault(typeof(IWidget))); + } + + [Test] + public void Import_an_instance_from_the_default_profile() + { + ProfileManager source = new ProfileManager(); + ConfiguredInstance sourceInstance = new ConfiguredInstance(typeof(AWidget)); + source.SetDefault(PROFILE, typeof(IWidget), sourceInstance); + + ProfileManager destination = new ProfileManager(); + destination.DefaultProfileName = PROFILE; + destination.ImportFrom(source); + + Assert.AreSame(sourceInstance, destination.GetDefault(typeof(IWidget))); + } + + [Test] + public void Import_a_default_when_the_destination_already_has_an_active_profile() + { + ProfileManager source = new ProfileManager(); + ConfiguredInstance sourceInstance = new ConfiguredInstance(typeof(AWidget)); + source.SetDefault(PROFILE, typeof(IWidget), sourceInstance); + + ProfileManager destination = new ProfileManager(); + destination.SetDefault(PROFILE, typeof(Rule), new ConfiguredInstance(typeof(ColorRule))); + destination.CurrentProfile = PROFILE; + destination.ImportFrom(source); + + Assert.AreSame(sourceInstance, destination.GetDefault(typeof(IWidget))); + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-29 03:11:55 UTC (rev 110) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-30 16:36:24 UTC (rev 111) @@ -332,6 +332,7 @@ <Compile Include="Pipeline\DefaultInstanceTester.cs" /> <Compile Include="Pipeline\InstanceTester.cs" /> <Compile Include="Pipeline\LiteralInstanceTester.cs" /> + <Compile Include="Pipeline\ProfileManagerMergeTester.cs" /> <Compile Include="Pipeline\ProfileManagerTester.cs" /> <Compile Include="Pipeline\ProfileTester.cs" /> <Compile Include="Pipeline\PrototypeInstanceTester.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-05-29 03:12:01
|
Revision: 110 http://structuremap.svn.sourceforge.net/structuremap/?rev=110&view=rev Author: jeremydmiller Date: 2008-05-28 20:11:55 -0700 (Wed, 28 May 2008) Log Message: ----------- Starting the InstanceFactory.Merge functionality Modified Paths: -------------- trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap.Testing/Container/ContainerTester.cs Removed Paths: ------------- trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-05-28 15:50:14 UTC (rev 109) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-05-29 03:11:55 UTC (rev 110) @@ -157,6 +157,11 @@ _instanceBuilders.Add(family.Plugins); foreach (Instance instance in family.GetAllInstances()) { + if (_instances.ContainsKey(instance.Name)) + { + continue; + } + AddInstance(instance); } } Added: trunk/Source/StructureMap.Testing/Container/ContainerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/ContainerTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Container/ContainerTester.cs 2008-05-29 03:11:55 UTC (rev 110) @@ -0,0 +1,233 @@ +using System; +using NUnit.Framework; +using StructureMap.Configuration.DSL; +using StructureMap.Exceptions; +using StructureMap.Graph; +using StructureMap.Interceptors; +using StructureMap.Pipeline; +using StructureMap.Source; +using StructureMap.Testing.GenericWidgets; +using StructureMap.Testing.Widget; +using StructureMap.Testing.Widget3; + +namespace StructureMap.Testing.Container +{ + [TestFixture] + public class ContainerTester : Registry + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + _manager = new StructureMap.Container(delegate(Registry registry) + { + registry.ScanAssemblies().IncludeAssembly("StructureMap.Testing.Widget"); + registry.BuildInstancesOf<Rule>(); + registry.BuildInstancesOf<IWidget>(); + registry.BuildInstancesOf<WidgetMaker>(); + }); + } + + #endregion + + private IContainer _manager; + + private void addColorMemento(string Color) + { + ConfiguredInstance instance = new ConfiguredInstance(Color).WithConcreteKey("Color").SetProperty("Color", Color); + + _manager.AddInstance<Rule>(instance); + _manager.AddInstance<IWidget>(instance); + _manager.AddInstance<WidgetMaker>(instance); + } + + public interface IProvider + { + } + + public class Provider : IProvider + { + } + + public class ClassThatUsesProvider + { + private readonly IProvider _provider; + + public ClassThatUsesProvider(IProvider provider) + { + _provider = provider; + } + + + public IProvider Provider + { + get { return _provider; } + } + } + + public class DifferentProvider : IProvider + { + } + + [Test] + public void CanBuildConcreteTypesThatAreNotPreviouslyRegistered() + { + IContainer manager = new StructureMap.Container(delegate(Registry registry) + { + // Create a new Container that has a default instance configured for only the + // IProvider interface. Container is the real "container" behind ObjectFactory + registry.ForRequestedType<IProvider>().TheDefaultIsConcreteType<Provider>(); + }); + + // Now, have that same Container create a ClassThatUsesProvider. StructureMap will + // see that ClassThatUsesProvider is concrete, determine its constructor args, and build one + // for you with the default IProvider. No other configuration necessary. + ClassThatUsesProvider classThatUsesProvider = manager.GetInstance<ClassThatUsesProvider>(); + Assert.IsInstanceOfType(typeof (Provider), classThatUsesProvider.Provider); + } + + [Test] + public void CanBuildConcreteTypesThatAreNotPreviouslyRegisteredWithArgumentsProvided() + { + IContainer manager = new StructureMap.Container(delegate(Registry registry) + { + registry.ForRequestedType<IProvider>().TheDefaultIsConcreteType<Provider>(); + }); + + DifferentProvider differentProvider = new DifferentProvider(); + ExplicitArguments args = new ExplicitArguments(); + args.Set<IProvider>(differentProvider); + + ClassThatUsesProvider classThatUsesProvider = manager.GetInstance<ClassThatUsesProvider>(args); + Assert.AreSame(differentProvider, classThatUsesProvider.Provider); + } + + + + + [Test] + public void FindAPluginFamilyForAGenericTypeFromPluginTypeName() + { + Type serviceType = typeof (IService<string>); + PluginGraph pluginGraph = PluginGraph.BuildGraphFromAssembly(serviceType.Assembly); + PipelineGraph pipelineGraph = new PipelineGraph(pluginGraph); + + Type stringService = typeof (IService<string>); + + IInstanceFactory factory = pipelineGraph.ForType(stringService); + Assert.AreEqual(stringService, factory.PluginType); + } + + [Test] + public void GetDefaultInstance() + { + addColorMemento("Red"); + addColorMemento("Orange"); + addColorMemento("Blue"); + + _manager.SetDefault(typeof (Rule), "Blue"); + ColorRule rule = _manager.GetInstance(typeof (Rule)) as ColorRule; + + Assert.IsNotNull(rule); + Assert.AreEqual("Blue", rule.Color); + } + + [Test] + public void GetInstanceOf3Types() + { + addColorMemento("Red"); + addColorMemento("Orange"); + addColorMemento("Blue"); + + ColorRule rule = _manager.GetInstance(typeof (Rule), "Blue") as ColorRule; + Assert.IsNotNull(rule); + Assert.AreEqual("Blue", rule.Color); + + ColorWidget widget = _manager.GetInstance(typeof (IWidget), "Red") as ColorWidget; + Assert.IsNotNull(widget); + Assert.AreEqual("Red", widget.Color); + + ColorWidgetMaker maker = _manager.GetInstance(typeof (WidgetMaker), "Orange") as ColorWidgetMaker; + Assert.IsNotNull(maker); + Assert.AreEqual("Orange", maker.Color); + } + + [Test, ExpectedException(typeof (StructureMapException))] + public void GetMissingType() + { + object o = _manager.GetInstance(typeof (string)); + } + + + private void assertColorIs(IContainer manager, string color) + { + ColorService rule = (ColorService) manager.GetInstance<IService>(); + Assert.AreEqual(color, rule.Color); + } + + [Test] + public void SetDefaultInstanceByString() + { + IContainer manager = new StructureMap.Container(delegate(Registry registry) + { + registry.ForRequestedType<IService>() + .AddInstance(Instance<ColorService>().WithName("Red").WithProperty("color").EqualTo("Red")) + .AddInstance(Instance<ColorService>().WithName("Blue").WithProperty("color").EqualTo("Blue")) + .AddInstance(Instance<ColorService>().WithName("Green").WithProperty("color").EqualTo("Green")); + }); + + manager.SetDefault(typeof(IService), "Red"); + assertColorIs(manager, "Red"); + + manager.SetDefault(typeof(IService), "Green"); + assertColorIs(manager, "Green"); + + manager.SetDefault(typeof(IService), "Blue"); + assertColorIs(manager, "Blue"); + } + + [Test] + public void Can_set_profile_name_and_reset_defaults() + { + IContainer manager = new StructureMap.Container(delegate(Registry registry) + { + registry.ForRequestedType<IService>() + .TheDefaultIs(Instance<ColorService>().WithName("Orange").WithProperty("color").EqualTo("Orange")) + .AddInstance(Instance<ColorService>().WithName("Red").WithProperty("color").EqualTo("Red")) + .AddInstance(Instance<ColorService>().WithName("Blue").WithProperty("color").EqualTo("Blue")) + .AddInstance(Instance<ColorService>().WithName("Green").WithProperty("color").EqualTo("Green")); + + registry.CreateProfile("Red").For<IService>().UseNamedInstance("Red"); + registry.CreateProfile("Blue").For<IService>().UseNamedInstance("Blue"); + }); + + assertColorIs(manager, "Orange"); + + manager.SetDefaultsToProfile("Red"); + assertColorIs(manager, "Red"); + + manager.SetDefaultsToProfile("Blue"); + assertColorIs(manager, "Blue"); + + manager.SetDefaultsToProfile(string.Empty); + assertColorIs(manager, "Orange"); + } + + [Test, ExpectedException(typeof(StructureMapException))] + public void TryToGetDefaultInstanceWithNoInstance() + { + StructureMap.Container manager = new StructureMap.Container(new PluginGraph()); + manager.GetInstance<IService>(); + } + + [Test, ExpectedException(typeof(StructureMapConfigurationException))] + public void CTOR_throws_StructureMapConfigurationException_if_there_is_an_error() + { + PluginGraph graph = new PluginGraph(); + graph.Log.RegisterError(400, new ApplicationException("Bad!")); + + new StructureMap.Container(graph); + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs 2008-05-28 15:50:14 UTC (rev 109) +++ trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs 2008-05-29 03:11:55 UTC (rev 110) @@ -94,5 +94,21 @@ Assert.IsNotNull(factory.FindInstance("New2")); Assert.IsNotNull(factory.FindInstance("New3")); } + + [Test] + public void Merge_from_PluginFamily_will_not_replace_an_existing_instance() + { + InstanceFactory factory = new InstanceFactory(typeof(IWidget)); + LiteralInstance instance1 = new LiteralInstance(new AWidget()).WithName("New"); + factory.AddInstance(instance1); + + PluginFamily family = new PluginFamily(typeof(IWidget)); + family.AddInstance(new LiteralInstance(new AWidget()).WithName("New")); + + factory.Merge(family); + + Assert.AreSame(instance1, factory.FindInstance("New")); + + } } } \ No newline at end of file Deleted: trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs 2008-05-28 15:50:14 UTC (rev 109) +++ trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs 2008-05-29 03:11:55 UTC (rev 110) @@ -1,233 +0,0 @@ -using System; -using NUnit.Framework; -using StructureMap.Configuration.DSL; -using StructureMap.Exceptions; -using StructureMap.Graph; -using StructureMap.Interceptors; -using StructureMap.Pipeline; -using StructureMap.Source; -using StructureMap.Testing.GenericWidgets; -using StructureMap.Testing.Widget; -using StructureMap.Testing.Widget3; - -namespace StructureMap.Testing.Container -{ - [TestFixture] - public class InstanceManagerTester : Registry - { - #region Setup/Teardown - - [SetUp] - public void SetUp() - { - _manager = new StructureMap.Container(delegate(Registry registry) - { - registry.ScanAssemblies().IncludeAssembly("StructureMap.Testing.Widget"); - registry.BuildInstancesOf<Rule>(); - registry.BuildInstancesOf<IWidget>(); - registry.BuildInstancesOf<WidgetMaker>(); - }); - } - - #endregion - - private IContainer _manager; - - private void addColorMemento(string Color) - { - ConfiguredInstance instance = new ConfiguredInstance(Color).WithConcreteKey("Color").SetProperty("Color", Color); - - _manager.AddInstance<Rule>(instance); - _manager.AddInstance<IWidget>(instance); - _manager.AddInstance<WidgetMaker>(instance); - } - - public interface IProvider - { - } - - public class Provider : IProvider - { - } - - public class ClassThatUsesProvider - { - private readonly IProvider _provider; - - public ClassThatUsesProvider(IProvider provider) - { - _provider = provider; - } - - - public IProvider Provider - { - get { return _provider; } - } - } - - public class DifferentProvider : IProvider - { - } - - [Test] - public void CanBuildConcreteTypesThatAreNotPreviouslyRegistered() - { - IContainer manager = new StructureMap.Container(delegate(Registry registry) - { - // Create a new Container that has a default instance configured for only the - // IProvider interface. Container is the real "container" behind ObjectFactory - registry.ForRequestedType<IProvider>().TheDefaultIsConcreteType<Provider>(); - }); - - // Now, have that same Container create a ClassThatUsesProvider. StructureMap will - // see that ClassThatUsesProvider is concrete, determine its constructor args, and build one - // for you with the default IProvider. No other configuration necessary. - ClassThatUsesProvider classThatUsesProvider = manager.GetInstance<ClassThatUsesProvider>(); - Assert.IsInstanceOfType(typeof (Provider), classThatUsesProvider.Provider); - } - - [Test] - public void CanBuildConcreteTypesThatAreNotPreviouslyRegisteredWithArgumentsProvided() - { - IContainer manager = new StructureMap.Container(delegate(Registry registry) - { - registry.ForRequestedType<IProvider>().TheDefaultIsConcreteType<Provider>(); - }); - - DifferentProvider differentProvider = new DifferentProvider(); - ExplicitArguments args = new ExplicitArguments(); - args.Set<IProvider>(differentProvider); - - ClassThatUsesProvider classThatUsesProvider = manager.GetInstance<ClassThatUsesProvider>(args); - Assert.AreSame(differentProvider, classThatUsesProvider.Provider); - } - - - - - [Test] - public void FindAPluginFamilyForAGenericTypeFromPluginTypeName() - { - Type serviceType = typeof (IService<string>); - PluginGraph pluginGraph = PluginGraph.BuildGraphFromAssembly(serviceType.Assembly); - PipelineGraph pipelineGraph = new PipelineGraph(pluginGraph); - - Type stringService = typeof (IService<string>); - - IInstanceFactory factory = pipelineGraph.ForType(stringService); - Assert.AreEqual(stringService, factory.PluginType); - } - - [Test] - public void GetDefaultInstance() - { - addColorMemento("Red"); - addColorMemento("Orange"); - addColorMemento("Blue"); - - _manager.SetDefault(typeof (Rule), "Blue"); - ColorRule rule = _manager.GetInstance(typeof (Rule)) as ColorRule; - - Assert.IsNotNull(rule); - Assert.AreEqual("Blue", rule.Color); - } - - [Test] - public void GetInstanceOf3Types() - { - addColorMemento("Red"); - addColorMemento("Orange"); - addColorMemento("Blue"); - - ColorRule rule = _manager.GetInstance(typeof (Rule), "Blue") as ColorRule; - Assert.IsNotNull(rule); - Assert.AreEqual("Blue", rule.Color); - - ColorWidget widget = _manager.GetInstance(typeof (IWidget), "Red") as ColorWidget; - Assert.IsNotNull(widget); - Assert.AreEqual("Red", widget.Color); - - ColorWidgetMaker maker = _manager.GetInstance(typeof (WidgetMaker), "Orange") as ColorWidgetMaker; - Assert.IsNotNull(maker); - Assert.AreEqual("Orange", maker.Color); - } - - [Test, ExpectedException(typeof (StructureMapException))] - public void GetMissingType() - { - object o = _manager.GetInstance(typeof (string)); - } - - - private void assertColorIs(IContainer manager, string color) - { - ColorService rule = (ColorService) manager.GetInstance<IService>(); - Assert.AreEqual(color, rule.Color); - } - - [Test] - public void SetDefaultInstanceByString() - { - IContainer manager = new StructureMap.Container(delegate(Registry registry) - { - registry.ForRequestedType<IService>() - .AddInstance(Instance<ColorService>().WithName("Red").WithProperty("color").EqualTo("Red")) - .AddInstance(Instance<ColorService>().WithName("Blue").WithProperty("color").EqualTo("Blue")) - .AddInstance(Instance<ColorService>().WithName("Green").WithProperty("color").EqualTo("Green")); - }); - - manager.SetDefault(typeof(IService), "Red"); - assertColorIs(manager, "Red"); - - manager.SetDefault(typeof(IService), "Green"); - assertColorIs(manager, "Green"); - - manager.SetDefault(typeof(IService), "Blue"); - assertColorIs(manager, "Blue"); - } - - [Test] - public void Can_set_profile_name_and_reset_defaults() - { - IContainer manager = new StructureMap.Container(delegate(Registry registry) - { - registry.ForRequestedType<IService>() - .TheDefaultIs(Instance<ColorService>().WithName("Orange").WithProperty("color").EqualTo("Orange")) - .AddInstance(Instance<ColorService>().WithName("Red").WithProperty("color").EqualTo("Red")) - .AddInstance(Instance<ColorService>().WithName("Blue").WithProperty("color").EqualTo("Blue")) - .AddInstance(Instance<ColorService>().WithName("Green").WithProperty("color").EqualTo("Green")); - - registry.CreateProfile("Red").For<IService>().UseNamedInstance("Red"); - registry.CreateProfile("Blue").For<IService>().UseNamedInstance("Blue"); - }); - - assertColorIs(manager, "Orange"); - - manager.SetDefaultsToProfile("Red"); - assertColorIs(manager, "Red"); - - manager.SetDefaultsToProfile("Blue"); - assertColorIs(manager, "Blue"); - - manager.SetDefaultsToProfile(string.Empty); - assertColorIs(manager, "Orange"); - } - - [Test, ExpectedException(typeof(StructureMapException))] - public void TryToGetDefaultInstanceWithNoInstance() - { - StructureMap.Container manager = new StructureMap.Container(new PluginGraph()); - manager.GetInstance<IService>(); - } - - [Test, ExpectedException(typeof(StructureMapConfigurationException))] - public void CTOR_throws_StructureMapConfigurationException_if_there_is_an_error() - { - PluginGraph graph = new PluginGraph(); - graph.Log.RegisterError(400, new ApplicationException("Bad!")); - - new StructureMap.Container(graph); - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-28 15:50:14 UTC (rev 109) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-29 03:11:55 UTC (rev 110) @@ -214,7 +214,7 @@ <Compile Include="Container\InstanceFactoryTester.cs"> <SubType>Code</SubType> </Compile> - <Compile Include="Container\InstanceManagerTester.cs"> + <Compile Include="Container\ContainerTester.cs"> <SubType>Code</SubType> </Compile> <Compile Include="Container\IntegratedTester.cs"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-05-28 15:50:17
|
Revision: 109 http://structuremap.svn.sourceforge.net/structuremap/?rev=109&view=rev Author: jeremydmiller Date: 2008-05-28 08:50:14 -0700 (Wed, 28 May 2008) Log Message: ----------- Modified Paths: -------------- trunk/Source/StructureMap/Emitting/ClassBuilder.cs trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs trunk/Source/StructureMap/InstanceBuilder.cs trunk/Source/StructureMap/InstanceBuilderList.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs trunk/Source/StructureMap.AutoMocking/StructureMap.AutoMocking.csproj trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs trunk/Source/StructureMap.Testing/Container/EmittingTester.cs trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs trunk/Source/StructureMap.Testing.Widget/Decision.cs trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs Added Paths: ----------- trunk/Source/StructureMap.AutoMocking/AutoMockedContainer.cs trunk/Source/StructureMap.Testing/InstanceBuilderListTester.cs trunk/Source/StructureMap.Testing/MergingTester.cs Removed Paths: ------------- trunk/Source/StructureMap/InstanceManager.cs trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs Modified: trunk/Source/StructureMap/Emitting/ClassBuilder.cs =================================================================== --- trunk/Source/StructureMap/Emitting/ClassBuilder.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap/Emitting/ClassBuilder.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -83,31 +83,6 @@ ilgen.Emit(OpCodes.Ret); } - - public void AddReadonlyStringProperty(string propertyName, string propertyValue, bool @override) - { - PropertyBuilder prop = - _newTypeBuilder.DefineProperty(propertyName, PropertyAttributes.HasDefault, typeof (string), null); - - MethodAttributes atts = MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig | - MethodAttributes.Final | MethodAttributes.SpecialName; - - string getterMethodName = "get_" + propertyName; - - MethodBuilder methodGet = - _newTypeBuilder.DefineMethod(getterMethodName, atts, CallingConventions.Standard, typeof (string), null); - ILGenerator gen = methodGet.GetILGenerator(); - - LocalBuilder ilReturn = gen.DeclareLocal(typeof (string)); - - gen.Emit(OpCodes.Ldstr, propertyValue); - gen.Emit(OpCodes.Stloc_0); - gen.Emit(OpCodes.Ldloc_0); - gen.Emit(OpCodes.Ret); - - prop.SetGetMethod(methodGet); - } - public void AddPluggedTypeGetter(Type pluggedType) { PropertyBuilder prop = Modified: trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs =================================================================== --- trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -94,7 +94,6 @@ private void configureClassBuilder(ClassBuilder builderClass, Plugin plugin) { - builderClass.AddReadonlyStringProperty("ConcreteTypeKey", plugin.ConcreteKey, true); builderClass.AddPluggedTypeGetter(plugin.PluggedType); BuildInstanceMethod method = new BuildInstanceMethod(plugin); Modified: trunk/Source/StructureMap/InstanceBuilder.cs =================================================================== --- trunk/Source/StructureMap/InstanceBuilder.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap/InstanceBuilder.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -15,8 +15,6 @@ { } - public abstract string ConcreteTypeKey { get; } - public abstract Type PluggedType { get; } public abstract object BuildInstance(IConfiguredInstance instance, IBuildSession session); Modified: trunk/Source/StructureMap/InstanceBuilderList.cs =================================================================== --- trunk/Source/StructureMap/InstanceBuilderList.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap/InstanceBuilderList.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -9,6 +9,7 @@ { private readonly Dictionary<Type, InstanceBuilder> _builders = new Dictionary<Type, InstanceBuilder>(); private readonly Type _pluginType; + private readonly Dictionary<string, Type> _aliases = new Dictionary<string, Type>(); public InstanceBuilderList(Type pluginType, IEnumerable<Plugin> plugins) @@ -17,7 +18,17 @@ processPlugins(plugins); } + public InstanceBuilderList(Type pluginType) + { + _pluginType = pluginType; + } + public int BuilderCount + { + get { return _builders.Count; } + } + + public InstanceBuilder FindByType(Type pluggedType) { if (pluggedType == null) @@ -34,7 +45,7 @@ if (TypeRules.CanBeCast(_pluginType, pluggedType)) { Plugin plugin = new Plugin(pluggedType); - processPlugins(new Plugin[] {plugin}); + processPlugin(plugin); return _builders[pluggedType]; } @@ -44,24 +55,32 @@ public InstanceBuilder FindByConcreteKey(string concreteKey) { - foreach (KeyValuePair<Type, InstanceBuilder> pair in _builders) + if (_aliases.ContainsKey(concreteKey)) { - if (pair.Value.ConcreteTypeKey == concreteKey) - { - return pair.Value; - } + Type pluggedType = _aliases[concreteKey]; + return FindByType(pluggedType); } return null; } - public void Add(Type pluggedType, InstanceBuilder builder) + private void processPlugin(Plugin plugin) { - _builders.Add(pluggedType, builder); + processPlugins(new Plugin[] { plugin }); } private void processPlugins(IEnumerable<Plugin> plugins) { + foreach (Plugin plugin in plugins) + { + if (_aliases.ContainsKey(plugin.ConcreteKey)) + { + continue; + } + + _aliases.Add(plugin.ConcreteKey, plugin.PluggedType); + } + List<InstanceBuilder> list = createInstanceBuilders(plugins); foreach (InstanceBuilder builder in list) { @@ -71,8 +90,27 @@ private List<InstanceBuilder> createInstanceBuilders(IEnumerable<Plugin> plugins) { - InstanceBuilderAssembly builderAssembly = new InstanceBuilderAssembly(_pluginType, plugins); + List<Plugin> list = new List<Plugin>(); + foreach (Plugin plugin in plugins) + { + if (!_builders.ContainsKey(plugin.PluggedType)) + { + list.Add(plugin); + } + } + + InstanceBuilderAssembly builderAssembly = new InstanceBuilderAssembly(_pluginType, list); return builderAssembly.Compile(); } + + public void Add(Plugin plugin) + { + Add(new Plugin[] {plugin}); + } + + public void Add(IEnumerable<Plugin> plugins) + { + processPlugins(plugins); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -18,6 +18,11 @@ #region constructor functions + public InstanceFactory(Type pluginType) : this(new PluginFamily(pluginType)) + { + + } + /// <summary> /// Constructor to use when troubleshooting possible configuration issues. /// </summary> @@ -107,11 +112,10 @@ } - public Instance AddType<T>() + [Obsolete] public Instance AddType<T>() { InstanceBuilder builder = _instanceBuilders.FindByType(typeof (T)); - ConfiguredInstance instance = new ConfiguredInstance(); - instance.WithConcreteKey(builder.ConcreteTypeKey).WithName(builder.ConcreteTypeKey); + ConfiguredInstance instance = new ConfiguredInstance(typeof(T)).WithName(TypePath.GetAssemblyQualifiedName(typeof(T))); AddInstance(instance); @@ -147,5 +151,14 @@ } #endregion + + public void Merge(PluginFamily family) + { + _instanceBuilders.Add(family.Plugins); + foreach (Instance instance in family.GetAllInstances()) + { + AddInstance(instance); + } + } } } \ No newline at end of file Deleted: trunk/Source/StructureMap/InstanceManager.cs =================================================================== --- trunk/Source/StructureMap/InstanceManager.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap/InstanceManager.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -1,291 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics; -using System.Text; -using StructureMap.Configuration.DSL; -using StructureMap.Diagnostics; -using StructureMap.Graph; -using StructureMap.Interceptors; -using StructureMap.Pipeline; - -namespace StructureMap -{ - /// <summary> - /// A collection of IInstanceFactory's. - /// </summary> - public class InstanceManager : TypeRules, IContainer - { - private InterceptorLibrary _interceptorLibrary; - private PipelineGraph _pipelineGraph; - - public InstanceManager(Action<Registry> action) - { - Registry registry = new Registry(); - action(registry); - - construct(registry.Build()); - } - - public InstanceManager(Registry registry) : this(registry.Build()) - { - } - - public InstanceManager() : this(new PluginGraph()) - { - } - - /// <summary> - /// Constructor to create an InstanceManager - /// </summary> - /// <param name="pluginGraph">PluginGraph containing the instance and type definitions - /// for the InstanceManager</param> - /// <param name="failOnException">Flags the InstanceManager to fail or trap exceptions</param> - public InstanceManager(PluginGraph pluginGraph) - { - construct(pluginGraph); - } - - private void construct(PluginGraph pluginGraph) - { - _interceptorLibrary = pluginGraph.InterceptorLibrary; - - if (!pluginGraph.IsSealed) - { - pluginGraph.Seal(); - } - - pluginGraph.Log.AssertFailures(); - - _pipelineGraph = new PipelineGraph(pluginGraph); - } - - protected MissingFactoryFunction onMissingFactory - { - set { _pipelineGraph.OnMissingFactory = value; } - } - - #region IContainer Members - - public T GetInstance<T>(string instanceKey) - { - return (T) GetInstance(typeof (T), instanceKey); - } - - public T GetInstance<T>(Instance instance) - { - return (T) GetInstance(typeof (T), instance); - } - - public PLUGINTYPE GetInstance<PLUGINTYPE>(ExplicitArguments args) - { - Instance defaultInstance = _pipelineGraph.GetDefault(typeof (PLUGINTYPE)); - - ExplicitInstance<PLUGINTYPE> instance = new ExplicitInstance<PLUGINTYPE>(args, defaultInstance); - return GetInstance<PLUGINTYPE>(instance); - } - - public void Inject<PLUGINTYPE>(PLUGINTYPE instance) - { - _pipelineGraph.Inject(instance); - } - - public void InjectByName<PLUGINTYPE>(PLUGINTYPE instance, string instanceKey) - { - LiteralInstance literalInstance = new LiteralInstance(instance); - literalInstance.Name = instanceKey; - - AddInstance<PLUGINTYPE>(literalInstance); - } - - public void InjectByName<PLUGINTYPE, CONCRETETYPE>(string instanceKey) - { - ConfiguredInstance instance = new ConfiguredInstance(typeof(CONCRETETYPE)); - instance.Name = instanceKey; - - AddInstance<PLUGINTYPE>(instance); - } - - public T GetInstance<T>() - { - return (T) GetInstance(typeof (T)); - } - - public T FillDependencies<T>() - { - return (T) FillDependencies(typeof (T)); - } - - public void InjectStub<T>(T instance) - { - InjectStub(typeof (T), instance); - } - - public IList<T> GetAllInstances<T>() - { - List<T> list = new List<T>(); - - IBuildSession session = withNewSession(); - - foreach (T instance in forType(typeof (T)).GetAllInstances(session)) - { - list.Add(instance); - } - - return list; - } - - public void SetDefaultsToProfile(string profile) - { - _pipelineGraph.CurrentProfile = profile; - } - - /// <summary> - /// Creates the named instance of the PluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instanceKey"></param> - /// <returns></returns> - public object GetInstance(Type pluginType, string instanceKey) - { - return withNewSession().CreateInstance(pluginType, instanceKey); - } - - - /// <summary> - /// Creates a new object instance of the requested type - /// </summary> - /// <param name="pluginType"></param> - /// <returns></returns> - public object GetInstance(Type pluginType) - { - return withNewSession().CreateInstance(pluginType); - } - - - /// <summary> - /// Creates a new instance of the requested type using the InstanceMemento. Mostly used from other - /// classes to link children members - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instance"></param> - /// <returns></returns> - public object GetInstance(Type pluginType, Instance instance) - { - return withNewSession().CreateInstance(pluginType, instance); - } - - /// <summary> - /// Sets the default instance for the PluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instance"></param> - public void SetDefault(Type pluginType, Instance instance) - { - _pipelineGraph.SetDefault(pluginType, instance); - } - - /// <summary> - /// Sets the default instance for the PluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instanceKey"></param> - public void SetDefault(Type pluginType, string instanceKey) - { - ReferencedInstance reference = new ReferencedInstance(instanceKey); - _pipelineGraph.SetDefault(pluginType, reference); - } - - - /// <summary> - /// Attempts to create a new instance of the requested type. Automatically inserts the default - /// configured instance for each dependency in the StructureMap constructor function. - /// </summary> - /// <param name="type"></param> - /// <returns></returns> - public object FillDependencies(Type type) - { - if (!IsConcrete(type)) - { - throw new StructureMapException(230, type.FullName); - } - - Plugin plugin = new Plugin(type); - if (!plugin.CanBeAutoFilled) - { - throw new StructureMapException(230, type.FullName); - } - - return GetInstance(type); - } - - /// <summary> - /// Sets up the InstanceManager to return the object in the "stub" argument anytime - /// any instance of the PluginType is requested - /// </summary> - /// <param name="pluginType"></param> - /// <param name="stub"></param> - public void InjectStub(Type pluginType, object stub) - { - if (!CanBeCast(pluginType, stub.GetType())) - { - throw new StructureMapException(220, pluginType.FullName, - stub.GetType().FullName); - } - - - LiteralInstance instance = new LiteralInstance(stub); - _pipelineGraph.SetDefault(pluginType, instance); - } - - public IList GetAllInstances(Type type) - { - return forType(type).GetAllInstances(withNewSession()); - } - - public void AddInstance<T>(Instance instance) - { - _pipelineGraph.AddInstance<T>(instance); - } - - public void AddInstance<PLUGINTYPE, CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE - { - _pipelineGraph.AddInstance<PLUGINTYPE, CONCRETETYPE>(); - } - - public void AddDefaultInstance<PLUGINTYPE, CONCRETETYPE>() - { - _pipelineGraph.AddDefaultInstance<PLUGINTYPE, CONCRETETYPE>(); - } - - public string WhatDoIHave() - { - WhatDoIHaveWriter writer = new WhatDoIHaveWriter(_pipelineGraph); - return writer.GetText(); - } - - public ExplicitArgsExpression With<T>(T arg) - { - return new ExplicitArgsExpression(this).With<T>(arg); - } - - public IExplicitProperty With(string argName) - { - return new ExplicitArgsExpression(this).With(argName); - } - - #endregion - - private IBuildSession withNewSession() - { - return new BuildSession(_pipelineGraph, _interceptorLibrary); - } - - - protected IInstanceFactory forType(Type type) - { - return _pipelineGraph.ForType(type); - } - - } -} \ No newline at end of file Added: trunk/Source/StructureMap.AutoMocking/AutoMockedContainer.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/AutoMockedContainer.cs (rev 0) +++ trunk/Source/StructureMap.AutoMocking/AutoMockedContainer.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -0,0 +1,33 @@ +using System; +using StructureMap.Graph; +using StructureMap.Pipeline; + +namespace StructureMap.AutoMocking +{ + public class AutoMockedContainer : Container + { + private readonly ServiceLocator _locator; + + public AutoMockedContainer(ServiceLocator locator) + { + _locator = locator; + + onMissingFactory = delegate(Type pluginType, ProfileManager profileManager) + { + if (!pluginType.IsAbstract && pluginType.IsClass) + { + return null; + } + + object service = _locator.Service(pluginType); + InstanceFactory factory = new InstanceFactory(new PluginFamily(pluginType)); + + LiteralInstance instance = new LiteralInstance(service); + + profileManager.SetDefault(pluginType, instance); + + return factory; + }; + } + } +} \ No newline at end of file Deleted: trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -1,34 +0,0 @@ -using System; -using StructureMap.Graph; -using StructureMap.Pipeline; - -namespace StructureMap.AutoMocking -{ - public class AutoMockedInstanceManager : Container - { - private readonly ServiceLocator _locator; - - public AutoMockedInstanceManager(ServiceLocator locator) - { - _locator = locator; - - onMissingFactory = delegate(Type pluginType, ProfileManager profileManager) - { - if (!pluginType.IsAbstract && pluginType.IsClass) - { - return null; - } - - object service = _locator.Service(pluginType); - InstanceFactory factory = new InstanceFactory(new PluginFamily(pluginType)); - - LiteralInstance instance = new LiteralInstance(service); - - profileManager.SetDefault(pluginType, instance); - - return factory; - }; - } - - } -} \ No newline at end of file Modified: trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -13,13 +13,13 @@ // Note that it subclasses the RhinoMocks.MockRepository class public class RhinoAutoMocker<TARGETCLASS> : MockRepository where TARGETCLASS : class { - private readonly AutoMockedInstanceManager _manager; + private readonly AutoMockedContainer _manager; private TARGETCLASS _classUnderTest; public RhinoAutoMocker() { RhinoMocksServiceLocator locator = new RhinoMocksServiceLocator(this); - _manager = new AutoMockedInstanceManager(locator); + _manager = new AutoMockedContainer(locator); } // Replaces the inner Container in ObjectFactory with the mocked Modified: trunk/Source/StructureMap.AutoMocking/StructureMap.AutoMocking.csproj =================================================================== --- trunk/Source/StructureMap.AutoMocking/StructureMap.AutoMocking.csproj 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.AutoMocking/StructureMap.AutoMocking.csproj 2008-05-28 15:50:14 UTC (rev 109) @@ -42,7 +42,7 @@ <Compile Include="..\CommonAssemblyInfo.cs"> <Link>CommonAssemblyInfo.cs</Link> </Compile> - <Compile Include="AutoMockedInstanceManager.cs" /> + <Compile Include="AutoMockedContainer.cs" /> <Compile Include="IntegrationSpecification.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="RhinoAutoMocker.cs" /> Modified: trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -16,14 +16,14 @@ { _mocks = new MockRepository(); _locator = new RhinoMocksServiceLocator(_mocks); - _instanceManager = new AutoMockedInstanceManager(_locator); + _container = new AutoMockedContainer(_locator); } #endregion private MockRepository _mocks; private RhinoMocksServiceLocator _locator; - private AutoMockedInstanceManager _instanceManager; + private AutoMockedContainer _container; public class ConcreteThing @@ -132,11 +132,11 @@ [Test] public void AutoFillAConcreteClassWithMocks() { - IMockedService service = _instanceManager.GetInstance<IMockedService>(); - IMockedService2 service2 = _instanceManager.GetInstance<IMockedService2>(); - IMockedService3 service3 = _instanceManager.GetInstance<IMockedService3>(); + IMockedService service = _container.GetInstance<IMockedService>(); + IMockedService2 service2 = _container.GetInstance<IMockedService2>(); + IMockedService3 service3 = _container.GetInstance<IMockedService3>(); - ConcreteClass concreteClass = _instanceManager.FillDependencies<ConcreteClass>(); + ConcreteClass concreteClass = _container.FillDependencies<ConcreteClass>(); Assert.AreSame(service, concreteClass.Service); Assert.AreSame(service2, concreteClass.Service2); @@ -146,7 +146,7 @@ [Test] public void GetAFullMockForAServiceThatHasNotPreviouslyBeenRequested() { - IMockedService service = _instanceManager.GetInstance<IMockedService>(); + IMockedService service = _container.GetInstance<IMockedService>(); Assert.IsNotNull(service); @@ -169,21 +169,21 @@ public void InjectAStubAndGetTheStubBack() { StubService stub = new StubService(); - _instanceManager.InjectStub<IMockedService>(stub); + _container.InjectStub<IMockedService>(stub); - Assert.AreSame(stub, _instanceManager.GetInstance<IMockedService>()); - Assert.AreSame(stub, _instanceManager.GetInstance<IMockedService>()); - Assert.AreSame(stub, _instanceManager.GetInstance<IMockedService>()); + Assert.AreSame(stub, _container.GetInstance<IMockedService>()); + Assert.AreSame(stub, _container.GetInstance<IMockedService>()); + Assert.AreSame(stub, _container.GetInstance<IMockedService>()); } [Test] public void RequestTheServiceTwiceAndGetTheExactSameMockObject() { - IMockedService service = _instanceManager.GetInstance<IMockedService>(); - Assert.AreSame(service, _instanceManager.GetInstance<IMockedService>()); - Assert.AreSame(service, _instanceManager.GetInstance<IMockedService>()); - Assert.AreSame(service, _instanceManager.GetInstance<IMockedService>()); - Assert.AreSame(service, _instanceManager.GetInstance<IMockedService>()); + IMockedService service = _container.GetInstance<IMockedService>(); + Assert.AreSame(service, _container.GetInstance<IMockedService>()); + Assert.AreSame(service, _container.GetInstance<IMockedService>()); + Assert.AreSame(service, _container.GetInstance<IMockedService>()); + Assert.AreSame(service, _container.GetInstance<IMockedService>()); } [Test] Modified: trunk/Source/StructureMap.Testing/Container/EmittingTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/EmittingTester.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.Testing/Container/EmittingTester.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -73,12 +73,6 @@ } [Test] - public void ConcreteTypeKey() - { - Assert.AreEqual("Complex", builder.ConcreteTypeKey); - } - - [Test] public void DoubleProperty() { Assert.AreEqual(4, rule.Double); Modified: trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -61,9 +61,38 @@ Assert.IsNotNull(gateway); } + [Test] + public void Import_from_family_picks_up_new_InstanceBuilders() + { + InstanceFactory factory = new InstanceFactory(typeof(IWidget)); + + PluginFamily family = new PluginFamily(typeof(IWidget)); + family.AddPlugin(typeof (AWidget)); + family.AddPlugin(typeof (ColorWidget)); + factory.Merge(family); + InstanceBuilder builder = factory.FindBuilderByType(typeof (AWidget)); + Assert.IsNotNull(builder); + builder = factory.FindBuilderByType(typeof(ColorWidget)); + Assert.IsNotNull(builder); + } + [Test] + public void Import_from_family_picks_up_new_instances() + { + InstanceFactory factory = new InstanceFactory(typeof(IWidget)); + PluginFamily family = new PluginFamily(typeof(IWidget)); + family.AddInstance(new LiteralInstance(new AWidget()).WithName("New")); + family.AddInstance(new LiteralInstance(new AWidget()).WithName("New2")); + family.AddInstance(new LiteralInstance(new AWidget()).WithName("New3")); + + factory.Merge(family); + + Assert.IsNotNull(factory.FindInstance("New")); + Assert.IsNotNull(factory.FindInstance("New2")); + Assert.IsNotNull(factory.FindInstance("New3")); + } } } \ No newline at end of file Added: trunk/Source/StructureMap.Testing/InstanceBuilderListTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/InstanceBuilderListTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/InstanceBuilderListTester.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Text; +using NUnit.Framework; +using StructureMap.Graph; +using StructureMap.Testing.Widget; + +namespace StructureMap.Testing +{ + [TestFixture] + public class InstanceBuilderListTester + { + [Test] + public void InstanceBuilderList_add_a_new_InstanceBuilder_if_the_new_Plugin_is_not_recognized() + { + InstanceBuilderList list = new InstanceBuilderList(typeof(IWidget)); + Assert.AreEqual(0, list.BuilderCount); + + Plugin plugin = new Plugin(typeof(AWidget)); + list.Add(plugin); + + Assert.AreEqual(1, list.BuilderCount); + InstanceBuilder builder = list.FindByType(typeof(AWidget)); + + Assert.IsNotNull(builder); + } + + [Test] + public void InstanceBuilderList_should_not_add_a_new_InstanceBuilder_if_the_same_one_exists() + { + InstanceBuilderList list = new InstanceBuilderList(typeof(IWidget)); + Plugin plugin = new Plugin(typeof(AWidget)); + list.Add(plugin); + list.Add(plugin); + + Assert.AreEqual(1, list.BuilderCount); + } + + [Test] + public void Do_not_add_a_new_InstanceBuilder_for_the_same_plugged_type_but_different_concrete_key() + { + InstanceBuilderList list = new InstanceBuilderList(typeof(IWidget)); + Plugin plugin = new Plugin(typeof(AWidget)); + list.Add(plugin); + + Plugin plugin2 = new Plugin(typeof(AWidget), "DifferentKey"); + list.Add(plugin2); + + Assert.AreEqual(1, list.BuilderCount); + } + + [Test] + public void Find_the_InstanceBuilder_by_concrete_key_with_different_aliased_concrete_keys() + { + InstanceBuilderList list = new InstanceBuilderList(typeof(IWidget)); + Plugin plugin = new Plugin(typeof(AWidget)); + list.Add(plugin); + + Plugin plugin2 = new Plugin(typeof(AWidget), "DifferentKey"); + list.Add(plugin2); + + InstanceBuilder builder1 = list.FindByConcreteKey(plugin.ConcreteKey); + InstanceBuilder builder2 = list.FindByConcreteKey(plugin2.ConcreteKey); + + Assert.AreSame(builder1, builder2); + } + } +} Added: trunk/Source/StructureMap.Testing/MergingTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/MergingTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/MergingTester.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; +using NUnit.Framework; +using StructureMap.Graph; +using StructureMap.Testing.Widget; + +namespace StructureMap.Testing +{ + [TestFixture] + public class MergingTester + { + + + + } +} Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-28 15:50:14 UTC (rev 109) @@ -315,8 +315,10 @@ </Compile> <Compile Include="Graph\TypePathTester.cs" /> <Compile Include="ImplicitPluginFromPluggedTypeAttributeTester.cs" /> + <Compile Include="InstanceBuilderListTester.cs" /> <Compile Include="InstanceMementoInstanceCreationTester.cs" /> <Compile Include="MementoTester.cs" /> + <Compile Include="MergingTester.cs" /> <Compile Include="ObjectFactoryTester.cs"> <SubType>Code</SubType> </Compile> Modified: trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -51,14 +51,6 @@ public class StringListBuilder : InstanceBuilder { - - public override string ConcreteTypeKey - { - get { return null; } - } - - - public override object BuildInstance(IConfiguredInstance instance, StructureMap.Pipeline.IBuildSession session) { return null; Modified: trunk/Source/StructureMap.Testing.Widget/Decision.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/Decision.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.Testing.Widget/Decision.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -16,11 +16,6 @@ public class DecisionBuilder : InstanceBuilder { - public override string ConcreteTypeKey - { - get { return null; } - } - public override object BuildInstance(IConfiguredInstance instance, StructureMap.Pipeline.IBuildSession session) { return new Decision( Modified: trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -92,11 +92,6 @@ public class ChildLoaderTemplate : InstanceBuilder { - public override string ConcreteTypeKey - { - get { return null; } - } - public override Type PluggedType { get { throw new NotImplementedException(); } Modified: trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -28,11 +28,6 @@ public class CowBuilder : InstanceBuilder { - public override string ConcreteTypeKey - { - get { return "Default"; } - } - public Type ThePluginType { get Modified: trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -13,12 +13,6 @@ { } - - public override string ConcreteTypeKey - { - get { throw new NotImplementedException(); } - } - public override Type PluggedType { get { throw new NotImplementedException(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-05-28 04:02:57
|
Revision: 108 http://structuremap.svn.sourceforge.net/structuremap/?rev=108&view=rev Author: jeremydmiller Date: 2008-05-27 21:02:54 -0700 (Tue, 27 May 2008) Log Message: ----------- renaming InstanceManager to Container Modified Paths: -------------- trunk/Source/StructureMap/Configuration/GraphBuilder.cs trunk/Source/StructureMap/IContainer.cs trunk/Source/StructureMap/InstanceBuilder.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/PluginGraphBuilder.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs trunk/Source/StructureMap.Testing/BuildSessionTester.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs trunk/Source/StructureMap.Testing/Container/ExceptionHandling/StructureMapExceptionTester.cs trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs trunk/Source/StructureMap.Testing/Container/FillDependenciesTester.cs trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs trunk/Source/StructureMap.Testing/Container/IntegratedTester.cs trunk/Source/StructureMap.Testing/Container/Interceptors/TypeInterceptionTester.cs trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs trunk/Source/StructureMap.Testing/Container/TypeFindingTester.cs trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs trunk/Source/StructureMap.Testing/Graph/PluginTester.cs trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs trunk/Source/StructureMap.Testing/ObjectMother.cs Added Paths: ----------- trunk/Source/StructureMap/Container.cs Modified: trunk/Source/StructureMap/Configuration/GraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -11,7 +11,7 @@ private readonly PluginGraph _pluginGraph; private readonly PluginGraph _systemGraph; private Profile _profile; - private InstanceManager _systemInstanceManager; + private Container _systemContainer; public GraphBuilder(Registry[] registries) : this(registries, new PluginGraph()) @@ -110,12 +110,12 @@ { Instance instance = memento.ReadInstance(_systemGraph, type); - if (_systemInstanceManager == null) + if (_systemContainer == null) { - _systemInstanceManager = new InstanceManager(_systemGraph); + _systemContainer = new Container(_systemGraph); } - return _systemInstanceManager.GetInstance(type, instance); + return _systemContainer.GetInstance(type, instance); } } } \ No newline at end of file Added: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs (rev 0) +++ trunk/Source/StructureMap/Container.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -0,0 +1,291 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Text; +using StructureMap.Configuration.DSL; +using StructureMap.Diagnostics; +using StructureMap.Graph; +using StructureMap.Interceptors; +using StructureMap.Pipeline; + +namespace StructureMap +{ + /// <summary> + /// A collection of IInstanceFactory's. + /// </summary> + public class Container : TypeRules, IContainer + { + private InterceptorLibrary _interceptorLibrary; + private PipelineGraph _pipelineGraph; + + public Container(Action<Registry> action) + { + Registry registry = new Registry(); + action(registry); + + construct(registry.Build()); + } + + public Container(Registry registry) : this(registry.Build()) + { + } + + public Container() : this(new PluginGraph()) + { + } + + /// <summary> + /// Constructor to create an Container + /// </summary> + /// <param name="pluginGraph">PluginGraph containing the instance and type definitions + /// for the Container</param> + /// <param name="failOnException">Flags the Container to fail or trap exceptions</param> + public Container(PluginGraph pluginGraph) + { + construct(pluginGraph); + } + + private void construct(PluginGraph pluginGraph) + { + _interceptorLibrary = pluginGraph.InterceptorLibrary; + + if (!pluginGraph.IsSealed) + { + pluginGraph.Seal(); + } + + pluginGraph.Log.AssertFailures(); + + _pipelineGraph = new PipelineGraph(pluginGraph); + } + + protected MissingFactoryFunction onMissingFactory + { + set { _pipelineGraph.OnMissingFactory = value; } + } + + #region IContainer Members + + public T GetInstance<T>(string instanceKey) + { + return (T) GetInstance(typeof (T), instanceKey); + } + + public T GetInstance<T>(Instance instance) + { + return (T) GetInstance(typeof (T), instance); + } + + public PLUGINTYPE GetInstance<PLUGINTYPE>(ExplicitArguments args) + { + Instance defaultInstance = _pipelineGraph.GetDefault(typeof (PLUGINTYPE)); + + ExplicitInstance<PLUGINTYPE> instance = new ExplicitInstance<PLUGINTYPE>(args, defaultInstance); + return GetInstance<PLUGINTYPE>(instance); + } + + public void Inject<PLUGINTYPE>(PLUGINTYPE instance) + { + _pipelineGraph.Inject(instance); + } + + public void InjectByName<PLUGINTYPE>(PLUGINTYPE instance, string instanceKey) + { + LiteralInstance literalInstance = new LiteralInstance(instance); + literalInstance.Name = instanceKey; + + AddInstance<PLUGINTYPE>(literalInstance); + } + + public void InjectByName<PLUGINTYPE, CONCRETETYPE>(string instanceKey) + { + ConfiguredInstance instance = new ConfiguredInstance(typeof(CONCRETETYPE)); + instance.Name = instanceKey; + + AddInstance<PLUGINTYPE>(instance); + } + + public T GetInstance<T>() + { + return (T) GetInstance(typeof (T)); + } + + public T FillDependencies<T>() + { + return (T) FillDependencies(typeof (T)); + } + + public void InjectStub<T>(T instance) + { + InjectStub(typeof (T), instance); + } + + public IList<T> GetAllInstances<T>() + { + List<T> list = new List<T>(); + + IBuildSession session = withNewSession(); + + foreach (T instance in forType(typeof (T)).GetAllInstances(session)) + { + list.Add(instance); + } + + return list; + } + + public void SetDefaultsToProfile(string profile) + { + _pipelineGraph.CurrentProfile = profile; + } + + /// <summary> + /// Creates the named instance of the PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instanceKey"></param> + /// <returns></returns> + public object GetInstance(Type pluginType, string instanceKey) + { + return withNewSession().CreateInstance(pluginType, instanceKey); + } + + + /// <summary> + /// Creates a new object instance of the requested type + /// </summary> + /// <param name="pluginType"></param> + /// <returns></returns> + public object GetInstance(Type pluginType) + { + return withNewSession().CreateInstance(pluginType); + } + + + /// <summary> + /// Creates a new instance of the requested type using the InstanceMemento. Mostly used from other + /// classes to link children members + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instance"></param> + /// <returns></returns> + public object GetInstance(Type pluginType, Instance instance) + { + return withNewSession().CreateInstance(pluginType, instance); + } + + /// <summary> + /// Sets the default instance for the PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instance"></param> + public void SetDefault(Type pluginType, Instance instance) + { + _pipelineGraph.SetDefault(pluginType, instance); + } + + /// <summary> + /// Sets the default instance for the PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instanceKey"></param> + public void SetDefault(Type pluginType, string instanceKey) + { + ReferencedInstance reference = new ReferencedInstance(instanceKey); + _pipelineGraph.SetDefault(pluginType, reference); + } + + + /// <summary> + /// Attempts to create a new instance of the requested type. Automatically inserts the default + /// configured instance for each dependency in the StructureMap constructor function. + /// </summary> + /// <param name="type"></param> + /// <returns></returns> + public object FillDependencies(Type type) + { + if (!IsConcrete(type)) + { + throw new StructureMapException(230, type.FullName); + } + + Plugin plugin = new Plugin(type); + if (!plugin.CanBeAutoFilled) + { + throw new StructureMapException(230, type.FullName); + } + + return GetInstance(type); + } + + /// <summary> + /// Sets up the Container to return the object in the "stub" argument anytime + /// any instance of the PluginType is requested + /// </summary> + /// <param name="pluginType"></param> + /// <param name="stub"></param> + public void InjectStub(Type pluginType, object stub) + { + if (!CanBeCast(pluginType, stub.GetType())) + { + throw new StructureMapException(220, pluginType.FullName, + stub.GetType().FullName); + } + + + LiteralInstance instance = new LiteralInstance(stub); + _pipelineGraph.SetDefault(pluginType, instance); + } + + public IList GetAllInstances(Type type) + { + return forType(type).GetAllInstances(withNewSession()); + } + + public void AddInstance<T>(Instance instance) + { + _pipelineGraph.AddInstance<T>(instance); + } + + public void AddInstance<PLUGINTYPE, CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE + { + _pipelineGraph.AddInstance<PLUGINTYPE, CONCRETETYPE>(); + } + + public void AddDefaultInstance<PLUGINTYPE, CONCRETETYPE>() + { + _pipelineGraph.AddDefaultInstance<PLUGINTYPE, CONCRETETYPE>(); + } + + public string WhatDoIHave() + { + WhatDoIHaveWriter writer = new WhatDoIHaveWriter(_pipelineGraph); + return writer.GetText(); + } + + public ExplicitArgsExpression With<T>(T arg) + { + return new ExplicitArgsExpression(this).With<T>(arg); + } + + public IExplicitProperty With(string argName) + { + return new ExplicitArgsExpression(this).With(argName); + } + + #endregion + + private IBuildSession withNewSession() + { + return new BuildSession(_pipelineGraph, _interceptorLibrary); + } + + + protected IInstanceFactory forType(Type type) + { + return _pipelineGraph.ForType(type); + } + + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/IContainer.cs =================================================================== --- trunk/Source/StructureMap/IContainer.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap/IContainer.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -18,7 +18,7 @@ T GetInstance<T>(Instance instance); /// <summary> - /// Sets up the InstanceManager to return the object in the "stub" argument anytime + /// Sets up the Container to return the object in the "stub" argument anytime /// any instance of the PluginType is requested /// </summary> /// <param name="pluginType"></param> Modified: trunk/Source/StructureMap/InstanceBuilder.cs =================================================================== --- trunk/Source/StructureMap/InstanceBuilder.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap/InstanceBuilder.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -9,7 +9,7 @@ /// </summary> public abstract class InstanceBuilder { - private InstanceManager _manager; + private Container _manager; public InstanceBuilder() { Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -129,7 +129,7 @@ manager.AddInstance<PLUGINTYPE, CONCRETETYPE>(); } - #region InstanceManager and setting defaults + #region Container and setting defaults private static IContainer manager { @@ -226,14 +226,14 @@ } - private static InstanceManager buildManager() + private static Container buildManager() { PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); - InstanceManager instanceManager = new InstanceManager(graph); - instanceManager.SetDefaultsToProfile(_profile); + Container container = new Container(graph); + container.SetDefaultsToProfile(_profile); - return instanceManager; + return container; } #endregion Modified: trunk/Source/StructureMap/PluginGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/PluginGraphBuilder.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap/PluginGraphBuilder.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -9,7 +9,7 @@ { /// <summary> /// Reads configuration XML documents and builds the structures necessary to initialize - /// the InstanceManager/IInstanceFactory/InstanceBuilder/ObjectInstanceActivator objects + /// the Container/IInstanceFactory/InstanceBuilder/ObjectInstanceActivator objects /// </summary> public class PluginGraphBuilder { Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-05-28 04:02:54 UTC (rev 108) @@ -292,7 +292,7 @@ <Compile Include="InstanceFactory.cs"> <SubType>Code</SubType> </Compile> - <Compile Include="InstanceManager.cs"> + <Compile Include="Container.cs"> <SubType>Code</SubType> </Compile> <Compile Include="InstanceMemento.cs"> Modified: trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -4,7 +4,7 @@ namespace StructureMap.AutoMocking { - public class AutoMockedInstanceManager : InstanceManager + public class AutoMockedInstanceManager : Container { private readonly ServiceLocator _locator; Modified: trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -22,8 +22,8 @@ _manager = new AutoMockedInstanceManager(locator); } - // Replaces the inner InstanceManager in ObjectFactory with the mocked - // InstanceManager from the auto mocking container. This will make ObjectFactory + // Replaces the inner Container in ObjectFactory with the mocked + // Container from the auto mocking container. This will make ObjectFactory // return mocks for everything. Use cautiously!!!!!!!!!!!!!!! // Gets the ClassUnderTest with mock objects (or stubs) pushed in Modified: trunk/Source/StructureMap.Testing/BuildSessionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -138,7 +138,7 @@ [Test] public void If_no_child_array_is_explicitly_defined_return_all_instances() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.AddInstanceOf<IWidget>(new ColorWidget("Red")); registry.AddInstanceOf<IWidget>(new ColorWidget("Blue")); Modified: trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -60,7 +60,7 @@ PluginGraphBuilder builder = new PluginGraphBuilder(parser); PluginGraph graph = builder.Build(); - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); GrandChild tommy = (GrandChild) manager.GetInstance(typeof (GrandChild), "Tommy"); Assert.AreEqual(false, tommy.RightHanded); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -16,7 +16,7 @@ public void SetUp() { - manager = new InstanceManager(delegate(Registry registry) + manager = new StructureMap.Container(delegate(Registry registry) { registry.ScanAssemblies().IncludeAssemblyContainingType<ColorWidget>(); @@ -65,7 +65,7 @@ [Test] public void AddInstanceAndOverrideTheConcreteTypeForADependency() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { // Specify a new Instance that specifies the concrete type used for a dependency registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName("AWidgetRule") @@ -87,7 +87,7 @@ [Test] public void SimpleCaseWithNamedInstance() { - manager = new InstanceManager(delegate(Registry registry) + manager = new StructureMap.Container(delegate(Registry registry) { // Specify a new Instance and override the Name registry.AddInstanceOf<IWidget>().UsingConcreteType<AWidget>().WithName("MyInstance"); @@ -100,7 +100,7 @@ [Test] public void SpecifyANewInstanceOverrideADependencyWithANamedInstance() { - manager = new InstanceManager(delegate(Registry registry) + manager = new StructureMap.Container(delegate(Registry registry) { registry.AddInstanceOf<Rule>().UsingConcreteType<ARule>().WithName("Alias"); @@ -128,7 +128,7 @@ // Specify a new Instance, create an instance for a dependency on the fly string instanceKey = "OrangeWidgetRule"; - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName(instanceKey) .Child<IWidget>().Is( @@ -152,7 +152,7 @@ CloneableWidget theWidget = new CloneableWidget("Jeremy"); - manager = new InstanceManager(delegate(Registry registry) + manager = new StructureMap.Container(delegate(Registry registry) { registry.AddPrototypeInstanceOf<IWidget>(theWidget).WithName("Jeremy"); }); @@ -177,7 +177,7 @@ // Return the specific instance when an IWidget named "Julia" is requested CloneableWidget julia = new CloneableWidget("Julia"); - manager = new InstanceManager(delegate(Registry registry) + manager = new StructureMap.Container(delegate(Registry registry) { registry.AddInstanceOf<IWidget>(julia).WithName("Julia"); }); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -30,7 +30,7 @@ [Test] public void A_concrete_type_is_available_by_name_when_it_is_added_by_the_shorthand_mechanism() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<IAddTypes>() .AddConcreteType<RedAddTypes>("Red") @@ -47,7 +47,7 @@ [Test] public void A_concrete_type_is_available_when_it_is_added_by_the_shorthand_mechanism() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<IAddTypes>() .AddConcreteType<RedAddTypes>() @@ -64,7 +64,7 @@ [Test] public void Make_sure_that_we_dont_double_dip_instances_when_we_register_a_type_with_a_name() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<IAddTypes>() .AddConcreteType<RedAddTypes>("Red") Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -31,7 +31,7 @@ Concretion concretion1 = new Concretion(); Concretion concretion2 = new Concretion(); - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<Abstraction>() .AddInstances( @@ -49,7 +49,7 @@ { Concretion concretion = new Concretion(); - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<Abstraction>().TheDefaultIs( ConstructedBy<Abstraction>(delegate { return concretion; }) @@ -65,7 +65,7 @@ Concretion concretion1 = new Concretion(); Concretion concretion2 = new Concretion(); - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<Abstraction>().AddInstance( ConstructedBy<Abstraction>(delegate { return concretion1; }).WithName("One") @@ -85,7 +85,7 @@ { Concretion concretion = new Concretion(); - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<Abstraction>().AddInstance( ConstructedBy<Abstraction>(delegate { return concretion; }) Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -38,8 +38,8 @@ [Test] public void Add_an_instance_by_lambda() { - InstanceManager manager = - new InstanceManager( + StructureMap.Container manager = + new StructureMap.Container( delegate(Registry registry) { registry.ForRequestedType<IWidget>().AddInstance(delegate { return new AWidget(); }); }); Assert.IsInstanceOfType(typeof (AWidget), manager.GetAllInstances<IWidget>()[0]); @@ -50,8 +50,8 @@ { AWidget aWidget = new AWidget(); - InstanceManager manager = - new InstanceManager( + StructureMap.Container manager = + new StructureMap.Container( delegate(Registry registry) { registry.ForRequestedType<IWidget>().AddInstance(aWidget); }); Assert.IsInstanceOfType(typeof (AWidget), manager.GetAllInstances<IWidget>()[0]); @@ -60,7 +60,7 @@ [Test] public void AddInstanceByNameOnlyAddsOneInstanceToStructureMap() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<Something>().AddInstance( RegistryExpressions.Instance<Something>().UsingConcreteType<RedSomething>().WithName("Red") @@ -73,7 +73,7 @@ [Test] public void AddInstanceWithNameOnlyAddsOneInstanceToStructureMap() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.AddInstanceOf<Something>().UsingConcreteType<RedSomething>().WithName("Red"); }); @@ -143,7 +143,7 @@ PluginGraph pluginGraph = registry.Build(); Assert.IsTrue(pluginGraph.ContainsFamily(typeof (IGateway))); - InstanceManager manager = new InstanceManager(pluginGraph); + StructureMap.Container manager = new StructureMap.Container(pluginGraph); IGateway gateway = (IGateway) manager.GetInstance(typeof (IGateway)); Assert.IsInstanceOfType(typeof (StubbedGateway), gateway); @@ -158,7 +158,7 @@ Assert.IsTrue(pluginGraph.ContainsFamily(typeof (IGateway))); - InstanceManager manager = new InstanceManager(pluginGraph); + StructureMap.Container manager = new StructureMap.Container(pluginGraph); IGateway gateway = (IGateway) manager.GetInstance(typeof (IGateway)); Assert.IsInstanceOfType(typeof (FakeGateway), gateway); @@ -167,7 +167,7 @@ [Test] public void CreatePluginFamilyWithADefault() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.BuildInstancesOf<IWidget>().TheDefaultIs( RegistryExpressions.Instance<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo( @@ -195,8 +195,8 @@ [Test] public void Set_the_default_by_a_lambda() { - InstanceManager manager = - new InstanceManager( + StructureMap.Container manager = + new StructureMap.Container( delegate(Registry registry) { registry.ForRequestedType<IWidget>().TheDefaultIs(delegate { return new AWidget(); }); }); Assert.IsInstanceOfType(typeof (AWidget), manager.GetInstance<IWidget>()); @@ -207,8 +207,8 @@ { AWidget aWidget = new AWidget(); - InstanceManager manager = - new InstanceManager( + StructureMap.Container manager = + new StructureMap.Container( delegate(Registry registry) { registry.ForRequestedType<IWidget>().TheDefaultIs(aWidget); }); Assert.AreSame(aWidget, manager.GetInstance<IWidget>()); @@ -217,7 +217,7 @@ [Test] public void TheDefaultInstanceIsConcreteType() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { // Needs to blow up if the concrete type can't be used registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<ARule>(); @@ -237,7 +237,7 @@ Assert.IsTrue(pluginGraph.ContainsFamily(typeof (IGateway))); - InstanceManager manager = new InstanceManager(pluginGraph); + StructureMap.Container manager = new StructureMap.Container(pluginGraph); IGateway gateway = (IGateway) manager.GetInstance(typeof (IGateway)); Assert.IsInstanceOfType(typeof (DefaultGateway), gateway); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -12,7 +12,7 @@ private void assertThingMatches(Action<Registry> action) { - IContainer manager = new InstanceManager(action); + IContainer manager = new StructureMap.Container(action); Thing actual = manager.GetInstance<Thing>(); Assert.AreEqual(_prototype, actual); } Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -45,7 +45,7 @@ [Test] public void Add_concrete_type() { - InstanceManager manager = new InstanceManager(delegate(Registry r) + StructureMap.Container manager = new StructureMap.Container(delegate(Registry r) { r.ForRequestedType(typeof(ITarget)).AddConcreteType(typeof(Target1)); }); @@ -57,7 +57,7 @@ [Test] public void Add_concrete_type_with_name() { - InstanceManager manager = new InstanceManager(delegate(Registry r) + StructureMap.Container manager = new StructureMap.Container(delegate(Registry r) { r.ForRequestedType(typeof(ITarget)).AddConcreteType(typeof(Target1), "1"); r.ForRequestedType(typeof(ITarget)).AddConcreteType(typeof(Target2), "2"); @@ -73,7 +73,7 @@ [Test] public void Add_default_by_concrete_type() { - InstanceManager manager = new InstanceManager(delegate(Registry r) + StructureMap.Container manager = new StructureMap.Container(delegate(Registry r) { r.ForRequestedType(typeof (ITarget)).TheDefaultIsConcreteType(typeof (Target3)); }); @@ -84,7 +84,7 @@ [Test] public void Add_default_instance() { - InstanceManager manager = new InstanceManager(delegate(Registry r) + StructureMap.Container manager = new StructureMap.Container(delegate(Registry r) { r.ForRequestedType(typeof(ITarget)).TheDefaultIs(Instance<Target2>()); }); @@ -95,7 +95,7 @@ [Test] public void Add_instance_by_lambda() { - InstanceManager manager = new InstanceManager(delegate(Registry r) + StructureMap.Container manager = new StructureMap.Container(delegate(Registry r) { r.ForRequestedType(typeof(ITarget)).TheDefaultIs(delegate() { return new Target1(); }); }); @@ -106,7 +106,7 @@ [Test] public void Add_instance_directly() { - InstanceManager manager = new InstanceManager(delegate(Registry r) + StructureMap.Container manager = new StructureMap.Container(delegate(Registry r) { r.ForRequestedType(typeof (ITarget)).AddInstance(Instance<Target2>()); }); @@ -118,7 +118,7 @@ [Test] public void Enrichment() { - InstanceManager manager = new InstanceManager(delegate(Registry r) + StructureMap.Container manager = new StructureMap.Container(delegate(Registry r) { r.ForRequestedType(typeof(ITarget)) .TheDefaultIsConcreteType(typeof(Target1)) @@ -164,7 +164,7 @@ { ITarget created = null; - InstanceManager manager = new InstanceManager(delegate(Registry r) + StructureMap.Container manager = new StructureMap.Container(delegate(Registry r) { r.ForRequestedType(typeof (ITarget)) .TheDefaultIsConcreteType(typeof (Target3)) Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -82,7 +82,7 @@ [Test] public void CanStillAddOtherPropertiesAfterTheCallToChildArray() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<Processor>() .TheDefaultIs( @@ -103,7 +103,7 @@ [Test] public void InjectPropertiesByName() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<Processor2>() .TheDefaultIs( @@ -153,7 +153,7 @@ [Test] public void PlaceMemberInArrayByReference() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.AddInstanceOf<IHandler>().UsingConcreteType<Handler1>().WithName("One"); registry.AddInstanceOf<IHandler>().UsingConcreteType<Handler2>().WithName("Two"); @@ -178,7 +178,7 @@ [Test] public void ProgrammaticallyInjectArrayAllInline() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<Processor>() .TheDefaultIs( Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -38,7 +38,7 @@ { if (_manager == null) { - _manager = new InstanceManager(delegate(Registry registry) + _manager = new StructureMap.Container(delegate(Registry registry) { _defaultRegistry(registry); action(registry); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -15,7 +15,7 @@ { _lastService = null; - _manager = new InstanceManager(delegate(Registry registry) + _manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<IService>().AddInstances ( Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -56,7 +56,7 @@ Assert.AreEqual(Profile.InstanceKeyForProfile(theProfileName), defaultInstance.Name); - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); manager.SetDefaultsToProfile(theProfileName); AWidget widget = (AWidget)manager.GetInstance<IWidget>(); Assert.IsNotNull(widget); @@ -83,7 +83,7 @@ { string theProfileName = "something"; - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.CreateProfile(theProfileName) .For<IWidget>().UseConcreteType<AWidget>() @@ -101,7 +101,7 @@ { string theProfileName = "something"; - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.CreateProfile(theProfileName) .For<IWidget>().Use(delegate() { return new AWidget(); }) @@ -122,7 +122,7 @@ string theProfileName = "something"; IWidget theTemplate = new AWidget(); - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.CreateProfile(theProfileName) .For<IWidget>().UsePrototypeOf(theTemplate); Modified: trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -21,12 +21,12 @@ "; _graph = DataMother.BuildPluginGraphFromXml(xml); - _manager = new InstanceManager(_graph); + _manager = new StructureMap.Container(_graph); } #endregion - private InstanceManager _manager; + private StructureMap.Container _manager; private PluginGraph _graph; [Test] Modified: trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -85,7 +85,7 @@ public void GettingTheRightInstanceKeyWhenUsingAMAchineOverrideInCombinationWithProfile() { ProfileBuilder.OverrideMachineName("GREEN-BOX"); - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); ColorWidget widget = (ColorWidget) manager.GetInstance<IWidget>(); Assert.AreEqual("Green", widget.Color); @@ -95,7 +95,7 @@ public void GotTheInstanceForTheMachineOverride() { ProfileBuilder.OverrideMachineName("ORANGE-BOX"); - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); ColorWidget widget = (ColorWidget)manager.GetInstance<IWidget>(); Assert.AreEqual("Orange", widget.Color); @@ -104,7 +104,7 @@ [Test] public void HasADefaultInstanceKey() { - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); manager.SetDefaultsToProfile("Green"); @@ -115,7 +115,7 @@ [Test] public void HasTheOverrideForProfile() { - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); manager.SetDefaultsToProfile("Blue"); ColorRule rule = (ColorRule) manager.GetInstance<Rule>(); @@ -131,7 +131,7 @@ public void InlineMachine1() { ProfileBuilder.OverrideMachineName("ORANGE-BOX"); - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); ColorWidget widget = (ColorWidget)manager.GetInstance(typeof(IWidget)); Assert.AreEqual("Orange", widget.Color); @@ -141,7 +141,7 @@ public void InlineMachine2() { ProfileBuilder.OverrideMachineName("GREEN-BOX"); - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); ColorWidget widget = (ColorWidget)manager.GetInstance(typeof(IWidget)); Assert.AreEqual("Green", widget.Color); @@ -150,7 +150,7 @@ [Test] public void SetTheProfile() { - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); manager.SetDefaultsToProfile("Green"); ColorRule greenRule = (ColorRule)manager.GetInstance(typeof(Rule)); Modified: trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -17,12 +17,12 @@ public void SetUp() { _graph = DataMother.GetPluginGraph("ShortInstance.xml"); - _manager = new InstanceManager(_graph); + _manager = new StructureMap.Container(_graph); } #endregion - private InstanceManager _manager; + private StructureMap.Container _manager; private PluginGraph _graph; [Test] Modified: trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -39,7 +39,7 @@ PluginGraph graph = builder.Build(); - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); Decision d1 = (Decision) manager.GetInstance(typeof (Decision), "RedBlue"); Assert.IsNotNull(d1); Modified: trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -59,7 +59,7 @@ [Test] public void AddInstanceToInstanceManagerWhenTheInstanceFactoryDoesNotExist() { - InstanceManager manager = new InstanceManager(new PluginGraph()); + StructureMap.Container manager = new StructureMap.Container(new PluginGraph()); manager.AddInstance<IService>(new LiteralInstance(_red).WithName("Red")); manager.AddInstance<IService>(new LiteralInstance(_blue).WithName("Blue")); @@ -99,7 +99,7 @@ PluginFamily family = pluginGraph.FindFamily(typeof(ISomething)); family.AddPlugin(typeof (SomethingOne), "One"); - InstanceManager manager = new InstanceManager(pluginGraph); + StructureMap.Container manager = new StructureMap.Container(pluginGraph); ConfiguredInstance instance = new ConfiguredInstance().WithConcreteKey("One").WithName("One"); manager.AddInstance<ISomething>(instance); @@ -113,7 +113,7 @@ public void AddPluginForTypeWhenThePluginDoesNotAlreadyExistsDoesNothing() { PluginGraph pluginGraph = new PluginGraph(); - InstanceManager manager = new InstanceManager(pluginGraph); + StructureMap.Container manager = new StructureMap.Container(pluginGraph); manager.AddInstance<ISomething, SomethingOne>(); Modified: trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -23,7 +23,7 @@ PluginFamily family = graph.FindFamily(typeof (Cow)); family.AddPlugin(typeof (Cow), "Default"); - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); ConfiguredInstance instance = new ConfiguredInstance() .WithConcreteKey("Default").WithName("Angus") Modified: trunk/Source/StructureMap.Testing/Container/ExceptionHandling/StructureMapExceptionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/ExceptionHandling/StructureMapExceptionTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Container/ExceptionHandling/StructureMapExceptionTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -107,14 +107,14 @@ } - private void assertErrorIsThrown(int errorCode, string xml, Action<InstanceManager> action) + private void assertErrorIsThrown(int errorCode, string xml, Action<StructureMap.Container> action) { XmlDocument document = new XmlDocument(); document.LoadXml(xml.Replace("\"", "'")); ConfigurationParser parser = new ConfigurationParser(document.DocumentElement); PluginGraphBuilder builder = new PluginGraphBuilder(parser); - InstanceManager manager = new InstanceManager(builder.Build()); + StructureMap.Container manager = new StructureMap.Container(builder.Build()); try { @@ -154,7 +154,7 @@ <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''> </PluginFamily> </StructureMap> ", - delegate (InstanceManager manager) + delegate (StructureMap.Container manager) { manager.GetInstance<IWidget>("NotAnActualInstanceName"); } @@ -187,7 +187,7 @@ <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''></PluginFamily> </StructureMap> ", - delegate (InstanceManager manager) + delegate (StructureMap.Container manager) { manager.GetInstance<IWidget>(); } Modified: trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -123,7 +123,7 @@ [Test] public void PassAnArgumentIntoExplicitArgumentsForARequestedInterface() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<IProvider>().TheDefaultIsConcreteType<LumpProvider>(); }); @@ -158,7 +158,7 @@ [Test] public void PassExplicitArgsIntoInstanceManager() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<ExplicitTarget>().TheDefaultIs( Registry.Instance<ExplicitTarget>() @@ -211,7 +211,7 @@ [Test] public void Fill_in_argument_by_name() { - InstanceManager manager = new InstanceManager(); + StructureMap.Container manager = new StructureMap.Container(); manager.AddDefaultInstance<IView, View>(); Node theNode = new Node(); @@ -230,7 +230,7 @@ [Test] public void Pass_in_arguments_as_dictionary() { - InstanceManager manager = new InstanceManager(); + StructureMap.Container manager = new StructureMap.Container(); manager.AddDefaultInstance<IView, View>(); Node theNode = new Node(); Modified: trunk/Source/StructureMap.Testing/Container/FillDependenciesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/FillDependenciesTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Container/FillDependenciesTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -14,7 +14,7 @@ { PluginGraph pluginGraph = ObjectMother.GetPluginGraph(); - InstanceManager manager = new InstanceManager(pluginGraph); + StructureMap.Container manager = new StructureMap.Container(pluginGraph); // The dependencies must have a default setting first manager.SetDefault(typeof (IStrategy), "Red"); @@ -33,7 +33,7 @@ public void TryToFillDependenciesOnAbstractClassThrowsException() { PluginGraph pluginGraph = ObjectMother.GetPluginGraph(); - InstanceManager manager = new InstanceManager(pluginGraph); + StructureMap.Container manager = new StructureMap.Container(pluginGraph); manager.FillDependencies(typeof (AbstractClass)); } @@ -43,7 +43,7 @@ public void TryToFillDependenciesOnClassWithPrimitiveArgumentsThrowsException() { PluginGraph pluginGraph = ObjectMother.GetPluginGraph(); - InstanceManager manager = new InstanceManager(pluginGraph); + StructureMap.Container manager = new StructureMap.Container(pluginGraph); manager.FillDependencies(typeof (CannotBeFilledConcreteClass)); } Modified: trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -33,7 +33,7 @@ PluginGraph pluginGraph = DataMother.GetDiagnosticPluginGraph("SampleConfig.xml"); - InstanceManager manager = new InstanceManager(pluginGraph); + StructureMap.Container manager = new StructureMap.Container(pluginGraph); IList list = manager.GetAllInstances(typeof (IWidget)); Modified: trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -17,7 +17,7 @@ [SetUp] public void SetUp() { - _manager = new InstanceManager(delegate(Registry registry) + _manager = new StructureMap.Container(delegate(Registry registry) { registry.BuildInstancesOf<Rule>(); registry.ScanAssemblies() @@ -29,7 +29,7 @@ #endregion - private InstanceManager _manager; + private StructureMap.Container _manager; Modified: trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -20,7 +20,7 @@ [SetUp] public void SetUp() { - _manager = new InstanceManager(delegate(Registry registry) + _manager = new StructureMap.Container(delegate(Registry registry) { registry.ScanAssemblies().IncludeAssembly("StructureMap.Testing.Widget"); registry.BuildInstancesOf<Rule>(); @@ -73,14 +73,14 @@ [Test] public void CanBuildConcreteTypesThatAreNotPreviouslyRegistered() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { - // Create a new InstanceManager that has a default instance configured for only the - // IProvider interface. InstanceManager is the real "container" behind ObjectFactory + // Create a new Container that has a default instance configured for only the + // IProvider interface. Container is the real "container" behind ObjectFactory registry.ForRequestedType<IProvider>().TheDefaultIsConcreteType<Provider>(); }); - // Now, have that same InstanceManager create a ClassThatUsesProvider. StructureMap will + // Now, have that same Container create a ClassThatUsesProvider. StructureMap will // see that ClassThatUsesProvider is concrete, determine its constructor args, and build one // for you with the default IProvider. No other configuration necessary. ClassThatUsesProvider classThatUsesProvider = manager.GetInstance<ClassThatUsesProvider>(); @@ -90,7 +90,7 @@ [Test] public void CanBuildConcreteTypesThatAreNotPreviouslyRegisteredWithArgumentsProvided() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.... [truncated message content] |
From: <jer...@us...> - 2008-05-28 03:58:53
|
Revision: 107 http://structuremap.svn.sourceforge.net/structuremap/?rev=107&view=rev Author: jeremydmiller Date: 2008-05-27 20:58:49 -0700 (Tue, 27 May 2008) Log Message: ----------- Renaming CreateInstance to GetInstance in InstanceManager to be consistent with ObjectFactory, renaming IInstanceManager.cs to IContainer Modified Paths: -------------- trunk/Source/StructureMap/Configuration/GraphBuilder.cs trunk/Source/StructureMap/ExplicitArgsExpression.cs trunk/Source/StructureMap/InstanceManager.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs trunk/Source/StructureMap.Testing/BuildSessionTester.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs trunk/Source/StructureMap.Testing/Container/ExceptionHandling/StructureMapExceptionTester.cs trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs trunk/Source/StructureMap.Testing/Container/FillDependenciesTester.cs trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs trunk/Source/StructureMap.Testing/Container/IntegratedTester.cs trunk/Source/StructureMap.Testing/Container/Interceptors/TypeInterceptionTester.cs trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs trunk/Source/StructureMap.Testing/Container/TypeFindingTester.cs trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs trunk/Source/StructureMap.Testing/Graph/PluginTester.cs trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs Added Paths: ----------- trunk/Source/StructureMap/IContainer.cs Removed Paths: ------------- trunk/Source/StructureMap/IInstanceManager.cs Modified: trunk/Source/StructureMap/Configuration/GraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -115,7 +115,7 @@ _systemInstanceManager = new InstanceManager(_systemGraph); } - return _systemInstanceManager.CreateInstance(type, instance); + return _systemInstanceManager.GetInstance(type, instance); } } } \ No newline at end of file Modified: trunk/Source/StructureMap/ExplicitArgsExpression.cs =================================================================== --- trunk/Source/StructureMap/ExplicitArgsExpression.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap/ExplicitArgsExpression.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -10,10 +10,10 @@ public class ExplicitArgsExpression : IExplicitProperty { private readonly ExplicitArguments _args = new ExplicitArguments(); - private readonly IInstanceManager _manager; + private readonly IContainer _manager; private string _lastArgName; - internal ExplicitArgsExpression(IInstanceManager manager) + internal ExplicitArgsExpression(IContainer manager) { _manager = manager; } @@ -43,7 +43,7 @@ public T GetInstance<T>() { - return _manager.CreateInstance<T>(_args); + return _manager.GetInstance<T>(_args); } } } \ No newline at end of file Added: trunk/Source/StructureMap/IContainer.cs =================================================================== --- trunk/Source/StructureMap/IContainer.cs (rev 0) +++ trunk/Source/StructureMap/IContainer.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -0,0 +1,82 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using StructureMap.Pipeline; + +namespace StructureMap +{ + public interface IContainer + { + T GetInstance<T>(string instanceKey); + T GetInstance<T>(); + T FillDependencies<T>(); + object FillDependencies(Type type); + void InjectStub<T>(T instance); + IList<T> GetAllInstances<T>(); + void SetDefaultsToProfile(string profile); + + T GetInstance<T>(Instance instance); + + /// <summary> + /// Sets up the InstanceManager to return the object in the "stub" argument anytime + /// any instance of the PluginType is requested + /// </summary> + /// <param name="pluginType"></param> + /// <param name="stub"></param> + void InjectStub(Type pluginType, object stub); + + IList GetAllInstances(Type type); + void AddInstance<T>(Instance instance); + void AddInstance<PLUGINTYPE, CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE; + void AddDefaultInstance<PLUGINTYPE, CONCRETETYPE>(); + void Inject<PLUGINTYPE>(PLUGINTYPE instance); + void InjectByName<PLUGINTYPE>(PLUGINTYPE instance, string instanceKey); + void InjectByName<PLUGINTYPE, CONCRETETYPE>(string instanceKey); + + string WhatDoIHave(); + + /// <summary> + /// Sets the default instance for the PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instance"></param> + void SetDefault(Type pluginType, Instance instance); + + /// <summary> + /// Sets the default instance for the PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instanceKey"></param> + void SetDefault(Type pluginType, string instanceKey); + + /// <summary> + /// Creates a new object instance of the requested type + /// </summary> + /// <param name="pluginType"></param> + /// <returns></returns> + object GetInstance(Type pluginType); + + + /// <summary> + /// Creates a new instance of the requested type using the InstanceMemento. Mostly used from other + /// classes to link children members + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instance"></param> + /// <returns></returns> + object GetInstance(Type pluginType, Instance instance); + + /// <summary> + /// Creates the named instance of the PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instanceKey"></param> + /// <returns></returns> + object GetInstance(Type pluginType, string instanceKey); + + PLUGINTYPE GetInstance<PLUGINTYPE>(ExplicitArguments args); + + ExplicitArgsExpression With<T>(T arg); + IExplicitProperty With(string argName); + } +} \ No newline at end of file Deleted: trunk/Source/StructureMap/IInstanceManager.cs =================================================================== --- trunk/Source/StructureMap/IInstanceManager.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap/IInstanceManager.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -1,82 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using StructureMap.Pipeline; - -namespace StructureMap -{ - public interface IInstanceManager - { - T CreateInstance<T>(string instanceKey); - T CreateInstance<T>(); - T FillDependencies<T>(); - object FillDependencies(Type type); - void InjectStub<T>(T instance); - IList<T> GetAllInstances<T>(); - void SetDefaultsToProfile(string profile); - - T CreateInstance<T>(Instance instance); - - /// <summary> - /// Sets up the InstanceManager to return the object in the "stub" argument anytime - /// any instance of the PluginType is requested - /// </summary> - /// <param name="pluginType"></param> - /// <param name="stub"></param> - void InjectStub(Type pluginType, object stub); - - IList GetAllInstances(Type type); - void AddInstance<T>(Instance instance); - void AddInstance<PLUGINTYPE, CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE; - void AddDefaultInstance<PLUGINTYPE, CONCRETETYPE>(); - void Inject<PLUGINTYPE>(PLUGINTYPE instance); - void InjectByName<PLUGINTYPE>(PLUGINTYPE instance, string instanceKey); - void InjectByName<PLUGINTYPE, CONCRETETYPE>(string instanceKey); - - string WhatDoIHave(); - - /// <summary> - /// Sets the default instance for the PluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instance"></param> - void SetDefault(Type pluginType, Instance instance); - - /// <summary> - /// Sets the default instance for the PluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instanceKey"></param> - void SetDefault(Type pluginType, string instanceKey); - - /// <summary> - /// Creates a new object instance of the requested type - /// </summary> - /// <param name="pluginType"></param> - /// <returns></returns> - object CreateInstance(Type pluginType); - - - /// <summary> - /// Creates a new instance of the requested type using the InstanceMemento. Mostly used from other - /// classes to link children members - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instance"></param> - /// <returns></returns> - object CreateInstance(Type pluginType, Instance instance); - - /// <summary> - /// Creates the named instance of the PluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instanceKey"></param> - /// <returns></returns> - object CreateInstance(Type pluginType, string instanceKey); - - PLUGINTYPE CreateInstance<PLUGINTYPE>(ExplicitArguments args); - - ExplicitArgsExpression With<T>(T arg); - IExplicitProperty With(string argName); - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceManager.cs =================================================================== --- trunk/Source/StructureMap/InstanceManager.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap/InstanceManager.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -14,7 +14,7 @@ /// <summary> /// A collection of IInstanceFactory's. /// </summary> - public class InstanceManager : TypeRules, IInstanceManager + public class InstanceManager : TypeRules, IContainer { private InterceptorLibrary _interceptorLibrary; private PipelineGraph _pipelineGraph; @@ -65,24 +65,24 @@ set { _pipelineGraph.OnMissingFactory = value; } } - #region IInstanceManager Members + #region IContainer Members - public T CreateInstance<T>(string instanceKey) + public T GetInstance<T>(string instanceKey) { - return (T) CreateInstance(typeof (T), instanceKey); + return (T) GetInstance(typeof (T), instanceKey); } - public T CreateInstance<T>(Instance instance) + public T GetInstance<T>(Instance instance) { - return (T) CreateInstance(typeof (T), instance); + return (T) GetInstance(typeof (T), instance); } - public PLUGINTYPE CreateInstance<PLUGINTYPE>(ExplicitArguments args) + public PLUGINTYPE GetInstance<PLUGINTYPE>(ExplicitArguments args) { Instance defaultInstance = _pipelineGraph.GetDefault(typeof (PLUGINTYPE)); ExplicitInstance<PLUGINTYPE> instance = new ExplicitInstance<PLUGINTYPE>(args, defaultInstance); - return CreateInstance<PLUGINTYPE>(instance); + return GetInstance<PLUGINTYPE>(instance); } public void Inject<PLUGINTYPE>(PLUGINTYPE instance) @@ -106,9 +106,9 @@ AddInstance<PLUGINTYPE>(instance); } - public T CreateInstance<T>() + public T GetInstance<T>() { - return (T) CreateInstance(typeof (T)); + return (T) GetInstance(typeof (T)); } public T FillDependencies<T>() @@ -146,7 +146,7 @@ /// <param name="pluginType"></param> /// <param name="instanceKey"></param> /// <returns></returns> - public object CreateInstance(Type pluginType, string instanceKey) + public object GetInstance(Type pluginType, string instanceKey) { return withNewSession().CreateInstance(pluginType, instanceKey); } @@ -157,7 +157,7 @@ /// </summary> /// <param name="pluginType"></param> /// <returns></returns> - public object CreateInstance(Type pluginType) + public object GetInstance(Type pluginType) { return withNewSession().CreateInstance(pluginType); } @@ -170,7 +170,7 @@ /// <param name="pluginType"></param> /// <param name="instance"></param> /// <returns></returns> - public object CreateInstance(Type pluginType, Instance instance) + public object GetInstance(Type pluginType, Instance instance) { return withNewSession().CreateInstance(pluginType, instance); } @@ -216,7 +216,7 @@ throw new StructureMapException(230, type.FullName); } - return CreateInstance(type); + return GetInstance(type); } /// <summary> Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -16,7 +16,7 @@ public class ObjectFactory { private static readonly object _lockObject = new object(); - private static IInstanceManager _manager; + private static IContainer _manager; private static string _profile = string.Empty; private static event Notify _notify; @@ -131,7 +131,7 @@ #region InstanceManager and setting defaults - private static IInstanceManager manager + private static IContainer manager { get { @@ -184,7 +184,7 @@ /// Strictly used for testing scenarios /// </summary> /// <param name="manager"></param> - internal static void ReplaceManager(IInstanceManager manager) + internal static void ReplaceManager(IContainer manager) { _manager = manager; } @@ -246,7 +246,7 @@ /// <returns></returns> public static object GetInstance(Type TargetType) { - return manager.CreateInstance(TargetType); + return manager.GetInstance(TargetType); } /// <summary> @@ -256,7 +256,7 @@ /// <returns></returns> public static TargetType GetInstance<TargetType>() { - return (TargetType) manager.CreateInstance(typeof (TargetType)); + return (TargetType) manager.GetInstance(typeof (TargetType)); } /// <summary> @@ -267,7 +267,7 @@ /// <returns></returns> public static object GetInstance(Type TargetType, Instance instance) { - return manager.CreateInstance(TargetType, instance); + return manager.GetInstance(TargetType, instance); } /// <summary> @@ -278,7 +278,7 @@ /// <returns></returns> public static TargetType GetInstance<TargetType>(Instance instance) { - return (TargetType) manager.CreateInstance(typeof (TargetType), instance); + return (TargetType) manager.GetInstance(typeof (TargetType), instance); } /// <summary> @@ -289,7 +289,7 @@ /// <returns></returns> public static object GetNamedInstance(Type TargetType, string InstanceName) { - return manager.CreateInstance(TargetType, InstanceName); + return manager.GetInstance(TargetType, InstanceName); } /// <summary> @@ -300,7 +300,7 @@ /// <returns></returns> public static TargetType GetNamedInstance<TargetType>(string InstanceName) { - return (TargetType) manager.CreateInstance(typeof (TargetType), InstanceName); + return (TargetType) manager.GetInstance(typeof (TargetType), InstanceName); } /// <summary> Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-05-28 03:58:49 UTC (rev 107) @@ -285,7 +285,7 @@ <Compile Include="IInstanceFactory.cs"> <SubType>Code</SubType> </Compile> - <Compile Include="IInstanceManager.cs" /> + <Compile Include="IContainer.cs" /> <Compile Include="InstanceBuilder.cs"> <SubType>Code</SubType> </Compile> Modified: trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -60,7 +60,7 @@ foreach (ParameterInfo parameterInfo in ctor.GetParameters()) { Type dependencyType = parameterInfo.ParameterType; - object dependency = _manager.CreateInstance(dependencyType); + object dependency = _manager.GetInstance(dependencyType); list.Add(dependency); } @@ -71,7 +71,7 @@ // of the ClassUnderTest public T Get<T>() { - return _manager.CreateInstance<T>(); + return _manager.GetInstance<T>(); } // Set the auto mocking container to use a Stub for Type T Modified: trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -132,9 +132,9 @@ [Test] public void AutoFillAConcreteClassWithMocks() { - IMockedService service = _instanceManager.CreateInstance<IMockedService>(); - IMockedService2 service2 = _instanceManager.CreateInstance<IMockedService2>(); - IMockedService3 service3 = _instanceManager.CreateInstance<IMockedService3>(); + IMockedService service = _instanceManager.GetInstance<IMockedService>(); + IMockedService2 service2 = _instanceManager.GetInstance<IMockedService2>(); + IMockedService3 service3 = _instanceManager.GetInstance<IMockedService3>(); ConcreteClass concreteClass = _instanceManager.FillDependencies<ConcreteClass>(); @@ -146,7 +146,7 @@ [Test] public void GetAFullMockForAServiceThatHasNotPreviouslyBeenRequested() { - IMockedService service = _instanceManager.CreateInstance<IMockedService>(); + IMockedService service = _instanceManager.GetInstance<IMockedService>(); Assert.IsNotNull(service); @@ -171,19 +171,19 @@ StubService stub = new StubService(); _instanceManager.InjectStub<IMockedService>(stub); - Assert.AreSame(stub, _instanceManager.CreateInstance<IMockedService>()); - Assert.AreSame(stub, _instanceManager.CreateInstance<IMockedService>()); - Assert.AreSame(stub, _instanceManager.CreateInstance<IMockedService>()); + Assert.AreSame(stub, _instanceManager.GetInstance<IMockedService>()); + Assert.AreSame(stub, _instanceManager.GetInstance<IMockedService>()); + Assert.AreSame(stub, _instanceManager.GetInstance<IMockedService>()); } [Test] public void RequestTheServiceTwiceAndGetTheExactSameMockObject() { - IMockedService service = _instanceManager.CreateInstance<IMockedService>(); - Assert.AreSame(service, _instanceManager.CreateInstance<IMockedService>()); - Assert.AreSame(service, _instanceManager.CreateInstance<IMockedService>()); - Assert.AreSame(service, _instanceManager.CreateInstance<IMockedService>()); - Assert.AreSame(service, _instanceManager.CreateInstance<IMockedService>()); + IMockedService service = _instanceManager.GetInstance<IMockedService>(); + Assert.AreSame(service, _instanceManager.GetInstance<IMockedService>()); + Assert.AreSame(service, _instanceManager.GetInstance<IMockedService>()); + Assert.AreSame(service, _instanceManager.GetInstance<IMockedService>()); + Assert.AreSame(service, _instanceManager.GetInstance<IMockedService>()); } [Test] Modified: trunk/Source/StructureMap.Testing/BuildSessionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -138,14 +138,14 @@ [Test] public void If_no_child_array_is_explicitly_defined_return_all_instances() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.AddInstanceOf<IWidget>(new ColorWidget("Red")); registry.AddInstanceOf<IWidget>(new ColorWidget("Blue")); registry.AddInstanceOf<IWidget>(new ColorWidget("Green")); }); - WidgetHolder holder = manager.CreateInstance<WidgetHolder>(); + WidgetHolder holder = manager.GetInstance<WidgetHolder>(); Assert.AreEqual(3, holder.Widgets.Length); } Modified: trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -62,11 +62,11 @@ InstanceManager manager = new InstanceManager(graph); - GrandChild tommy = (GrandChild) manager.CreateInstance(typeof (GrandChild), "Tommy"); + GrandChild tommy = (GrandChild) manager.GetInstance(typeof (GrandChild), "Tommy"); Assert.AreEqual(false, tommy.RightHanded); Assert.AreEqual(1972, tommy.BirthYear); - ColorWidget blue = (ColorWidget) manager.CreateInstance(typeof (IWidget), "Blue"); + ColorWidget blue = (ColorWidget) manager.GetInstance(typeof (IWidget), "Blue"); Assert.AreEqual("Blue", blue.Color); } } Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -46,33 +46,33 @@ #endregion - private IInstanceManager manager; + private IContainer manager; [Test] public void AddAnInstanceWithANameAndAPropertySpecifyingConcreteKey() { - ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>("Purple"); + ColorWidget widget = (ColorWidget) manager.GetInstance<IWidget>("Purple"); Assert.AreEqual("Purple", widget.Color); } [Test] public void AddAnInstanceWithANameAndAPropertySpecifyingConcreteType() { - ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>("DarkGreen"); + ColorWidget widget = (ColorWidget) manager.GetInstance<IWidget>("DarkGreen"); Assert.AreEqual("DarkGreen", widget.Color); } [Test] public void AddInstanceAndOverrideTheConcreteTypeForADependency() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { // Specify a new Instance that specifies the concrete type used for a dependency registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName("AWidgetRule") .Child<IWidget>().IsConcreteType<AWidget>(); }); - WidgetRule rule = (WidgetRule) manager.CreateInstance<Rule>("AWidgetRule"); + WidgetRule rule = (WidgetRule) manager.GetInstance<Rule>("AWidgetRule"); Assert.IsInstanceOfType(typeof (AWidget), rule.Widget); } @@ -80,7 +80,7 @@ public void CreateAnInstancePullAPropertyFromTheApplicationConfig() { Assert.AreEqual("Blue", ConfigurationManager.AppSettings["Color"]); - ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>("AppSetting"); + ColorWidget widget = (ColorWidget) manager.GetInstance<IWidget>("AppSetting"); Assert.AreEqual("Blue", widget.Color); } @@ -93,7 +93,7 @@ registry.AddInstanceOf<IWidget>().UsingConcreteType<AWidget>().WithName("MyInstance"); }); - AWidget widget = (AWidget) manager.CreateInstance<IWidget>("MyInstance"); + AWidget widget = (AWidget) manager.GetInstance<IWidget>("MyInstance"); Assert.IsNotNull(widget); } @@ -115,9 +115,9 @@ .Child<IWidget>("widget").IsNamedInstance("Purple"); }); - Assert.IsInstanceOfType(typeof (ARule), manager.CreateInstance<Rule>("Alias")); + Assert.IsInstanceOfType(typeof (ARule), manager.GetInstance<Rule>("Alias")); - WidgetRule rule = (WidgetRule) manager.CreateInstance<Rule>("RuleThatUsesMyInstance"); + WidgetRule rule = (WidgetRule) manager.GetInstance<Rule>("RuleThatUsesMyInstance"); ColorWidget widget = (ColorWidget) rule.Widget; Assert.AreEqual("Purple", widget.Color); } @@ -128,7 +128,7 @@ // Specify a new Instance, create an instance for a dependency on the fly string instanceKey = "OrangeWidgetRule"; - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName(instanceKey) .Child<IWidget>().Is( @@ -139,7 +139,7 @@ }); - WidgetRule rule = (WidgetRule) manager.CreateInstance<Rule>(instanceKey); + WidgetRule rule = (WidgetRule) manager.GetInstance<Rule>(instanceKey); ColorWidget widget = (ColorWidget) rule.Widget; Assert.AreEqual("Orange", widget.Color); } @@ -157,9 +157,9 @@ registry.AddPrototypeInstanceOf<IWidget>(theWidget).WithName("Jeremy"); }); - CloneableWidget widget1 = (CloneableWidget) manager.CreateInstance<IWidget>("Jeremy"); - CloneableWidget widget2 = (CloneableWidget) manager.CreateInstance<IWidget>("Jeremy"); - CloneableWidget widget3 = (CloneableWidget) manager.CreateInstance<IWidget>("Jeremy"); + CloneableWidget widget1 = (CloneableWidget) manager.GetInstance<IWidget>("Jeremy"); + CloneableWidget widget2 = (CloneableWidget) manager.GetInstance<IWidget>("Jeremy"); + CloneableWidget widget3 = (CloneableWidget) manager.GetInstance<IWidget>("Jeremy"); Assert.AreEqual("Jeremy", widget1.Name); Assert.AreEqual("Jeremy", widget2.Name); @@ -182,9 +182,9 @@ registry.AddInstanceOf<IWidget>(julia).WithName("Julia"); }); - CloneableWidget widget1 = (CloneableWidget) manager.CreateInstance<IWidget>("Julia"); - CloneableWidget widget2 = (CloneableWidget) manager.CreateInstance<IWidget>("Julia"); - CloneableWidget widget3 = (CloneableWidget) manager.CreateInstance<IWidget>("Julia"); + CloneableWidget widget1 = (CloneableWidget) manager.GetInstance<IWidget>("Julia"); + CloneableWidget widget2 = (CloneableWidget) manager.GetInstance<IWidget>("Julia"); + CloneableWidget widget3 = (CloneableWidget) manager.GetInstance<IWidget>("Julia"); Assert.AreSame(julia, widget1); Assert.AreSame(julia, widget2); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -30,7 +30,7 @@ [Test] public void A_concrete_type_is_available_by_name_when_it_is_added_by_the_shorthand_mechanism() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<IAddTypes>() .AddConcreteType<RedAddTypes>("Red") @@ -39,15 +39,15 @@ .AddConcreteType<PurpleAddTypes>(); }); - Assert.IsInstanceOfType(typeof (RedAddTypes), manager.CreateInstance<IAddTypes>("Red")); - Assert.IsInstanceOfType(typeof (GreenAddTypes), manager.CreateInstance<IAddTypes>("Green")); - Assert.IsInstanceOfType(typeof (BlueAddTypes), manager.CreateInstance<IAddTypes>("Blue")); + Assert.IsInstanceOfType(typeof (RedAddTypes), manager.GetInstance<IAddTypes>("Red")); + Assert.IsInstanceOfType(typeof (GreenAddTypes), manager.GetInstance<IAddTypes>("Green")); + Assert.IsInstanceOfType(typeof (BlueAddTypes), manager.GetInstance<IAddTypes>("Blue")); } [Test] public void A_concrete_type_is_available_when_it_is_added_by_the_shorthand_mechanism() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<IAddTypes>() .AddConcreteType<RedAddTypes>() @@ -64,7 +64,7 @@ [Test] public void Make_sure_that_we_dont_double_dip_instances_when_we_register_a_type_with_a_name() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<IAddTypes>() .AddConcreteType<RedAddTypes>("Red") Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -31,7 +31,7 @@ Concretion concretion1 = new Concretion(); Concretion concretion2 = new Concretion(); - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<Abstraction>() .AddInstances( @@ -40,8 +40,8 @@ ); }); - Assert.AreSame(concretion1, manager.CreateInstance<Abstraction>("One")); - Assert.AreSame(concretion2, manager.CreateInstance<Abstraction>("Two")); + Assert.AreSame(concretion1, manager.GetInstance<Abstraction>("One")); + Assert.AreSame(concretion2, manager.GetInstance<Abstraction>("Two")); } [Test] @@ -49,14 +49,14 @@ { Concretion concretion = new Concretion(); - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<Abstraction>().TheDefaultIs( ConstructedBy<Abstraction>(delegate { return concretion; }) ); }); - Assert.AreSame(concretion, manager.CreateInstance<Abstraction>()); + Assert.AreSame(concretion, manager.GetInstance<Abstraction>()); } [Test] @@ -65,7 +65,7 @@ Concretion concretion1 = new Concretion(); Concretion concretion2 = new Concretion(); - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<Abstraction>().AddInstance( ConstructedBy<Abstraction>(delegate { return concretion1; }).WithName("One") @@ -76,8 +76,8 @@ ); }); - Assert.AreSame(concretion1, manager.CreateInstance<Abstraction>("One")); - Assert.AreSame(concretion2, manager.CreateInstance<Abstraction>("Two")); + Assert.AreSame(concretion1, manager.GetInstance<Abstraction>("One")); + Assert.AreSame(concretion2, manager.GetInstance<Abstraction>("Two")); } [Test] @@ -85,7 +85,7 @@ { Concretion concretion = new Concretion(); - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<Abstraction>().AddInstance( ConstructedBy<Abstraction>(delegate { return concretion; }) Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -60,7 +60,7 @@ [Test] public void AddInstanceByNameOnlyAddsOneInstanceToStructureMap() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<Something>().AddInstance( RegistryExpressions.Instance<Something>().UsingConcreteType<RedSomething>().WithName("Red") @@ -73,7 +73,7 @@ [Test] public void AddInstanceWithNameOnlyAddsOneInstanceToStructureMap() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.AddInstanceOf<Something>().UsingConcreteType<RedSomething>().WithName("Red"); }); @@ -144,7 +144,7 @@ Assert.IsTrue(pluginGraph.ContainsFamily(typeof (IGateway))); InstanceManager manager = new InstanceManager(pluginGraph); - IGateway gateway = (IGateway) manager.CreateInstance(typeof (IGateway)); + IGateway gateway = (IGateway) manager.GetInstance(typeof (IGateway)); Assert.IsInstanceOfType(typeof (StubbedGateway), gateway); } @@ -159,7 +159,7 @@ Assert.IsTrue(pluginGraph.ContainsFamily(typeof (IGateway))); InstanceManager manager = new InstanceManager(pluginGraph); - IGateway gateway = (IGateway) manager.CreateInstance(typeof (IGateway)); + IGateway gateway = (IGateway) manager.GetInstance(typeof (IGateway)); Assert.IsInstanceOfType(typeof (FakeGateway), gateway); } @@ -167,7 +167,7 @@ [Test] public void CreatePluginFamilyWithADefault() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.BuildInstancesOf<IWidget>().TheDefaultIs( RegistryExpressions.Instance<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo( @@ -175,7 +175,7 @@ ); }); - ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>(); + ColorWidget widget = (ColorWidget) manager.GetInstance<IWidget>(); Assert.AreEqual("Red", widget.Color); } @@ -199,7 +199,7 @@ new InstanceManager( delegate(Registry registry) { registry.ForRequestedType<IWidget>().TheDefaultIs(delegate { return new AWidget(); }); }); - Assert.IsInstanceOfType(typeof (AWidget), manager.CreateInstance<IWidget>()); + Assert.IsInstanceOfType(typeof (AWidget), manager.GetInstance<IWidget>()); } [Test] @@ -211,19 +211,19 @@ new InstanceManager( delegate(Registry registry) { registry.ForRequestedType<IWidget>().TheDefaultIs(aWidget); }); - Assert.AreSame(aWidget, manager.CreateInstance<IWidget>()); + Assert.AreSame(aWidget, manager.GetInstance<IWidget>()); } [Test] public void TheDefaultInstanceIsConcreteType() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { // Needs to blow up if the concrete type can't be used registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<ARule>(); }); - Assert.IsInstanceOfType(typeof (ARule), manager.CreateInstance<Rule>()); + Assert.IsInstanceOfType(typeof (ARule), manager.GetInstance<Rule>()); } [Test] @@ -238,7 +238,7 @@ Assert.IsTrue(pluginGraph.ContainsFamily(typeof (IGateway))); InstanceManager manager = new InstanceManager(pluginGraph); - IGateway gateway = (IGateway) manager.CreateInstance(typeof (IGateway)); + IGateway gateway = (IGateway) manager.GetInstance(typeof (IGateway)); Assert.IsInstanceOfType(typeof (DefaultGateway), gateway); } Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -12,8 +12,8 @@ private void assertThingMatches(Action<Registry> action) { - IInstanceManager manager = new InstanceManager(action); - Thing actual = manager.CreateInstance<Thing>(); + IContainer manager = new InstanceManager(action); + Thing actual = manager.GetInstance<Thing>(); Assert.AreEqual(_prototype, actual); } Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -65,9 +65,9 @@ }); - Assert.IsInstanceOfType(typeof(Target1), manager.CreateInstance<ITarget>("1")); - Assert.IsInstanceOfType(typeof(Target2), manager.CreateInstance<ITarget>("2")); - Assert.IsInstanceOfType(typeof(Target3), manager.CreateInstance<ITarget>("3")); + Assert.IsInstanceOfType(typeof(Target1), manager.GetInstance<ITarget>("1")); + Assert.IsInstanceOfType(typeof(Target2), manager.GetInstance<ITarget>("2")); + Assert.IsInstanceOfType(typeof(Target3), manager.GetInstance<ITarget>("3")); } [Test] @@ -78,7 +78,7 @@ r.ForRequestedType(typeof (ITarget)).TheDefaultIsConcreteType(typeof (Target3)); }); - Assert.IsInstanceOfType(typeof(Target3), manager.CreateInstance<ITarget>()); + Assert.IsInstanceOfType(typeof(Target3), manager.GetInstance<ITarget>()); } [Test] @@ -89,7 +89,7 @@ r.ForRequestedType(typeof(ITarget)).TheDefaultIs(Instance<Target2>()); }); - Assert.IsInstanceOfType(typeof(Target2), manager.CreateInstance<ITarget>()); + Assert.IsInstanceOfType(typeof(Target2), manager.GetInstance<ITarget>()); } [Test] @@ -100,7 +100,7 @@ r.ForRequestedType(typeof(ITarget)).TheDefaultIs(delegate() { return new Target1(); }); }); - Assert.IsInstanceOfType(typeof(Target1), manager.CreateInstance<ITarget>()); + Assert.IsInstanceOfType(typeof(Target1), manager.GetInstance<ITarget>()); } [Test] @@ -125,7 +125,7 @@ .EnrichWith(delegate(object raw){ return new WrappedTarget((ITarget) raw);}); }); - WrappedTarget target = (WrappedTarget) manager.CreateInstance<ITarget>(); + WrappedTarget target = (WrappedTarget) manager.GetInstance<ITarget>(); Assert.IsInstanceOfType(typeof(Target1), target.Inner); } @@ -171,7 +171,7 @@ .OnCreation(delegate(object raw) { created = (ITarget) raw; }); }); - manager.CreateInstance<ITarget>(); + manager.GetInstance<ITarget>(); Assert.IsInstanceOfType(typeof(Target3), created); } Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -82,7 +82,7 @@ [Test] public void CanStillAddOtherPropertiesAfterTheCallToChildArray() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<Processor>() .TheDefaultIs( @@ -96,14 +96,14 @@ ); }); - Processor processor = manager.CreateInstance<Processor>(); + Processor processor = manager.GetInstance<Processor>(); Assert.AreEqual("Jeremy", processor.Name); } [Test] public void InjectPropertiesByName() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<Processor2>() .TheDefaultIs( @@ -120,7 +120,7 @@ }); - Processor2 processor = manager.CreateInstance<Processor2>(); + Processor2 processor = manager.GetInstance<Processor2>(); Assert.IsInstanceOfType(typeof (Handler1), processor.First[0]); Assert.IsInstanceOfType(typeof (Handler2), processor.First[1]); @@ -153,7 +153,7 @@ [Test] public void PlaceMemberInArrayByReference() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.AddInstanceOf<IHandler>().UsingConcreteType<Handler1>().WithName("One"); registry.AddInstanceOf<IHandler>().UsingConcreteType<Handler2>().WithName("Two"); @@ -169,7 +169,7 @@ ); }); - Processor processor = manager.CreateInstance<Processor>(); + Processor processor = manager.GetInstance<Processor>(); Assert.IsInstanceOfType(typeof (Handler2), processor.Handlers[0]); Assert.IsInstanceOfType(typeof (Handler1), processor.Handlers[1]); @@ -178,7 +178,7 @@ [Test] public void ProgrammaticallyInjectArrayAllInline() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<Processor>() .TheDefaultIs( @@ -192,7 +192,7 @@ ); }); - Processor processor = manager.CreateInstance<Processor>(); + Processor processor = manager.GetInstance<Processor>(); Assert.IsInstanceOfType(typeof (Handler1), processor.Handlers[0]); Assert.IsInstanceOfType(typeof (Handler2), processor.Handlers[1]); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -31,7 +31,7 @@ #endregion private IService _lastService; - private IInstanceManager _manager; + private IContainer _manager; private Action<Registry> _defaultRegistry; private IService getService(Action<Registry> action, string name) @@ -45,7 +45,7 @@ }); } - return _manager.CreateInstance<IService>(name); + return _manager.GetInstance<IService>(name); } [Test] Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -47,12 +47,12 @@ private ColorService _lastService; - private IInstanceManager _manager; + private IContainer _manager; [Test] public void DecorateAConstructedService() { - IService service = _manager.CreateInstance<IService>("Purple"); + IService service = _manager.GetInstance<IService>("Purple"); DecoratorService decoratorService = (DecoratorService) service; ColorService innerService = (ColorService) decoratorService.Inner; @@ -62,7 +62,7 @@ [Test] public void DecorateInline() { - IService service = _manager.CreateInstance<IService>("Decorated"); + IService service = _manager.GetInstance<IService>("Decorated"); DecoratorService decoratorService = (DecoratorService) service; ColorService innerService = (ColorService) decoratorService.Inner; @@ -74,7 +74,7 @@ public void OnCreationWithAConstructedService() { Assert.IsNull(_lastService); - IService interceptedService = _manager.CreateInstance<IService>("Yellow"); + IService interceptedService = _manager.GetInstance<IService>("Yellow"); Assert.AreSame(_lastService, interceptedService); } @@ -85,10 +85,10 @@ // "NotIntercepted" should not. Assert.IsNull(_lastService); - _manager.CreateInstance<IService>("NotIntercepted"); + _manager.GetInstance<IService>("NotIntercepted"); Assert.IsNull(_lastService); - IService interceptedService = _manager.CreateInstance<IService>("Intercepted"); + IService interceptedService = _manager.GetInstance<IService>("Intercepted"); Assert.AreSame(_lastService, interceptedService); } @@ -97,7 +97,7 @@ { try { - _manager.CreateInstance<IService>("Bad"); + _manager.GetInstance<IService>("Bad"); Assert.Fail("Should have thrown an error"); } catch (StructureMapException e) Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -58,7 +58,7 @@ InstanceManager manager = new InstanceManager(graph); manager.SetDefaultsToProfile(theProfileName); - AWidget widget = (AWidget)manager.CreateInstance<IWidget>(); + AWidget widget = (AWidget)manager.GetInstance<IWidget>(); Assert.IsNotNull(widget); } @@ -83,7 +83,7 @@ { string theProfileName = "something"; - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.CreateProfile(theProfileName) .For<IWidget>().UseConcreteType<AWidget>() @@ -91,8 +91,8 @@ }); manager.SetDefaultsToProfile(theProfileName); - Assert.IsInstanceOfType(typeof(AWidget), manager.CreateInstance<IWidget>()); - Assert.IsInstanceOfType(typeof(DefaultRule), manager.CreateInstance<Rule>()); + Assert.IsInstanceOfType(typeof(AWidget), manager.GetInstance<IWidget>()); + Assert.IsInstanceOfType(typeof(DefaultRule), manager.GetInstance<Rule>()); } @@ -101,7 +101,7 @@ { string theProfileName = "something"; - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.CreateProfile(theProfileName) .For<IWidget>().Use(delegate() { return new AWidget(); }) @@ -112,8 +112,8 @@ manager.SetDefaultsToProfile(theProfileName); - Assert.IsInstanceOfType(typeof(AWidget), manager.CreateInstance<IWidget>()); - Assert.IsInstanceOfType(typeof(DefaultRule), manager.CreateInstance<Rule>()); + Assert.IsInstanceOfType(typeof(AWidget), manager.GetInstance<IWidget>()); + Assert.IsInstanceOfType(typeof(DefaultRule), manager.GetInstance<Rule>()); } [Test] @@ -122,7 +122,7 @@ string theProfileName = "something"; IWidget theTemplate = new AWidget(); - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.CreateProfile(theProfileName) .For<IWidget>().UsePrototypeOf(theTemplate); @@ -130,8 +130,8 @@ manager.SetDefaultsToProfile(theProfileName); - IWidget widget1 = manager.CreateInstance<IWidget>(); - IWidget widget2 = manager.CreateInstance<IWidget>(); + IWidget widget1 = manager.GetInstance<IWidget>(); + IWidget widget2 = manager.GetInstance<IWidget>(); Assert.IsNotNull(widget1); Assert.IsNotNull(widget2); Modified: trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -39,20 +39,20 @@ [Test] public void GetTheRule() { - ColorRule rule = (ColorRule) _manager.CreateInstance<Rule>(); + ColorRule rule = (ColorRule) _manager.GetInstance<Rule>(); Assert.AreEqual("Blue", rule.Color); - ColorRule rule2 = (ColorRule) _manager.CreateInstance<Rule>(); + ColorRule rule2 = (ColorRule) _manager.GetInstance<Rule>(); Assert.AreSame(rule, rule2); } [Test] public void GetTheWidget() { - ColorWidget widget = (ColorWidget) _manager.CreateInstance<IWidget>(); + ColorWidget widget = (ColorWidget) _manager.GetInstance<IWidget>(); Assert.AreEqual("Red", widget.Color); - ColorWidget widget2 = (ColorWidget) _manager.CreateInstance<IWidget>(); + ColorWidget widget2 = (ColorWidget) _manager.GetInstance<IWidget>(); Assert.AreNotSame(widget, widget2); } } Modified: trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -87,7 +87,7 @@ ProfileBuilder.OverrideMachineName("GREEN-BOX"); InstanceManager manager = new InstanceManager(graph); - ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>(); + ColorWidget widget = (ColorWidget) manager.GetInstance<IWidget>(); Assert.AreEqual("Green", widget.Color); } @@ -97,7 +97,7 @@ ProfileBuilder.OverrideMachineName("ORANGE-BOX"); InstanceManager manager = new InstanceManager(graph); - ColorWidget widget = (ColorWidget)manager.CreateInstance<IWidget>(); + ColorWidget widget = (ColorWidget)manager.GetInstance<IWidget>(); Assert.AreEqual("Orange", widget.Color); } @@ -108,7 +108,7 @@ manager.SetDefaultsToProfile("Green"); - ColorWidget widget = (ColorWidget)manager.CreateInstance<IWidget>(); + ColorWidget widget = (ColorWidget)manager.GetInstance<IWidget>(); Assert.AreEqual("Green", widget.Color); } @@ -118,10 +118,10 @@ InstanceManager manager = new InstanceManager(graph); manager.SetDefaultsToProfile("Blue"); - ColorRule rule = (ColorRule) manager.CreateInstance<Rule>(); + ColorRule rule = (ColorRule) manager.GetInstance<Rule>(); Assert.AreEqual("Blue", rule.Color); - ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>(); + ColorWidget widget = (ColorWidget) manager.GetInstance<IWidget>(); Assert.AreEqual("Blue", widget.Color); } @@ -133,7 +133,7 @@ ProfileBuilder.OverrideMachineName("ORANGE-BOX"); InstanceManager manager = new InstanceManager(graph); - ColorWidget widget = (ColorWidget)manager.CreateInstance(typeof(IWidget)); + ColorWidget widget = (ColorWidget)manager.GetInstance(typeof(IWidget)); Assert.AreEqual("Orange", widget.Color); } @@ -143,7 +143,7 @@ ProfileBuilder.OverrideMachineName("GREEN-BOX"); InstanceManager manager = new InstanceManager(graph); - ColorWidget widget = (ColorWidget)manager.CreateInstance(typeof(IWidget)); + ColorWidget widget = (ColorWidget)manager.GetInstance(typeof(IWidget)); Assert.AreEqual("Green", widget.Color); } @@ -153,12 +153,12 @@ InstanceManager manager = new InstanceManager(graph); manager.SetDefaultsToProfile("Green"); - ColorRule greenRule = (ColorRule)manager.CreateInstance(typeof(Rule)); + ColorRule greenRule = (ColorRule)manager.GetInstance(typeof(Rule)); Assert.AreEqual("Green", greenRule.Color); manager.SetDefaultsToProfile("Blue"); - ColorRule blueRule = (ColorRule)manager.CreateInstance(typeof(Rule)); + ColorRule blueRule = (ColorRule)manager.GetInstance(typeof(Rule)); Assert.AreEqual("Blue", blueRule.Color); } } Modified: trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -49,17 +49,17 @@ [Test] public void GetTheRule() { - ColorRule rule = (ColorRule) _manager.CreateInstance<Rule>("Blue"); + ColorRule rule = (ColorRule) _manager.GetInstance<Rule>("Blue"); ... [truncated message content] |
From: <jer...@us...> - 2008-05-28 03:35:04
|
Revision: 106 http://structuremap.svn.sourceforge.net/structuremap/?rev=106&view=rev Author: jeremydmiller Date: 2008-05-27 20:35:02 -0700 (Tue, 27 May 2008) Log Message: ----------- minor refactoring of Registry Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-28 03:15:34 UTC (rev 105) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-28 03:35:02 UTC (rev 106) @@ -10,16 +10,9 @@ public class Registry : RegistryExpressions { private readonly List<Action<PluginGraph>> _actions = new List<Action<PluginGraph>>(); - private readonly PluginGraph _graph; - public Registry(PluginGraph graph) : this() - { - _graph = graph; - } - public Registry() { - _graph = new PluginGraph(); configure(); } @@ -79,10 +72,11 @@ public PluginGraph Build() { - ConfigurePluginGraph(_graph); - _graph.Seal(); + PluginGraph graph = new PluginGraph(); + ConfigurePluginGraph(graph); + graph.Seal(); - return _graph; + return graph; } /// <summary> @@ -95,10 +89,7 @@ ConfiguredInstance instance = new ConfiguredInstance(); addExpression( - delegate(PluginGraph pluginGraph) - { - pluginGraph.FindFamily(typeof (PLUGINTYPE)).AddInstance(instance); - }); + delegate(PluginGraph pluginGraph) { pluginGraph.FindFamily(typeof (PLUGINTYPE)).AddInstance(instance); }); return instance; } @@ -113,7 +104,7 @@ public LiteralInstance AddInstanceOf<PLUGINTYPE>(PLUGINTYPE target) { LiteralInstance literal = new LiteralInstance(target); - _graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(literal); + _actions.Add(delegate(PluginGraph graph) { graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(literal); }); return literal; } @@ -126,10 +117,13 @@ /// <returns></returns> public PrototypeInstance AddPrototypeInstanceOf<PLUGINTYPE>(PLUGINTYPE prototype) { - PrototypeInstance expression = new PrototypeInstance((ICloneable) prototype); - _graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(expression); + PrototypeInstance instance = new PrototypeInstance((ICloneable) prototype); + _actions.Add(delegate(PluginGraph graph) + { + graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(instance); + }); - return expression; + return instance; } /// <summary> @@ -138,7 +132,7 @@ /// <typeparam name="PLUGINTYPE"></typeparam> /// <param name="url"></param> /// <returns></returns> - public static UserControlInstance LoadUserControlFrom<PLUGINTYPE>(string url) + public static UserControlInstance LoadUserControlFrom(string url) { return new UserControlInstance(url); } Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2008-05-28 03:15:34 UTC (rev 105) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2008-05-28 03:35:02 UTC (rev 106) @@ -24,11 +24,6 @@ public class TestRegistry : Registry { - public TestRegistry(PluginGraph graph) : base(graph) - { - } - - public TestRegistry() { } Modified: trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs 2008-05-28 03:15:34 UTC (rev 105) +++ trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs 2008-05-28 03:35:02 UTC (rev 106) @@ -18,23 +18,20 @@ [SetUp] public void SetUp() { - PluginGraph graph = new PluginGraph(); - Registry registry = new Registry(graph); + Registry registry = new Registry(); registry.BuildInstancesOf<Rule>(); registry.ScanAssemblies() .IncludeAssembly("StructureMap.Testing.Widget") .IncludeAssembly("StructureMap.Testing.Widget2"); - registry.Build(); + PluginGraph graph = registry.Build(); PipelineGraph pipelineGraph = new PipelineGraph(graph); _session = new BuildSession(pipelineGraph, graph.InterceptorLibrary); - instance = new ConfiguredInstance(); } #endregion - private ConfiguredInstance instance; private IBuildSession _session; @@ -52,17 +49,7 @@ } } - [Test] - public void TestComplexRule() - { - ConfiguredInstance instance = (ConfiguredInstance)ComplexRule.GetInstance(); - Rule rule = (Rule)instance.Build(typeof(Rule), _session); - Assert.IsNotNull(rule); - Assert.IsTrue(rule is ComplexRule); - } - - [Test] public void AttachDependencies_should_find_the_InstanceBuilder_by_ConcreteKey_if_PluggedType_does_not_exists() { @@ -106,7 +93,7 @@ using (mocks.Playback()) { - object actualObject = ((IConfiguredInstance)instance).Build(GetType(), session, builder); + object actualObject = ((IConfiguredInstance) instance).Build(GetType(), session, builder); Assert.AreSame(theObjectBuilt, actualObject); } } @@ -134,10 +121,10 @@ [Test, ExpectedException(typeof (StructureMapException))] public void BuildRuleWithAMissingValue() { - IStructuredInstance instance = (IStructuredInstance)ComplexRule.GetInstance(); + IStructuredInstance instance = (IStructuredInstance) ComplexRule.GetInstance(); instance.RemoveKey("String"); - ComplexRule rule = (ComplexRule) ((Instance)instance).Build(typeof (Rule), _session); + ComplexRule rule = (ComplexRule) ((Instance) instance).Build(typeof (Rule), _session); } [Test] @@ -225,7 +212,8 @@ [Test] public void GetProperty_happy_path() { - instance.SetProperty("Color", "Red") + ConfiguredInstance instance = new ConfiguredInstance() + .SetProperty("Color", "Red") .SetProperty("Age", "34"); IConfiguredInstance configuredInstance = instance; @@ -242,7 +230,7 @@ { try { - IConfiguredInstance configuredInstance = instance; + IConfiguredInstance configuredInstance = new ConfiguredInstance(); configuredInstance.GetProperty("anything"); Assert.Fail("Did not throw exception"); } @@ -277,6 +265,16 @@ } [Test] + public void TestComplexRule() + { + ConfiguredInstance instance = (ConfiguredInstance) ComplexRule.GetInstance(); + + Rule rule = (Rule) instance.Build(typeof (Rule), _session); + Assert.IsNotNull(rule); + Assert.IsTrue(rule is ComplexRule); + } + + [Test] public void Trying_to_build_with_an_InvalidCastException_will_throw_error_206() { MockRepository mocks = new MockRepository(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-05-28 03:15:35
|
Revision: 105 http://structuremap.svn.sourceforge.net/structuremap/?rev=105&view=rev Author: jeremydmiller Date: 2008-05-27 20:15:34 -0700 (Tue, 27 May 2008) Log Message: ----------- Cleaning up Registry code Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Configuration/FamilyParser.cs trunk/Source/StructureMap/InstanceManager.cs trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap.Testing/BuildSessionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs trunk/Source/StructureMap.Testing/Container/Interceptors/TypeInterceptionTester.cs trunk/Source/StructureMap.Testing/Container/TypeFindingTester.cs trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-27 23:46:15 UTC (rev 104) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-28 03:15:34 UTC (rev 105) @@ -32,7 +32,18 @@ }); } + public CreatePluginFamilyExpression<PLUGINTYPE> AddInstances(params Instance[] instances) + { + return alterAndContinue(delegate(PluginFamily family) + { + foreach (Instance instance in instances) + { + family.AddInstance(instance); + } + }); + } + // TODO: 3.5, Try alterAndContinue(f => {}); private CreatePluginFamilyExpression<PLUGINTYPE> alterAndContinue(Action<PluginFamily> action) { Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-27 23:46:15 UTC (rev 104) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-28 03:15:34 UTC (rev 105) @@ -7,7 +7,7 @@ namespace StructureMap.Configuration.DSL { - public class Registry : RegistryExpressions, IDisposable + public class Registry : RegistryExpressions { private readonly List<Action<PluginGraph>> _actions = new List<Action<PluginGraph>>(); private readonly PluginGraph _graph; @@ -23,15 +23,6 @@ configure(); } - #region IDisposable Members - - public void Dispose() - { - ConfigurePluginGraph(_graph); - } - - #endregion - /// <summary> /// Implement this method to /// </summary> @@ -86,12 +77,6 @@ return new CreatePluginFamilyExpression<PLUGINTYPE>(this); } - public IInstanceManager BuildInstanceManager() - { - ConfigurePluginGraph(_graph); - return new InstanceManager(_graph); - } - public PluginGraph Build() { ConfigurePluginGraph(_graph); Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-27 23:46:15 UTC (rev 104) +++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-28 03:15:34 UTC (rev 105) @@ -62,12 +62,12 @@ }); } - private InstanceScope findScope(XmlElement familyElement) + private static InstanceScope findScope(XmlElement familyElement) { InstanceScope returnValue = InstanceScope.PerRequest; string scopeString = familyElement.GetAttribute(XmlConstants.SCOPE_ATTRIBUTE); - if (scopeString != null && scopeString != string.Empty) + if (!string.IsNullOrEmpty(scopeString)) { returnValue = (InstanceScope) Enum.Parse(typeof (InstanceScope), scopeString); } Modified: trunk/Source/StructureMap/InstanceManager.cs =================================================================== --- trunk/Source/StructureMap/InstanceManager.cs 2008-05-27 23:46:15 UTC (rev 104) +++ trunk/Source/StructureMap/InstanceManager.cs 2008-05-28 03:15:34 UTC (rev 105) @@ -27,6 +27,10 @@ construct(registry.Build()); } + public InstanceManager(Registry registry) : this(registry.Build()) + { + } + public InstanceManager() : this(new PluginGraph()) { } @@ -283,6 +287,5 @@ return _pipelineGraph.ForType(type); } - } } \ No newline at end of file Modified: trunk/Source/StructureMap/StructureMapConfiguration.cs =================================================================== --- trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-05-27 23:46:15 UTC (rev 104) +++ trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-05-28 03:15:34 UTC (rev 105) @@ -166,7 +166,12 @@ return _registry.AddInstanceOf<T>(); } + public static void AddInstanceOf<T>(Instance instance) + { + _registry.ForRequestedType<T>().AddInstance(instance); + } + /// <summary> /// Adds a preconfigured instance of Type T to StructureMap. When this instance is requested, /// StructureMap will always return the original object. Modified: trunk/Source/StructureMap.Testing/BuildSessionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-05-27 23:46:15 UTC (rev 104) +++ trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-05-28 03:15:34 UTC (rev 105) @@ -138,13 +138,13 @@ [Test] public void If_no_child_array_is_explicitly_defined_return_all_instances() { - Registry registry = new Registry(); - registry.AddInstanceOf<IWidget>(new ColorWidget("Red")); - registry.AddInstanceOf<IWidget>(new ColorWidget("Blue")); - registry.AddInstanceOf<IWidget>(new ColorWidget("Green")); + IInstanceManager manager = new InstanceManager(delegate(Registry registry) + { + registry.AddInstanceOf<IWidget>(new ColorWidget("Red")); + registry.AddInstanceOf<IWidget>(new ColorWidget("Blue")); + registry.AddInstanceOf<IWidget>(new ColorWidget("Green")); + }); - IInstanceManager manager = registry.BuildInstanceManager(); - WidgetHolder holder = manager.CreateInstance<WidgetHolder>(); Assert.AreEqual(3, holder.Widgets.Length); } Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2008-05-27 23:46:15 UTC (rev 104) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2008-05-28 03:15:34 UTC (rev 105) @@ -15,38 +15,38 @@ [SetUp] public void SetUp() { - pluginGraph = new PluginGraph(); - Registry registry = new Registry(pluginGraph); - registry.ScanAssemblies().IncludeAssemblyContainingType<ColorWidget>(); + + manager = new InstanceManager(delegate(Registry registry) + { + registry.ScanAssemblies().IncludeAssemblyContainingType<ColorWidget>(); - // Add an instance with properties - registry.AddInstanceOf<IWidget>() - .UsingConcreteType<ColorWidget>() - .WithName("DarkGreen") - .WithProperty("Color").EqualTo("DarkGreen"); + // Add an instance with properties + registry.AddInstanceOf<IWidget>() + .UsingConcreteType<ColorWidget>() + .WithName("DarkGreen") + .WithProperty("Color").EqualTo("DarkGreen"); - // Add an instance by specifying the ConcreteKey - registry.AddInstanceOf<IWidget>() - .UsingConcreteTypeNamed("Color") - .WithName("Purple") - .WithProperty("Color").EqualTo("Purple"); + // Add an instance by specifying the ConcreteKey + registry.AddInstanceOf<IWidget>() + .UsingConcreteTypeNamed("Color") + .WithName("Purple") + .WithProperty("Color").EqualTo("Purple"); - // Pull a property from the App config - registry.AddInstanceOf<IWidget>() - .UsingConcreteType<ColorWidget>() - .WithName("AppSetting") - .WithProperty("Color").EqualToAppSetting("Color"); + // Pull a property from the App config + registry.AddInstanceOf<IWidget>() + .UsingConcreteType<ColorWidget>() + .WithName("AppSetting") + .WithProperty("Color").EqualToAppSetting("Color"); - registry.AddInstanceOf<IWidget>().UsingConcreteType<AWidget>(); + registry.AddInstanceOf<IWidget>().UsingConcreteType<AWidget>(); - manager = registry.BuildInstanceManager(); + }); } #endregion private IInstanceManager manager; - private PluginGraph pluginGraph; [Test] public void AddAnInstanceWithANameAndAPropertySpecifyingConcreteKey() @@ -65,14 +65,13 @@ [Test] public void AddInstanceAndOverrideTheConcreteTypeForADependency() { - Registry registry = new Registry(); + IInstanceManager manager = new InstanceManager(delegate(Registry registry) + { + // Specify a new Instance that specifies the concrete type used for a dependency + registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName("AWidgetRule") + .Child<IWidget>().IsConcreteType<AWidget>(); + }); - // Specify a new Instance that specifies the concrete type used for a dependency - registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName("AWidgetRule") - .Child<IWidget>().IsConcreteType<AWidget>(); - - manager = registry.BuildInstanceManager(); - WidgetRule rule = (WidgetRule) manager.CreateInstance<Rule>("AWidgetRule"); Assert.IsInstanceOfType(typeof (AWidget), rule.Widget); } @@ -88,13 +87,12 @@ [Test] public void SimpleCaseWithNamedInstance() { - Registry registry = new Registry(); + manager = new InstanceManager(delegate(Registry registry) + { + // Specify a new Instance and override the Name + registry.AddInstanceOf<IWidget>().UsingConcreteType<AWidget>().WithName("MyInstance"); + }); - // Specify a new Instance and override the Name - registry.AddInstanceOf<IWidget>().UsingConcreteType<AWidget>().WithName("MyInstance"); - - manager = registry.BuildInstanceManager(); - AWidget widget = (AWidget) manager.CreateInstance<IWidget>("MyInstance"); Assert.IsNotNull(widget); } @@ -102,25 +100,21 @@ [Test] public void SpecifyANewInstanceOverrideADependencyWithANamedInstance() { - Registry registry = new Registry(); + manager = new InstanceManager(delegate(Registry registry) + { + registry.AddInstanceOf<Rule>().UsingConcreteType<ARule>().WithName("Alias"); - //registry.ScanAssemblies().IncludeAssemblyContainingType<IWidget>(); + // Add an instance by specifying the ConcreteKey + registry.AddInstanceOf<IWidget>() + .UsingConcreteType<ColorWidget>() + .WithName("Purple") + .WithProperty("Color").EqualTo("Purple"); + // Specify a new Instance, override a dependency with a named instance + registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName("RuleThatUsesMyInstance") + .Child<IWidget>("widget").IsNamedInstance("Purple"); + }); - registry.AddInstanceOf<Rule>().UsingConcreteType<ARule>().WithName("Alias"); - - // Add an instance by specifying the ConcreteKey - registry.AddInstanceOf<IWidget>() - .UsingConcreteType<ColorWidget>() - .WithName("Purple") - .WithProperty("Color").EqualTo("Purple"); - - // Specify a new Instance, override a dependency with a named instance - registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName("RuleThatUsesMyInstance") - .Child<IWidget>("widget").IsNamedInstance("Purple"); - - manager = registry.BuildInstanceManager(); - Assert.IsInstanceOfType(typeof (ARule), manager.CreateInstance<Rule>("Alias")); WidgetRule rule = (WidgetRule) manager.CreateInstance<Rule>("RuleThatUsesMyInstance"); @@ -131,21 +125,21 @@ [Test] public void SpecifyANewInstanceWithADependency() { - Registry registry = new Registry(); - // Specify a new Instance, create an instance for a dependency on the fly string instanceKey = "OrangeWidgetRule"; - registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName(instanceKey) - .Child<IWidget>().Is( - Registry.Instance<IWidget>().UsingConcreteType<ColorWidget>() - .WithProperty("Color").EqualTo("Orange") - .WithName("Orange") - ); - IInstanceManager mgr = registry.BuildInstanceManager(); + IInstanceManager manager = new InstanceManager(delegate(Registry registry) + { + registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName(instanceKey) + .Child<IWidget>().Is( + Registry.Instance<IWidget>().UsingConcreteType<ColorWidget>() + .WithProperty("Color").EqualTo("Orange") + .WithName("Orange") + ); + }); - WidgetRule rule = (WidgetRule) mgr.CreateInstance<Rule>(instanceKey); + WidgetRule rule = (WidgetRule) manager.CreateInstance<Rule>(instanceKey); ColorWidget widget = (ColorWidget) rule.Widget; Assert.AreEqual("Orange", widget.Color); } @@ -153,13 +147,15 @@ [Test] public void UseAPreBuiltObjectForAnInstanceAsAPrototype() { - Registry registry = new Registry(); // Build an instance for IWidget, then setup StructureMap to return cloned instances of the // "Prototype" (GoF pattern) whenever someone asks for IWidget named "Jeremy" CloneableWidget theWidget = new CloneableWidget("Jeremy"); - registry.AddPrototypeInstanceOf<IWidget>(theWidget).WithName("Jeremy"); + - manager = registry.BuildInstanceManager(); + manager = new InstanceManager(delegate(Registry registry) + { + registry.AddPrototypeInstanceOf<IWidget>(theWidget).WithName("Jeremy"); + }); CloneableWidget widget1 = (CloneableWidget) manager.CreateInstance<IWidget>("Jeremy"); CloneableWidget widget2 = (CloneableWidget) manager.CreateInstance<IWidget>("Jeremy"); @@ -178,12 +174,13 @@ [Test] public void UseAPreBuiltObjectWithAName() { - Registry registry = new Registry(); // Return the specific instance when an IWidget named "Julia" is requested CloneableWidget julia = new CloneableWidget("Julia"); - registry.AddInstanceOf<IWidget>(julia).WithName("Julia"); - manager = registry.BuildInstanceManager(); + manager = new InstanceManager(delegate(Registry registry) + { + registry.AddInstanceOf<IWidget>(julia).WithName("Julia"); + }); CloneableWidget widget1 = (CloneableWidget) manager.CreateInstance<IWidget>("Julia"); CloneableWidget widget2 = (CloneableWidget) manager.CreateInstance<IWidget>("Julia"); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs 2008-05-27 23:46:15 UTC (rev 104) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs 2008-05-28 03:15:34 UTC (rev 105) @@ -30,14 +30,15 @@ [Test] public void A_concrete_type_is_available_by_name_when_it_is_added_by_the_shorthand_mechanism() { - Registry registry = new Registry(); - registry.ForRequestedType<IAddTypes>() - .AddConcreteType<RedAddTypes>("Red") - .AddConcreteType<GreenAddTypes>("Green") - .AddConcreteType<BlueAddTypes>("Blue") - .AddConcreteType<PurpleAddTypes>(); + IInstanceManager manager = new InstanceManager(delegate(Registry registry) + { + registry.ForRequestedType<IAddTypes>() + .AddConcreteType<RedAddTypes>("Red") + .AddConcreteType<GreenAddTypes>("Green") + .AddConcreteType<BlueAddTypes>("Blue") + .AddConcreteType<PurpleAddTypes>(); + }); - IInstanceManager manager = registry.BuildInstanceManager(); Assert.IsInstanceOfType(typeof (RedAddTypes), manager.CreateInstance<IAddTypes>("Red")); Assert.IsInstanceOfType(typeof (GreenAddTypes), manager.CreateInstance<IAddTypes>("Green")); Assert.IsInstanceOfType(typeof (BlueAddTypes), manager.CreateInstance<IAddTypes>("Blue")); @@ -46,28 +47,33 @@ [Test] public void A_concrete_type_is_available_when_it_is_added_by_the_shorthand_mechanism() { - Registry registry = new Registry(); - registry.ForRequestedType<IAddTypes>() - .AddConcreteType<RedAddTypes>() - .AddConcreteType<GreenAddTypes>() - .AddConcreteType<BlueAddTypes>() - .AddConcreteType<PurpleAddTypes>(); + IInstanceManager manager = new InstanceManager(delegate(Registry registry) + { + registry.ForRequestedType<IAddTypes>() + .AddConcreteType<RedAddTypes>() + .AddConcreteType<GreenAddTypes>() + .AddConcreteType<BlueAddTypes>() + .AddConcreteType<PurpleAddTypes>(); + }); - IList<IAddTypes> instances = registry.BuildInstanceManager().GetAllInstances<IAddTypes>(); + + IList<IAddTypes> instances = manager.GetAllInstances<IAddTypes>(); Assert.AreEqual(4, instances.Count); } [Test] public void Make_sure_that_we_dont_double_dip_instances_when_we_register_a_type_with_a_name() { - Registry registry = new Registry(); - registry.ForRequestedType<IAddTypes>() - .AddConcreteType<RedAddTypes>("Red") - .AddConcreteType<GreenAddTypes>() - .AddConcreteType<BlueAddTypes>("Blue") - .AddConcreteType<PurpleAddTypes>(); + IInstanceManager manager = new InstanceManager(delegate(Registry registry) + { + registry.ForRequestedType<IAddTypes>() + .AddConcreteType<RedAddTypes>("Red") + .AddConcreteType<GreenAddTypes>() + .AddConcreteType<BlueAddTypes>("Blue") + .AddConcreteType<PurpleAddTypes>(); + }); - IList<IAddTypes> instances = registry.BuildInstanceManager().GetAllInstances<IAddTypes>(); + IList<IAddTypes> instances = manager.GetAllInstances<IAddTypes>(); Assert.AreEqual(4, instances.Count); } } Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs 2008-05-27 23:46:15 UTC (rev 104) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs 2008-05-28 03:15:34 UTC (rev 105) @@ -31,17 +31,15 @@ Concretion concretion1 = new Concretion(); Concretion concretion2 = new Concretion(); - Registry registry = new Registry(); - registry.ForRequestedType<Abstraction>() - .AddInstance( - ConstructedBy<Abstraction>(delegate { return concretion1; }).WithName("One") - ) - .AddInstance( - ConstructedBy<Abstraction>(delegate { return concretion2; }).WithName("Two") - ); + IInstanceManager manager = new InstanceManager(delegate(Registry registry) + { + registry.ForRequestedType<Abstraction>() + .AddInstances( + ConstructedBy<Abstraction>(delegate { return concretion1; }).WithName("One"), + ConstructedBy<Abstraction>(delegate { return concretion2; }).WithName("Two") + ); + }); - IInstanceManager manager = registry.BuildInstanceManager(); - Assert.AreSame(concretion1, manager.CreateInstance<Abstraction>("One")); Assert.AreSame(concretion2, manager.CreateInstance<Abstraction>("Two")); } @@ -51,12 +49,13 @@ { Concretion concretion = new Concretion(); - Registry registry = new Registry(); - registry.ForRequestedType<Abstraction>().TheDefaultIs( - ConstructedBy<Abstraction>(delegate { return concretion; }) - ); + IInstanceManager manager = new InstanceManager(delegate(Registry registry) + { + registry.ForRequestedType<Abstraction>().TheDefaultIs( + ConstructedBy<Abstraction>(delegate { return concretion; }) + ); + }); - IInstanceManager manager = registry.BuildInstanceManager(); Assert.AreSame(concretion, manager.CreateInstance<Abstraction>()); } @@ -66,17 +65,17 @@ Concretion concretion1 = new Concretion(); Concretion concretion2 = new Concretion(); - Registry registry = new Registry(); - registry.ForRequestedType<Abstraction>().AddInstance( - ConstructedBy<Abstraction>(delegate { return concretion1; }).WithName("One") - ); + IInstanceManager manager = new InstanceManager(delegate(Registry registry) + { + registry.ForRequestedType<Abstraction>().AddInstance( + ConstructedBy<Abstraction>(delegate { return concretion1; }).WithName("One") + ); - registry.ForRequestedType<Abstraction>().AddInstance( - ConstructedBy<Abstraction>(delegate { return concretion2; }).WithName("Two") - ); + registry.ForRequestedType<Abstraction>().AddInstance( + ConstructedBy<Abstraction>(delegate { return concretion2; }).WithName("Two") + ); + }); - IInstanceManager manager = registry.BuildInstanceManager(); - Assert.AreSame(concretion1, manager.CreateInstance<Abstraction>("One")); Assert.AreSame(concretion2, manager.CreateInstance<Abstraction>("Two")); } @@ -86,14 +85,13 @@ { Concretion concretion = new Concretion(); - Registry registry = new Registry(); - registry.ForRequestedType<Abstraction>().AddInstance( - ConstructedBy<Abstraction>(delegate { return concretion; }) - ); + IInstanceManager manager = new InstanceManager(delegate(Registry registry) + { + registry.ForRequestedType<Abstraction>().AddInstance( + ConstructedBy<Abstraction>(delegate { return concretion; }) + ); + }); - - IInstanceManager manager = registry.BuildInstanceManager(); - Abstraction actual = manager.GetAllInstances<Abstraction>()[0]; Assert.AreSame(concretion, actual); } Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-05-27 23:46:15 UTC (rev 104) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-05-28 03:15:34 UTC (rev 105) @@ -5,7 +5,6 @@ using StructureMap.Configuration.DSL; using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; -using StructureMap.Interceptors; using StructureMap.Pipeline; using StructureMap.Testing.Widget; using StructureMap.Testing.Widget3; @@ -37,14 +36,36 @@ } [Test] - public void AddInstanceByNameOnlyAddsOneInstanceToStructureMap() + public void Add_an_instance_by_lambda() { - Registry registry = new Registry(); - registry.ForRequestedType<Something>().AddInstance( - Registry.Instance<Something>().UsingConcreteType<RedSomething>().WithName("Red") - ); + InstanceManager manager = + new InstanceManager( + delegate(Registry registry) { registry.ForRequestedType<IWidget>().AddInstance(delegate { return new AWidget(); }); }); - IInstanceManager manager = registry.BuildInstanceManager(); + Assert.IsInstanceOfType(typeof (AWidget), manager.GetAllInstances<IWidget>()[0]); + } + + [Test] + public void Add_an_instance_by_literal() + { + AWidget aWidget = new AWidget(); + + InstanceManager manager = + new InstanceManager( + delegate(Registry registry) { registry.ForRequestedType<IWidget>().AddInstance(aWidget); }); + + Assert.IsInstanceOfType(typeof (AWidget), manager.GetAllInstances<IWidget>()[0]); + } + + [Test] + public void AddInstanceByNameOnlyAddsOneInstanceToStructureMap() + { + IInstanceManager manager = new InstanceManager(delegate(Registry registry) + { + registry.ForRequestedType<Something>().AddInstance( + RegistryExpressions.Instance<Something>().UsingConcreteType<RedSomething>().WithName("Red") + ); + }); IList<Something> instances = manager.GetAllInstances<Something>(); Assert.AreEqual(1, instances.Count); } @@ -52,12 +73,10 @@ [Test] public void AddInstanceWithNameOnlyAddsOneInstanceToStructureMap() { - PluginGraph graph = new PluginGraph(); - Registry registry = new Registry(graph); - registry.AddInstanceOf<Something>().UsingConcreteType<RedSomething>().WithName("Red"); - - - IInstanceManager manager = registry.BuildInstanceManager(); + IInstanceManager manager = new InstanceManager(delegate(Registry registry) + { + registry.AddInstanceOf<Something>().UsingConcreteType<RedSomething>().WithName("Red"); + }); IList<Something> instances = manager.GetAllInstances<Something>(); Assert.AreEqual(1, instances.Count); } @@ -65,72 +84,64 @@ [Test] public void AsAnotherScope() { - PluginGraph pluginGraph = new PluginGraph(); - using (Registry registry = new Registry(pluginGraph)) - { - CreatePluginFamilyExpression<IGateway> expression = - registry.BuildInstancesOf<IGateway>().CacheBy(InstanceScope.ThreadLocal); - Assert.IsNotNull(expression); - } + Registry registry = new Registry(); + CreatePluginFamilyExpression<IGateway> expression = + registry.BuildInstancesOf<IGateway>().CacheBy(InstanceScope.ThreadLocal); + Assert.IsNotNull(expression); + PluginGraph pluginGraph = registry.Build(); + PluginFamily family = pluginGraph.FindFamily(typeof (IGateway)); - Assert.IsInstanceOfType(typeof(ThreadLocalStoragePolicy), family.Policy); + Assert.IsInstanceOfType(typeof (ThreadLocalStoragePolicy), family.Policy); } [Test] public void BuildInstancesOfType() { - PluginGraph pluginGraph = new PluginGraph(); - using (Registry registry = new Registry(pluginGraph)) - { - registry.BuildInstancesOf<IGateway>(); - } + Registry registry = new Registry(); + registry.BuildInstancesOf<IGateway>(); + PluginGraph pluginGraph = registry.Build(); - Assert.IsTrue(pluginGraph.ContainsFamily(typeof(IGateway))); + Assert.IsTrue(pluginGraph.ContainsFamily(typeof (IGateway))); } [Test] public void BuildPluginFamilyAsPerRequest() { - PluginGraph pluginGraph = new PluginGraph(); - using (Registry registry = new Registry(pluginGraph)) - { - CreatePluginFamilyExpression<IGateway> expression = - registry.BuildInstancesOf<IGateway>(); - Assert.IsNotNull(expression); - } + Registry registry = new Registry(); + CreatePluginFamilyExpression<IGateway> expression = + registry.BuildInstancesOf<IGateway>(); + Assert.IsNotNull(expression); + PluginGraph pluginGraph = registry.Build(); + PluginFamily family = pluginGraph.FindFamily(typeof (IGateway)); - Assert.IsInstanceOfType(typeof(BuildPolicy), family.Policy); + Assert.IsInstanceOfType(typeof (BuildPolicy), family.Policy); } [Test] public void BuildPluginFamilyAsSingleton() { - PluginGraph pluginGraph = new PluginGraph(); - using (Registry registry = new Registry(pluginGraph)) - { - CreatePluginFamilyExpression<IGateway> expression = - registry.BuildInstancesOf<IGateway>().AsSingletons(); - Assert.IsNotNull(expression); - } + Registry registry = new Registry(); + CreatePluginFamilyExpression<IGateway> expression = + registry.BuildInstancesOf<IGateway>().AsSingletons(); + Assert.IsNotNull(expression); + PluginGraph pluginGraph = registry.Build(); PluginFamily family = pluginGraph.FindFamily(typeof (IGateway)); - Assert.IsInstanceOfType(typeof(SingletonPolicy), family.Policy); + Assert.IsInstanceOfType(typeof (SingletonPolicy), family.Policy); } [Test] public void CanOverrideTheDefaultInstance1() { - PluginGraph pluginGraph = new PluginGraph(); - using (Registry registry = new Registry(pluginGraph)) - { - // Specify the default implementation for an interface - registry.BuildInstancesOf<IGateway>().TheDefaultIsConcreteType<StubbedGateway>(); - } + Registry registry = new Registry(); + // Specify the default implementation for an interface + registry.BuildInstancesOf<IGateway>().TheDefaultIsConcreteType<StubbedGateway>(); - Assert.IsTrue(pluginGraph.ContainsFamily(typeof(IGateway))); + PluginGraph pluginGraph = registry.Build(); + Assert.IsTrue(pluginGraph.ContainsFamily(typeof (IGateway))); InstanceManager manager = new InstanceManager(pluginGraph); IGateway gateway = (IGateway) manager.CreateInstance(typeof (IGateway)); @@ -141,13 +152,11 @@ [Test] public void CanOverrideTheDefaultInstanceAndCreateAnAllNewPluginOnTheFly() { - PluginGraph pluginGraph = new PluginGraph(); - using (Registry registry = new Registry(pluginGraph)) - { - registry.BuildInstancesOf<IGateway>().TheDefaultIsConcreteType<FakeGateway>(); - } + Registry registry = new Registry(); + registry.BuildInstancesOf<IGateway>().TheDefaultIsConcreteType<FakeGateway>(); + PluginGraph pluginGraph = registry.Build(); - Assert.IsTrue(pluginGraph.ContainsFamily(typeof(IGateway))); + Assert.IsTrue(pluginGraph.ContainsFamily(typeof (IGateway))); InstanceManager manager = new InstanceManager(pluginGraph); IGateway gateway = (IGateway) manager.CreateInstance(typeof (IGateway)); @@ -158,13 +167,14 @@ [Test] public void CreatePluginFamilyWithADefault() { - Registry registry = new Registry(); - registry.BuildInstancesOf<IWidget>().TheDefaultIs( - Registry.Instance<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo("Red") - ); + IInstanceManager manager = new InstanceManager(delegate(Registry registry) + { + registry.BuildInstancesOf<IWidget>().TheDefaultIs( + RegistryExpressions.Instance<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo( + "Red") + ); + }); - IInstanceManager manager = registry.BuildInstanceManager(); - ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>(); Assert.AreEqual("Red", widget.Color); } @@ -174,44 +184,22 @@ { StubbedInstanceFactoryInterceptor factoryInterceptor = new StubbedInstanceFactoryInterceptor(); - PluginGraph pluginGraph = new PluginGraph(); - using (Registry registry = new Registry(pluginGraph)) - { - registry.BuildInstancesOf<IGateway>().InterceptConstructionWith(factoryInterceptor); - } - - Assert.AreSame(pluginGraph.FindFamily(typeof(IGateway)).Policy, factoryInterceptor); - } - - [Test] - public void TheDefaultInstanceIsConcreteType() - { Registry registry = new Registry(); + registry.BuildInstancesOf<IGateway>().InterceptConstructionWith(factoryInterceptor); - // Needs to blow up if the concrete type can't be used - registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<ARule>(); + PluginGraph pluginGraph = registry.Build(); - IInstanceManager manager = registry.BuildInstanceManager(); - - Assert.IsInstanceOfType(typeof (ARule), manager.CreateInstance<Rule>()); + Assert.AreSame(pluginGraph.FindFamily(typeof (IGateway)).Policy, factoryInterceptor); } [Test] - public void TheDefaultInstanceIsPickedUpFromTheAttribute() + public void Set_the_default_by_a_lambda() { - PluginGraph pluginGraph = new PluginGraph(); - using (Registry registry = new Registry(pluginGraph)) - { - registry.BuildInstancesOf<IGateway>(); - registry.ScanAssemblies().IncludeAssemblyContainingType<IGateway>(); - } + InstanceManager manager = + new InstanceManager( + delegate(Registry registry) { registry.ForRequestedType<IWidget>().TheDefaultIs(delegate { return new AWidget(); }); }); - Assert.IsTrue(pluginGraph.ContainsFamily(typeof(IGateway))); - - InstanceManager manager = new InstanceManager(pluginGraph); - IGateway gateway = (IGateway) manager.CreateInstance(typeof (IGateway)); - - Assert.IsInstanceOfType(typeof (DefaultGateway), gateway); + Assert.IsInstanceOfType(typeof (AWidget), manager.CreateInstance<IWidget>()); } [Test] @@ -219,56 +207,51 @@ { AWidget aWidget = new AWidget(); - InstanceManager manager = new InstanceManager(delegate(Registry registry) - { - registry.ForRequestedType<IWidget>().TheDefaultIs(aWidget); - }); + InstanceManager manager = + new InstanceManager( + delegate(Registry registry) { registry.ForRequestedType<IWidget>().TheDefaultIs(aWidget); }); Assert.AreSame(aWidget, manager.CreateInstance<IWidget>()); } [Test] - public void Set_the_default_by_a_lambda() + public void TheDefaultInstanceIsConcreteType() { - InstanceManager manager = new InstanceManager(delegate(Registry registry) + IInstanceManager manager = new InstanceManager(delegate(Registry registry) { - registry.ForRequestedType<IWidget>().TheDefaultIs(delegate() { return new AWidget(); }); + // Needs to blow up if the concrete type can't be used + registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<ARule>(); }); - Assert.IsInstanceOfType(typeof(AWidget), manager.CreateInstance<IWidget>()); + Assert.IsInstanceOfType(typeof (ARule), manager.CreateInstance<Rule>()); } [Test] - public void Add_an_instance_by_literal() + public void TheDefaultInstanceIsPickedUpFromTheAttribute() { - AWidget aWidget = new AWidget(); + Registry registry = new Registry(); + registry.BuildInstancesOf<IGateway>(); + registry.ScanAssemblies().IncludeAssemblyContainingType<IGateway>(); - InstanceManager manager = new InstanceManager(delegate(Registry registry) - { - registry.ForRequestedType<IWidget>().AddInstance(aWidget); - }); + PluginGraph pluginGraph = registry.Build(); - Assert.IsInstanceOfType(typeof(AWidget), manager.GetAllInstances<IWidget>()[0]); - } + Assert.IsTrue(pluginGraph.ContainsFamily(typeof (IGateway))); - [Test] - public void Add_an_instance_by_lambda() - { - InstanceManager manager = new InstanceManager(delegate(Registry registry) - { - registry.ForRequestedType<IWidget>().AddInstance(delegate() { return new AWidget(); }); - }); + InstanceManager manager = new InstanceManager(pluginGraph); + IGateway gateway = (IGateway) manager.CreateInstance(typeof (IGateway)); - Assert.IsInstanceOfType(typeof(AWidget), manager.GetAllInstances<IWidget>()[0]); + Assert.IsInstanceOfType(typeof (DefaultGateway), gateway); } } public class StubbedInstanceFactoryInterceptor : IBuildInterceptor { + #region IBuildInterceptor Members + public IBuildPolicy InnerPolicy { get { throw new NotImplementedException(); } - set { } + set { } } public object Build(IBuildSession buildSession, Type pluginType, Instance instance) @@ -280,5 +263,7 @@ { throw new NotImplementedException(); } + + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs 2008-05-27 23:46:15 UTC (rev 104) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs 2008-05-28 03:15:34 UTC (rev 105) @@ -1,19 +1,18 @@ using NUnit.Framework; using StructureMap.Configuration.DSL; -using StructureMap.Configuration.DSL.Expressions; using StructureMap.Pipeline; using StructureMap.Testing.Widget; namespace StructureMap.Testing.Configuration.DSL { [TestFixture] - public class DeepInstanceTester + public class DeepInstanceTester : RegistryExpressions { - private Thing _prototype = new Thing(4, "Jeremy", .333, new WidgetRule(new ColorWidget("yellow"))); + private readonly Thing _prototype = new Thing(4, "Jeremy", .333, new WidgetRule(new ColorWidget("yellow"))); - private void assertThingMatches(Registry registry) + private void assertThingMatches(Action<Registry> action) { - IInstanceManager manager = registry.BuildInstanceManager(); + IInstanceManager manager = new InstanceManager(action); Thing actual = manager.CreateInstance<Thing>(); Assert.AreEqual(_prototype, actual); } @@ -21,129 +20,129 @@ [Test] public void DeepInstance2() { - Registry registry = new Registry(); - registry.BuildInstancesOf<IWidget>().TheDefaultIs( - Registry.Instance<IWidget>().UsingConcreteType<ColorWidget>() - .WithProperty("Color").EqualTo("yellow") - ); + assertThingMatches(delegate(Registry registry) + { + registry.BuildInstancesOf<IWidget>().TheDefaultIs( + Instance<IWidget>().UsingConcreteType<ColorWidget>() + .WithProperty("Color").EqualTo("yellow") + ); - registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<WidgetRule>(); + registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<WidgetRule>(); - registry.BuildInstancesOf<Thing>().TheDefaultIs( - Registry.Instance<Thing>() - .UsingConcreteType<Thing>() - .WithProperty("average").EqualTo(.333) - .WithProperty("name").EqualTo("Jeremy") - .WithProperty("count").EqualTo(4) - ); - - assertThingMatches(registry); + registry.BuildInstancesOf<Thing>().TheDefaultIs( + Instance<Thing>() + .UsingConcreteType<Thing>() + .WithProperty("average").EqualTo(.333) + .WithProperty("name").EqualTo("Jeremy") + .WithProperty("count").EqualTo(4) + ); + }); } [Test] public void DeepInstance3() { - Registry registry = new Registry(); - registry.BuildInstancesOf<IWidget>().TheDefaultIs( - Registry.Object<IWidget>(new ColorWidget("yellow")) - ); + assertThingMatches(delegate(Registry registry) + { + registry.BuildInstancesOf<IWidget>().TheDefaultIs( + Object<IWidget>(new ColorWidget("yellow")) + ); - registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<WidgetRule>(); + registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<WidgetRule>(); - registry.BuildInstancesOf<Thing>().TheDefaultIs( - Registry.Instance<Thing>() - .UsingConcreteType<Thing>() - .WithProperty("average").EqualTo(.333) - .WithProperty("name").EqualTo("Jeremy") - .WithProperty("count").EqualTo(4) - ); - - assertThingMatches(registry); + registry.BuildInstancesOf<Thing>().TheDefaultIs( + Instance<Thing>() + .UsingConcreteType<Thing>() + .WithProperty("average").EqualTo(.333) + .WithProperty("name").EqualTo("Jeremy") + .WithProperty("count").EqualTo(4) + ); + }); } [Test] public void DeepInstance4() { - Registry registry = new Registry(); - registry.BuildInstancesOf<IWidget>().TheDefaultIs( - Registry.Prototype<IWidget>(new ColorWidget("yellow")) - ); + assertThingMatches(delegate(Registry registry) + { + registry.BuildInstancesOf<IWidget>().TheDefaultIs( + Prototype<IWidget>(new ColorWidget("yellow")) + ); - registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<WidgetRule>(); + registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<WidgetRule>(); - registry.BuildInstancesOf<Thing>().TheDefaultIs( - Registry.Instance<Thing>() - .UsingConcreteType<Thing>() - .WithProperty("average").EqualTo(.333) - .WithProperty("name").EqualTo("Jeremy") - .WithProperty("count").EqualTo(4) - ); - - assertThingMatches(registry); + registry.BuildInstancesOf<Thing>().TheDefaultIs( + Instance<Thing>() + .UsingConcreteType<Thing>() + .WithProperty("average").EqualTo(.333) + .WithProperty("name").EqualTo("Jeremy") + .WithProperty("count").EqualTo(4) + ); + }); } [Test] public void DeepInstance5() { - Registry registry = new Registry(); + assertThingMatches(delegate(Registry registry) + { + registry.AddInstanceOf<IWidget>() + .UsingConcreteType<ColorWidget>() + .WithName("Yellow") + .WithProperty("Color").EqualTo("yellow"); - registry.AddInstanceOf<IWidget>() - .UsingConcreteType<ColorWidget>() - .WithName("Yellow") - .WithProperty("Color").EqualTo("yellow"); + registry.AddInstanceOf<Rule>() + .UsingConcreteType<WidgetRule>() + .WithName("TheWidgetRule") + .Child<IWidget>().IsNamedInstance("Yellow"); - registry.AddInstanceOf<Rule>() - .UsingConcreteType<WidgetRule>() - .WithName("TheWidgetRule") - .Child<IWidget>().IsNamedInstance("Yellow"); - - registry.BuildInstancesOf<Thing>().TheDefaultIs( - Registry.Instance<Thing>() - .UsingConcreteType<Thing>() - .WithProperty("average").EqualTo(.333) - .WithProperty("name").EqualTo("Jeremy") - .WithProperty("count").EqualTo(4) - .Child<Rule>().IsNamedInstance("TheWidgetRule") - ); - - assertThingMatches(registry); + registry.BuildInstancesOf<Thing>().TheDefaultIs( + Instance<Thing>() + .UsingConcreteType<Thing>() + .WithProperty("average").EqualTo(.333) + .WithProperty("name").EqualTo("Jeremy") + .WithProperty("count").EqualTo(4) + .Child<Rule>().IsNamedInstance("TheWidgetRule") + ); + }); } [Test] public void DeepInstanceTest1() { - Registry registry = new Registry(); - ConfiguredInstance widgetExpression = Registry.Instance<IWidget>() + ConfiguredInstance widgetExpression = Instance<IWidget>() .UsingConcreteType<ColorWidget>() .WithProperty("Color").EqualTo("yellow"); - ConfiguredInstance ruleExpression = Registry.Instance<Rule>() + ConfiguredInstance ruleExpression = Instance<Rule>() .UsingConcreteType<WidgetRule>() .Child<IWidget>().Is(widgetExpression); - registry.BuildInstancesOf<Thing>().TheDefaultIs( - Registry.Instance<Thing>() - .UsingConcreteType<Thing>() - .WithProperty("name").EqualTo("Jeremy") - .WithProperty("count").EqualTo(4) - .WithProperty("average").EqualTo(.333) - .Child<Rule>().Is( - ruleExpression - ) - ); - assertThingMatches(registry); + assertThingMatches(delegate(Registry registry) + { + registry.BuildInstancesOf<Thing>().TheDefaultIs( + Instance<Thing>() + .UsingConcreteType<Thing>() + .WithProperty("name").EqualTo("Jeremy") + .WithProperty("count").EqualTo(4) + .WithProperty("average").EqualTo(.333) + .Child<Rule>().Is( + ruleExpression + ) + ); + }); } } public class Thing { - private double _average; - private int _count; - private string _name; - private Rule _rule; + private readonly double _average; + private readonly int _count; + private readonly string _name; + private readonly Rule _rule; public Thing(int count, string name, double average, Rule rule) Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs 2008-05-27 23:46:15 UTC (rev 104) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs 2008-05-28 03:15:34 UTC (rev 105) @@ -4,7 +4,7 @@ namespace StructureMap.Testing.Configuration.DSL { [TestFixture] - public class InjectArrayTester + public class InjectArrayTester : RegistryExpressions { #region Setup/Teardown @@ -41,8 +41,8 @@ public class Processor2 { - private IHandler[] _first; - private IHandler[] _second; + private readonly IHandler[] _first; + private readonly IHandler[] _second; public Processor2(IHandler[] first, IHandler[] second) @@ -82,44 +82,44 @@ [Test] public void CanStillAddOtherPropertiesAfterTheCallToChildArray() { - Registry registry = new Registry(); + IInstanceManager manager = new InstanceManager(delegate(Registry registry) + { + registry.ForRequestedType<Processor>() + .TheDefaultIs( + Instance<Processor>().UsingConcreteType<Processor>() + .ChildArray<IHandler[]>().Contains( + Instance<IHandler>().UsingConcreteType<Handler1>(), + Instance<IHandler>().UsingConcreteType<Handler2>(), + Instance<IHandler>().UsingConcreteType<Handler3>() + ) + .WithProperty("name").EqualTo("Jeremy") + ); + }); - registry.ForRequestedType<Processor>() - .TheDefaultIs( - Registry.Instance<Processor>().UsingConcreteType<Processor>() - .ChildArray<IHandler[]>().Contains( - Registry.Instance<IHandler>().UsingConcreteType<Handler1>(), - Registry.Instance<IHandler>().UsingConcreteType<Handler2>(), - Registry.Instance<IHandler>().UsingConcreteType<Handler3>() - ) - .WithProperty("name").EqualTo("Jeremy") - ); - - IInstanceManager manager = registry.BuildInstanceManager(); Processor processor = manager.CreateInstance<Processor>(); - Assert.AreEqual("Jeremy", processor.Name); } [Test] public void InjectPropertiesByName() { - Registry registry = new Registry(); + IInstanceManager manager = new InstanceManager(delegate(Registry registry) + { + registry.ForRequestedType<Processor2>() + .TheDefaultIs( + Instance<Processor2>().UsingConcreteType<Processor2>() + .ChildArray<IHandler[]>("first").Contains( + Instance<IHandler>().UsingConcreteType<Handler1>(), + Instance<IHandler>().UsingConcreteType<Handler2>() + ) + .ChildArray<IHandler[]>("second").Contains( + Instance<IHandler>().UsingConcreteType<Handler2>(), + Instance<IHandler>().UsingConcreteType<Handler3>() + ) + ); + }); - registry.ForRequestedType<Processor2>() - .TheDefaultIs( - Registry.Instance<Processor2>().UsingConcreteType<Processor2>() - .ChildArray<IHandler[]>("first").Contains( - Registry.Instance<IHandler>().UsingConcreteType<Handler1>(), - Registry.Instance<IHandler>().UsingConcreteType<Handler2>() - ) - .ChildArray<IHandler[]>("second").Contains( - Registry.Instance<IHandler>().UsingConcreteType<Handler2>(), - Registry.Instance<IHandler>().UsingConcreteType<Handler3>() - ) - ); - IInstanceManager manager = registry.BuildInstanceManager(); Processor2 processor = manager.CreateInstance<Processor2>(); Assert.IsInstanceOfType(typeof (Handler1), processor.First[0]); @@ -131,21 +131,21 @@ [Test, ExpectedException(typeof (StructureMapException), ExpectedMessage = - "StructureMap Exception Code: 307\nIn the call to ChildArray<T>(), the type T must be an array")] + "StructureMap Exception Code: 307\nIn the call to ChildArray<T>(), the type T must be an array")] public void InjectPropertiesByNameButUseTheElementType() { Registry registry = new Registry(); registry.ForRequestedType<Processor2>() .TheDefaultIs( - Registry.Instance<Processor2>().UsingConcreteType<Processor2>() + Instance<Processor2>().UsingConcreteType<Processor2>() .ChildArray<IHandler>("first").Contains( - Registry.Instance<IHandler>().UsingConcreteType<Handler1>(), - Registry.Instance<IHandler>().UsingConcreteType<Handler2>() + Instance<IHandler>().UsingConcreteType<Handler1>(), + Instance<IHandler>().UsingConcreteType<Handler2>() ) .ChildArray<IHandler[]>("second").Contains( - Registry.Instance<IHandler>().UsingConcreteType<Handler2>(), - Registry.Instance<IHandler>().UsingConcreteType<Handler3>() + Instance<IHandler>().UsingConcreteType<Handler2>(), + Instance<IHandler>().UsingConcreteType<Handler3>() ) ); } @@ -153,21 +153,22 @@ [Test] public void PlaceMemberInArrayByReference() { - Registry registry = new Registry(); - registry.AddInstanceOf<IHandler>().UsingConcreteType<Handler1>().WithName("One"); - registry.AddInstanceOf<IHandler>().UsingConcreteType<Handler2>().WithName("Two"); + IInstanceManager manager = new InstanceManager(delegate(Registry registry) + { + registry.AddInstanceOf<IHandler>().UsingConcreteType<Handler1>().WithName("One"); + registry.AddInstanceOf<IHandler>().UsingConcreteType<Handler2>().WithName("Two"); - registry.ForRequestedType<Processor>() - .TheDefaultIs( - Registry.Instance<Processor>().UsingConcreteType<Processor>() - .WithProperty("name").EqualTo("Jeremy") - .ChildArray<IHandler[]>().Contains( - Registry.Instance("Two"), - Registry.Instance("One") - ) - ); + registry.ForRequestedType<Processor>() + .TheDefaultIs( + Instance<Processor>().UsingConcreteType<Processor>() + .WithProperty("name").EqualTo("Jeremy") + .ChildArray<IHandler[]>().Contains( + Instance("Two"), + Instance("One") + ) + ); + }); - IInstanceManager manager = registry.BuildInstanceManager(); Processor processor = manager.CreateInstance<Processor>(); Assert.IsInstanceOfType(typeof (Handler2), processor.Handlers[0]); @@ -177,20 +178,20 @@ [Test] public void ProgrammaticallyInjectArrayAllInline() { - Registry registry = new Registry(); + IInstanceManager manager = new InstanceManager(delegate(Registry registry) + { + registry.ForRequestedType<Processor>() + .TheDefaultIs( + Instance<Processor>() + .ChildArray<IHandler[]>().Contains( + Instance<IHandler>().UsingConcreteType<Handler1>(), + Instance<IHandler>().UsingConcreteType<Handler2>(), + Instance<IHandler>().UsingConcreteType<Handler3>() + ) + .WithProperty("name").EqualTo("Jeremy") + ); + }); - registry.ForRequestedType<Processor>() - .TheDefaultIs( - Registry.Instance<Processor>().UsingConcreteType<Processor>() - .ChildArray<IHandler[]>().Contains( - Registry.Instance<IHandler>().UsingConcreteType<Handler1>(), - Registry.Instance<IHandler>().UsingConcreteType<Handler2>(), - Registry.Instance<IHandler>().UsingConcreteType<Handler3>() - ) - .WithProperty("name").EqualTo("Jeremy") - ); - - IInstanceManager manager = registry.BuildInstanceManager(); Processor processor = manager.CreateInstance<Processor>(); Assert.IsInstanceOfType(typeof (Handler1), processor.Handlers[0]); @@ -201,17 +202,17 @@ [Test, ExpectedException(typeof (StructureMapException), ... [truncated message content] |
From: <jer...@us...> - 2008-05-27 23:46:17
|
Revision: 104 http://structuremap.svn.sourceforge.net/structuremap/?rev=104&view=rev Author: jeremydmiller Date: 2008-05-27 16:46:15 -0700 (Tue, 27 May 2008) Log Message: ----------- Killing off the TODO's in the code, lots of defensive programming Modified Paths: -------------- trunk/Source/StructureMap/Configuration/FamilyParser.cs trunk/Source/StructureMap/Configuration/GraphBuilder.cs trunk/Source/StructureMap/Configuration/ProfileBuilder.cs trunk/Source/StructureMap/Diagnostics/Error.cs trunk/Source/StructureMap/Diagnostics/GraphLog.cs trunk/Source/StructureMap/Exceptions/StructureMapException.cs trunk/Source/StructureMap/Graph/Plugin.cs trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs trunk/Source/StructureMap/Pipeline/ProfileManager.cs trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap/StructureMapException.resx trunk/Source/StructureMap.Testing/Configuration/ProfileBuilderTester.cs trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing/TestData/AttributeNormalized.xml trunk/Source/StructureMap.Testing/TestData/PluggedTypeTest.xml Added Paths: ----------- trunk/Source/StructureMap/ErrorMessages.cs trunk/Source/StructureMap.Testing/Pipeline/ConstructorInstanceTester.cs Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-27 22:12:33 UTC (rev 103) +++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-27 23:46:15 UTC (rev 104) @@ -75,7 +75,6 @@ return returnValue; } - // TODO: change to many private void attachMementoSource(PluginFamily family, XmlElement familyElement) { XmlNode sourceNode = familyElement[XmlConstants.MEMENTO_SOURCE_NODE]; Modified: trunk/Source/StructureMap/Configuration/GraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-05-27 22:12:33 UTC (rev 103) +++ trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-05-27 23:46:15 UTC (rev 104) @@ -99,22 +99,9 @@ } } - public void WithType(TypePath path, string context, Action<Type> action) { - try - { - Type type = path.FindType(); - action(type); - } - catch (StructureMapException ex) - { - _pluginGraph.Log.RegisterError(ex); - } - catch (Exception ex) - { - _pluginGraph.Log.RegisterError(131, ex, path.AssemblyQualifiedName, context); - } + _pluginGraph.Log.WithType(path, context, action); } #endregion Modified: trunk/Source/StructureMap/Configuration/ProfileBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ProfileBuilder.cs 2008-05-27 22:12:33 UTC (rev 103) +++ trunk/Source/StructureMap/Configuration/ProfileBuilder.cs 2008-05-27 23:46:15 UTC (rev 104) @@ -47,12 +47,11 @@ public void OverrideProfile(TypePath typePath, string instanceKey) { - _pluginGraph.Log.Try(delegate() + _pluginGraph.Log.WithType(typePath, "while trying to add an override for a Profile", delegate(Type pluginType) { ReferencedInstance instance = new ReferencedInstance(instanceKey); - _pluginGraph.SetDefault(_lastProfile, typePath.FindType(), instance); - - }).AndReportErrorAs(107, typePath.AssemblyQualifiedName); + _pluginGraph.SetDefault(_lastProfile, pluginType, instance); + }); } public void AddMachine(string machineName, string profileName) @@ -72,9 +71,13 @@ return; } - // TODO: what if the Type cannot be found? - ReferencedInstance instance = new ReferencedInstance(instanceKey); - _profileManager.SetMachineDefault(typePath.FindType(), instance); + _pluginGraph.Log.WithType(typePath, + "trying to configure a Machine Override", + delegate(Type pluginType) + { + ReferencedInstance instance = new ReferencedInstance(instanceKey); + _profileManager.SetMachineDefault(pluginType, instance); + }); } public void SetDefaultProfileName(string profileName) Modified: trunk/Source/StructureMap/Diagnostics/Error.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/Error.cs 2008-05-27 22:12:33 UTC (rev 103) +++ trunk/Source/StructureMap/Diagnostics/Error.cs 2008-05-27 23:46:15 UTC (rev 104) @@ -22,10 +22,7 @@ public Error(int errorCode, params object[] args) { _code = errorCode; - string template = getMessage(errorCode); - if (template == null) template = string.Empty; - - _message = string.Format(template, args); + _message = ErrorMessages.GetMessage(errorCode, args); } public Error(int errorCode, Exception ex, params object[] args) : this(errorCode, args) @@ -62,11 +59,6 @@ #endregion - private static string getMessage(int errorCode) - { - ResourceManager resources = new ResourceManager(typeof (StructureMapException)); - return resources.GetString(errorCode.ToString()); - } public override bool Equals(object obj) { Modified: trunk/Source/StructureMap/Diagnostics/GraphLog.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/GraphLog.cs 2008-05-27 22:12:33 UTC (rev 103) +++ trunk/Source/StructureMap/Diagnostics/GraphLog.cs 2008-05-27 23:46:15 UTC (rev 104) @@ -127,6 +127,23 @@ } } + public void WithType(TypePath path, string context, Action<Type> action) + { + try + { + Type type = path.FindType(); + action(type); + } + catch (StructureMapException ex) + { + RegisterError(ex); + } + catch (Exception ex) + { + RegisterError(131, ex, path.AssemblyQualifiedName, context); + } + } + public TryAction Try(Action action) { return new TryAction(action, this); Added: trunk/Source/StructureMap/ErrorMessages.cs =================================================================== --- trunk/Source/StructureMap/ErrorMessages.cs (rev 0) +++ trunk/Source/StructureMap/ErrorMessages.cs 2008-05-27 23:46:15 UTC (rev 104) @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Resources; +using System.Text; + +namespace StructureMap +{ + internal static class ErrorMessages + { + public static string GetMessage(int errorCode, params object[] args) + { + string msg = "StructureMap Exception Code: " + errorCode + "\n"; + + for (int i = 0; i < args.Length; i++) + { + object arg = args[i]; + Type type = arg as Type; + if (type != null) + { + args[i] = type.AssemblyQualifiedName; + } + } + + string errorMsg = getMessage(errorCode); + if (errorMsg == null) + { + errorMsg = string.Empty; + } + + return string.Format(errorMsg, args); + } + + private static string getMessage(int errorCode) + { + ResourceManager resources = new ResourceManager(typeof(StructureMapException)); + return resources.GetString(errorCode.ToString()); + } + } +} Modified: trunk/Source/StructureMap/Exceptions/StructureMapException.cs =================================================================== --- trunk/Source/StructureMap/Exceptions/StructureMapException.cs 2008-05-27 22:12:33 UTC (rev 103) +++ trunk/Source/StructureMap/Exceptions/StructureMapException.cs 2008-05-27 23:46:15 UTC (rev 104) @@ -25,13 +25,17 @@ public StructureMapException(int ErrorCode, params object[] args) : base() { - initialize(ErrorCode, args); + _errorCode = ErrorCode; + _msg = string.Format("StructureMap Exception Code: {0}\n", _errorCode); + _msg += ErrorMessages.GetMessage(ErrorCode, args); } public StructureMapException(int ErrorCode, Exception InnerException, params object[] args) : base(string.Empty, InnerException) { - initialize(ErrorCode, args); + _errorCode = ErrorCode; + _msg = string.Format("StructureMap Exception Code: {0}\n", _errorCode); + _msg += ErrorMessages.GetMessage(ErrorCode, args); } public override string Message @@ -44,38 +48,8 @@ get { return _errorCode; } } - // TODO: Centralize this code somewhere so it isn't duplicated - private void initialize(int errorCode, params object[] args) - { - _errorCode = errorCode; - _msg = "StructureMap Exception Code: " + _errorCode + "\n"; - for (int i = 0; i < args.Length; i++) - { - object arg = args[i]; - Type type = arg as Type; - if (type != null) - { - args[i] = type.AssemblyQualifiedName; - } - } - string errorMsg = getMessage(ErrorCode); - if (errorMsg == null) - { - errorMsg = string.Empty; - } - - _msg += string.Format(errorMsg, args); - } - - private string getMessage(int errorCode) - { - ResourceManager resources = new ResourceManager(GetType()); - - return resources.GetString(errorCode.ToString()); - } - public override void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("errorCode", _errorCode, typeof (int)); Modified: trunk/Source/StructureMap/Graph/Plugin.cs =================================================================== --- trunk/Source/StructureMap/Graph/Plugin.cs 2008-05-27 22:12:33 UTC (rev 103) +++ trunk/Source/StructureMap/Graph/Plugin.cs 2008-05-27 23:46:15 UTC (rev 104) @@ -24,7 +24,6 @@ { if (concreteKey == string.Empty) { - // TODO: Move into PluginFamily and get the exception logged somewhere throw new StructureMapException(112, pluggedType.FullName); } Modified: trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs 2008-05-27 22:12:33 UTC (rev 103) +++ trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs 2008-05-27 23:46:15 UTC (rev 104) @@ -26,8 +26,14 @@ protected override object build(Type pluginType, IBuildSession session) { - // TODO: specific error message - return _builder(); + try + { + return _builder(); + } + catch (Exception ex) + { + throw new StructureMapException(207, ex, Name, pluginType); + } } protected override string getDescription() Modified: trunk/Source/StructureMap/Pipeline/ProfileManager.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2008-05-27 22:12:33 UTC (rev 103) +++ trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2008-05-27 23:46:15 UTC (rev 104) @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using StructureMap.Diagnostics; using StructureMap.Graph; namespace StructureMap.Pipeline @@ -36,21 +37,29 @@ get { return _currentProfile.Name; } set { - // TODO: Profile cannot be found - if (string.IsNullOrEmpty(value)) { _currentProfile = _default; } else { + validateHasProfile(value); + _currentProfile = getProfile(value); _default.FillAllTypesInto(_currentProfile); } } } + private void validateHasProfile(string profileName) + { + if (!_profiles.ContainsKey(profileName)) + { + throw new StructureMapException(280, profileName); + } + } + public Instance GetDefault(Type pluginType, string profileName) { Profile profile = getProfile(profileName); @@ -98,7 +107,7 @@ { findMasterInstances(graph); - setProfileDefaults(); + setProfileDefaults(graph.Log); processMachineDefaults(graph); @@ -117,14 +126,18 @@ } } - private void setProfileDefaults() + private void setProfileDefaults(GraphLog log) { if (string.IsNullOrEmpty(_defaultProfileName)) { return; } - // TODO: What if Profile doesn't exist? + if (!_profiles.ContainsKey(_defaultProfileName)) + { + log.RegisterError(280, _defaultProfileName); + } + Profile profile = getProfile(_defaultProfileName); profile.FillAllTypesInto(_default); } @@ -152,7 +165,10 @@ if (!string.IsNullOrEmpty(_defaultMachineProfileName)) { - // TODO: Machine profile name cannot be found + if (!_profiles.ContainsKey(_defaultMachineProfileName)) + { + graph.Log.RegisterError(280, _defaultMachineProfileName); + } Profile profile = getProfile(_defaultMachineProfileName); profile.FillAllTypesInto(_default); } Modified: trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs 2008-05-27 22:12:33 UTC (rev 103) +++ trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs 2008-05-27 23:46:15 UTC (rev 104) @@ -5,7 +5,7 @@ { public class PrototypeInstance : ExpressedInstance<PrototypeInstance> { - private ICloneable _prototype; + private readonly ICloneable _prototype; public PrototypeInstance(ICloneable prototype) @@ -21,7 +21,6 @@ protected override object build(Type pluginType, IBuildSession session) { - // TODO: VALIDATION IF IT CAN'T BE CAST return _prototype.Clone(); } Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-05-27 22:12:33 UTC (rev 103) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-05-27 23:46:15 UTC (rev 104) @@ -373,6 +373,7 @@ <None Include="..\structuremap.snk"> <Link>Properties\structuremap.snk</Link> </None> + <Compile Include="ErrorMessages.cs" /> <Compile Include="Pipeline\ConfiguredInstance.Building.cs" /> <Compile Include="Pipeline\IStructuredInstance.cs" /> </ItemGroup> Modified: trunk/Source/StructureMap/StructureMapException.resx =================================================================== --- trunk/Source/StructureMap/StructureMapException.resx 2008-05-27 22:12:33 UTC (rev 103) +++ trunk/Source/StructureMap/StructureMapException.resx 2008-05-27 23:46:15 UTC (rev 104) @@ -161,7 +161,7 @@ <value>Invalid property value(s), InstanceKey "{0}"</value> </data> <data name="207" xml:space="preserve"> - <value>Internal exception in the constructor function of the targeted concrete type. InstanceKey "{0}", PluginFamily {1}</value> + <value>Internal exception while creating Instance '{0}' of PluginType {1}. Check the inner exception for more details.</value> </data> <data name="104" xml:space="preserve"> <value>Type {0} cannot be plugged into type {1}</value> @@ -259,4 +259,7 @@ <data name="210" xml:space="preserve"> <value>The designated default instance '{0}' for PluginType {1} cannot be found</value> </data> + <data name="280" xml:space="preserve"> + <value>Requested Profile {0} cannot be found</value> + </data> </root> \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/ProfileBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/ProfileBuilderTester.cs 2008-05-27 22:12:33 UTC (rev 103) +++ trunk/Source/StructureMap.Testing/Configuration/ProfileBuilderTester.cs 2008-05-27 23:46:15 UTC (rev 104) @@ -63,8 +63,31 @@ Assert.AreEqual(instance, _graph.ProfileManager.GetMachineDefault(this.GetType())); } + [Test] + public void Log_131_if_trying_to_register_override_for_a_machine_when_the_PluginType_cannot_be_found() + { + _builder.AddMachine(THE_MACHINE_NAME, "TheProfile"); + + _graph.Log.AssertHasNoError(131); + + _builder.OverrideMachine(new TypePath("not a real type"), "Purple"); + _graph.Log.AssertHasError(131); + } + [Test] + public void Log_131_if_trying_to_register_override_for_a_profile_when_the_PluginType_cannot_be_found() + { + _builder.AddProfile("TheProfile"); + + _graph.Log.AssertHasNoError(131); + + _builder.OverrideProfile(new TypePath("not a real type"), "Purple"); + + _graph.Log.AssertHasError(131); + } + + [Test] public void Do_not_register_a_machine_override_if_it_is_NOT_the_matching_machine() { _builder.AddMachine("Some other machine", "TheProfile"); @@ -73,7 +96,24 @@ Assert.IsNull(_graph.ProfileManager.GetMachineDefault(this.GetType())); } + [Test] + public void Throw_280_if_requesting_an_invalid_profile() + { + try + { + ProfileManager manager = new ProfileManager(); + manager.CurrentProfile = "some profile that does not exist"; + + Assert.Fail("Should have thrown error"); + } + catch (StructureMapException ex) + { + Assert.AreEqual(280, ex.ErrorCode); + } + } + + [Test] public void SetDefaultProfileName() { string theProfileName = "some profile name"; @@ -82,17 +122,6 @@ Assert.AreEqual(theProfileName, _graph.ProfileManager.DefaultProfileName); } - [Test] - public void Override_profile_with_a_bad_TypePath_should_log_107() - { - PluginGraph graph = new PluginGraph(); - ProfileBuilder builder = new ProfileBuilder(graph); - - builder.AddProfile("something"); - builder.OverrideProfile(new TypePath("a type that does not exist"), "key"); - - graph.Log.AssertHasError(107); - } } } \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Pipeline/ConstructorInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/ConstructorInstanceTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Pipeline/ConstructorInstanceTester.cs 2008-05-27 23:46:15 UTC (rev 104) @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Text; +using NUnit.Framework; +using StructureMap.Pipeline; +using StructureMap.Testing.Widget; + +namespace StructureMap.Testing.Pipeline +{ + [TestFixture] + public class ConstructorInstanceTester + { + [Test] + public void Sad_path_inner_function_throws_exception_207_with_key_and_plugin_type() + { + ConstructorInstance instance = new ConstructorInstance(delegate() + { + throw new NotImplementedException(); + }); + + try + { + instance.Build(typeof (IWidget), null); + Assert.Fail("Should have thrown an exception"); + } + catch (StructureMapException ex) + { + Assert.AreEqual(207, ex.ErrorCode); + } + } + } +} Modified: trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerTester.cs 2008-05-27 22:12:33 UTC (rev 103) +++ trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerTester.cs 2008-05-27 23:46:15 UTC (rev 104) @@ -243,5 +243,30 @@ Assert.AreSame(_manager.GetDefault(typeof(IBuildPolicy), "Profile"), _manager.GetDefault(typeof(ISomething), "Profile")); Assert.AreSame(_manager.GetDefault(typeof(IBuildPolicy), "Profile2"), _manager.GetDefault(typeof(ISomething), "Profile2")); } + + [Test] + public void Log_280_if_the_default_profile_does_not_exist_upon_call_to_Seal() + { + ProfileManager manager = new ProfileManager(); + manager.DefaultProfileName = "something that doesn't exist"; + + PluginGraph graph = new PluginGraph(); + manager.Seal(graph); + + graph.Log.AssertHasError(280); + + } + + [Test] + public void Log_280_if_the_machine_default_profile_cannot_be_found() + { + ProfileManager manager = new ProfileManager(); + manager.DefaultMachineProfileName = "something that doesn't exist"; + + PluginGraph graph = new PluginGraph(); + manager.Seal(graph); + + graph.Log.AssertHasError(280); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-27 22:12:33 UTC (rev 103) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-27 23:46:15 UTC (rev 104) @@ -326,6 +326,7 @@ <Compile Include="PipelineGraphTester.cs" /> <Compile Include="Pipeline\BuildStrategiesTester.cs" /> <Compile Include="Pipeline\ConfiguredInstanceTester.cs" /> + <Compile Include="Pipeline\ConstructorInstanceTester.cs" /> <Compile Include="Pipeline\DefaultInstanceTester.cs" /> <Compile Include="Pipeline\InstanceTester.cs" /> <Compile Include="Pipeline\LiteralInstanceTester.cs" /> Modified: trunk/Source/StructureMap.Testing/TestData/AttributeNormalized.xml =================================================================== --- trunk/Source/StructureMap.Testing/TestData/AttributeNormalized.xml 2008-05-27 22:12:33 UTC (rev 103) +++ trunk/Source/StructureMap.Testing/TestData/AttributeNormalized.xml 2008-05-27 23:46:15 UTC (rev 104) @@ -1,5 +1,5 @@ <!--<?xml version="1.0" encoding="utf-8" ?>--> -<StructureMap DefaultProfile="TheDefaultProfile" MementoStyle="Attribute"> +<StructureMap MementoStyle="Attribute"> <Assembly Name="StructureMap.Testing.Widget"/> <Assembly Name="StructureMap.Testing.Widget2"/> <Assembly Name="StructureMap.Testing.Widget3"/> Modified: trunk/Source/StructureMap.Testing/TestData/PluggedTypeTest.xml =================================================================== --- trunk/Source/StructureMap.Testing/TestData/PluggedTypeTest.xml 2008-05-27 22:12:33 UTC (rev 103) +++ trunk/Source/StructureMap.Testing/TestData/PluggedTypeTest.xml 2008-05-27 23:46:15 UTC (rev 104) @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8" ?> -<StructureMap DefaultProfile="TheDefaultProfile" MementoStyle="Attribute"> +<StructureMap MementoStyle="Attribute"> <PluginFamily Type="StructureMap.Testing.Widget.IWidget" Assembly="StructureMap.Testing.Widget"> <Instance Key="Me" PluggedType="StructureMap.Testing.Widget.NotPluggableWidget,StructureMap.Testing.Widget" name="Jeremy"/> </PluginFamily> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-05-27 22:12:36
|
Revision: 103 http://structuremap.svn.sourceforge.net/structuremap/?rev=103&view=rev Author: jeremydmiller Date: 2008-05-27 15:12:33 -0700 (Tue, 27 May 2008) Log Message: ----------- little refactoring of ProfileManager and PluginFamily to move misplaced code Modified Paths: -------------- trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/Pipeline/ProfileManager.cs trunk/Source/StructureMap/StructureMapException.resx trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-27 17:50:51 UTC (rev 102) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-27 22:12:33 UTC (rev 103) @@ -297,5 +297,21 @@ AddInstance(memento); DefaultInstanceKey = memento.InstanceKey; } + + public void FillDefault(Profile profile) + { + if (string.IsNullOrEmpty(DefaultInstanceKey)) + { + return; + } + + Instance defaultInstance = GetInstance(DefaultInstanceKey); + if (defaultInstance == null) + { + Parent.Log.RegisterError(210, DefaultInstanceKey, PluginType); + } + + profile.FillTypeInto(PluginType, defaultInstance); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ProfileManager.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2008-05-27 17:50:51 UTC (rev 102) +++ trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2008-05-27 22:12:33 UTC (rev 103) @@ -133,7 +133,7 @@ { foreach (PluginFamily family in graph.PluginFamilies) { - findDefaultFromPluginFamily(family); + family.FillDefault(_default); } } @@ -158,19 +158,6 @@ } } - private void findDefaultFromPluginFamily(PluginFamily family) - { - // TODO: Sad path here if the default instance key cannot be found - // TODO: Pull inside of PluginFamily itself - if (string.IsNullOrEmpty(family.DefaultInstanceKey)) - { - return; - } - - Instance defaultInstance = family.GetInstance(family.DefaultInstanceKey); - _default.FillTypeInto(family.PluginType, defaultInstance); - } - public void CopyDefaults(Type basicType, Type templatedType) { _default.CopyDefault(basicType, templatedType); Modified: trunk/Source/StructureMap/StructureMapException.resx =================================================================== --- trunk/Source/StructureMap/StructureMapException.resx 2008-05-27 17:50:51 UTC (rev 102) +++ trunk/Source/StructureMap/StructureMapException.resx 2008-05-27 22:12:33 UTC (rev 103) @@ -256,4 +256,7 @@ <data name="270" xml:space="preserve"> <value>Instance specific interception failed for {0} of PluginType {1}</value> </data> + <data name="210" xml:space="preserve"> + <value>The designated default instance '{0}' for PluginType {1} cannot be found</value> + </data> </root> \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-05-27 17:50:51 UTC (rev 102) +++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-05-27 22:12:33 UTC (rev 103) @@ -112,6 +112,32 @@ } [Test] + public void FillDefault_happy_path() + { + PluginFamily family = new PluginFamily(typeof (IWidget)); + family.Parent = new PluginGraph(); + family.AddInstance(new ConfiguredInstance().WithName("Default")); + family.DefaultInstanceKey = "Default"; + + + family.FillDefault(new Profile("theProfile")); + + family.Parent.Log.AssertHasNoError(210); + } + + [Test] + public void FillDefault_sad_path_when_the_default_instance_key_does_not_exist_throws_210() + { + PluginFamily family = new PluginFamily(typeof (IWidget)); + family.Parent = new PluginGraph(); + + family.DefaultInstanceKey = "something that cannot be found"; + family.FillDefault(new Profile("theProfile")); + + family.Parent.Log.AssertHasError(210); + } + + [Test] public void If_PluginFamily_only_has_one_instance_make_that_the_default() { PluginFamily family = new PluginFamily(typeof (IGateway)); @@ -259,7 +285,7 @@ [Pluggable("Default")] public class SingletonRepositoryWithAttribute : ISingletonRepository { - private Guid _id = Guid.NewGuid(); + private readonly Guid _id = Guid.NewGuid(); public Guid Id { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-05-27 17:50:53
|
Revision: 102 http://structuremap.svn.sourceforge.net/structuremap/?rev=102&view=rev Author: jeremydmiller Date: 2008-05-27 10:50:51 -0700 (Tue, 27 May 2008) Log Message: ----------- killing off TODO's Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/RegistryExpressions.cs trunk/Source/StructureMap/Configuration/FamilyParser.cs trunk/Source/StructureMap/Configuration/GraphBuilder.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs trunk/Source/StructureMap/InstanceManager.cs trunk/Source/StructureMap/Pipeline/BuildPolicy.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs trunk/Source/StructureMap/Pipeline/Instance.cs trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap/StructureMapException.resx trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs trunk/Source/StructureMap.Testing/Graph/PluginTester.cs trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs trunk/Source/StructureMap.Testing.Widget/Rule.cs trunk/Source/StructureMap.Testing.Widget5/OtherGridColumn.cs Added Paths: ----------- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Building.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs trunk/Source/StructureMap/Pipeline/IStructuredInstance.cs Modified: trunk/Source/StructureMap/Configuration/DSL/RegistryExpressions.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/RegistryExpressions.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap/Configuration/DSL/RegistryExpressions.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -12,8 +12,7 @@ /// <returns></returns> public static ConfiguredInstance Instance<PLUGGEDTYPE>() { - ConfiguredInstance instance = new ConfiguredInstance(); - instance.PluggedType = typeof (PLUGGEDTYPE); + ConfiguredInstance instance = new ConfiguredInstance(typeof (PLUGGEDTYPE)); return instance; } Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -42,24 +42,11 @@ _builder.ConfigureFamily(pluginTypePath, delegate(PluginFamily family) { - // TODO: there's a little duplication here InstanceScope scope = findScope(element); family.SetScopeTo(scope); - Type pluginType = family.PluginType; - - string name = element.GetAttribute(XmlConstants.NAME); - if (string.IsNullOrEmpty(name)) - { - name = "DefaultInstanceOf" + pluginTypePath.AssemblyQualifiedName; - } - InstanceMemento memento = _mementoCreator.CreateMemento(element); - memento.InstanceKey = name; - - family.DefaultInstanceKey = name; - - family.AddInstance(memento); + family.AddDefaultMemento(memento); }); } Modified: trunk/Source/StructureMap/Configuration/GraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -63,7 +63,6 @@ public void PrepareSystemObjects() { - // TODO: is this a problem here? _systemGraph.Seal(); } Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -286,5 +286,16 @@ return plugin; } } + + public void AddDefaultMemento(InstanceMemento memento) + { + if (string.IsNullOrEmpty(memento.InstanceKey)) + { + memento.InstanceKey = "DefaultInstanceOf" + TypePath.GetAssemblyQualifiedName(PluginType); + } + + AddInstance(memento); + DefaultInstanceKey = memento.InstanceKey; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs =================================================================== --- trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -68,13 +68,11 @@ { if (property == null) { - // TODO -- log this throw new StructureMapException(240, propertyName, _plugin.PluggedType); } if (property.GetSetMethod() == null) { - // TODO -- log this throw new StructureMapException(241, propertyName, _plugin.PluggedType); } Modified: trunk/Source/StructureMap/InstanceManager.cs =================================================================== --- trunk/Source/StructureMap/InstanceManager.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap/InstanceManager.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -96,8 +96,7 @@ public void InjectByName<PLUGINTYPE, CONCRETETYPE>(string instanceKey) { - ConfiguredInstance instance = new ConfiguredInstance(); - instance.PluggedType = typeof(CONCRETETYPE); + ConfiguredInstance instance = new ConfiguredInstance(typeof(CONCRETETYPE)); instance.Name = instanceKey; AddInstance<PLUGINTYPE>(instance); @@ -207,7 +206,6 @@ throw new StructureMapException(230, type.FullName); } - // TODO: Little bit of smelliness here Plugin plugin = new Plugin(type); if (!plugin.CanBeAutoFilled) { Modified: trunk/Source/StructureMap/Pipeline/BuildPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/BuildPolicy.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap/Pipeline/BuildPolicy.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -15,8 +15,14 @@ object builtObject = instance.Build(pluginType, buildSession); - // TODO: error handling around the interception - return buildSession.ApplyInterception(pluginType, builtObject); + try + { + return buildSession.ApplyInterception(pluginType, builtObject); + } + catch (Exception e) + { + throw new StructureMapException(308, e, instance.Name, builtObject.GetType()); + } } public IBuildPolicy Clone() Added: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Building.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Building.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Building.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace StructureMap.Pipeline +{ + public partial class ConfiguredInstance + { + Type IConfiguredInstance.PluggedType + { + get { return _pluggedType; } + } + + Instance[] IConfiguredInstance.GetChildrenArray(string propertyName) + { + return _arrays.ContainsKey(propertyName) ? _arrays[propertyName] : null; + } + + string IConfiguredInstance.GetProperty(string propertyName) + { + if (!_properties.ContainsKey(propertyName)) + { + throw new StructureMapException(205, propertyName, Name); + } + + return _properties[propertyName]; + } + + object IConfiguredInstance.GetChild(string propertyName, Type pluginType, IBuildSession buildSession) + { + return getChild(propertyName, pluginType, buildSession); + } + + string IConfiguredInstance.ConcreteKey + { + get { return _concreteKey; } + set { _concreteKey = value; } + } + + + // Only open for testing + object IConfiguredInstance.Build(Type pluginType, IBuildSession session, InstanceBuilder builder) + { + if (builder == null) + { + throw new StructureMapException( + 201, _concreteKey, Name, pluginType); + } + + + try + { + return builder.BuildInstance(this, session); + } + catch (StructureMapException) + { + throw; + } + catch (InvalidCastException ex) + { + throw new StructureMapException(206, ex, Name); + } + catch (Exception ex) + { + throw new StructureMapException(207, ex, Name, pluginType.FullName); + } + } + + } +} Added: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -0,0 +1,283 @@ +using System; +using System.Configuration; +using StructureMap.Configuration.DSL; +using StructureMap.Graph; + +namespace StructureMap.Pipeline +{ + public partial class ConfiguredInstance + { + /// <summary> + /// Use a named Plugin type denoted by a [Pluggable("Key")] attribute + /// </summary> + /// <param name="concreteKey"></param> + /// <returns></returns> + public ConfiguredInstance UsingConcreteTypeNamed(string concreteKey) + { + _concreteKey = concreteKey; + return this; + } + + /// <summary> + /// Use type T for the concrete type of an instance + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + public ConfiguredInstance UsingConcreteType<T>() + { + _pluggedType = typeof (T); + return this; + } + + public ChildArrayExpression ChildArray<PLUGINTYPE>(string propertyName) + { + validateTypeIsArray<PLUGINTYPE>(); + + ChildArrayExpression expression = + new ChildArrayExpression(this, propertyName, typeof (PLUGINTYPE)); + + return expression; + } + + public ChildArrayExpression ChildArray(string propertyName, Type childType) + { + return new ChildArrayExpression(this, propertyName, childType); + } + + public ChildArrayExpression ChildArray<PLUGINTYPE>() + { + validateTypeIsArray<PLUGINTYPE>(); + + string propertyName = findPropertyName<PLUGINTYPE>(); + return ChildArray<PLUGINTYPE>(propertyName); + } + + /// <summary> + /// Start the definition of a child instance for type CONSTRUCTORARGUMENTTYPE + /// </summary> + /// <typeparam name="CONSTRUCTORARGUMENTTYPE"></typeparam> + /// <returns></returns> + public ChildInstanceExpression Child<CONSTRUCTORARGUMENTTYPE>() + { + string propertyName = findPropertyName<CONSTRUCTORARGUMENTTYPE>(); + + ChildInstanceExpression child = Child(propertyName); + child.ChildType = typeof (CONSTRUCTORARGUMENTTYPE); + + return child; + } + + public ChildInstanceExpression Child(string propertyName) + { + return new ChildInstanceExpression(this, propertyName); + } + + + /// <summary> + /// Starts the definition of a child instance specifying the argument name + /// in the case of a constructor function that consumes more than one argument + /// of type T + /// </summary> + /// <typeparam name="CONSTRUCTORARGUMENTTYPE"></typeparam> + /// <param name="propertyName"></param> + /// <returns></returns> + public ChildInstanceExpression Child<CONSTRUCTORARGUMENTTYPE>(string propertyName) + { + ChildInstanceExpression child = new ChildInstanceExpression(this, propertyName); + child.ChildType = typeof (CONSTRUCTORARGUMENTTYPE); + + return child; + } + + /// <summary> + /// Start the definition of a primitive argument to a constructor argument + /// </summary> + /// <param name="propertyName"></param> + /// <returns></returns> + public PropertyExpression WithProperty(string propertyName) + { + return new PropertyExpression(this, propertyName); + } + + public ConfiguredInstance WithConcreteKey(string concreteKey) + { + replaceNameIfNotAlreadySet(concreteKey); + _concreteKey = concreteKey; + return this; + } + + + private string findPropertyName<T>() + { + Plugin plugin = new Plugin(_pluggedType); + string propertyName = plugin.FindFirstConstructorArgumentOfType<T>(); + + if (string.IsNullOrEmpty(propertyName)) + { + throw new StructureMapException(305, typeof (T)); + } + + return propertyName; + } + + private static void validateTypeIsArray<PLUGINTYPE>() + { + if (!typeof (PLUGINTYPE).IsArray) + { + throw new StructureMapException(307); + } + } + + #region Nested type: ChildArrayExpression + + public class ChildArrayExpression + { + private readonly Type _childType; + private readonly ConfiguredInstance _instance; + private readonly string _propertyName; + + public ChildArrayExpression(ConfiguredInstance instance, string propertyName, Type childType) + { + _instance = instance; + _propertyName = propertyName; + + _childType = _childType; + } + + public ConfiguredInstance Contains(params Instance[] instances) + { + _instance.setChildArray(_propertyName, instances); + + return _instance; + } + } + + #endregion + + #region Nested type: ChildInstanceExpression + + /// <summary> + /// Part of the Fluent Interface, represents a nonprimitive argument to a + /// constructure function + /// </summary> + public class ChildInstanceExpression + { + private readonly ConfiguredInstance _instance; + private readonly string _propertyName; + private Type _childType; + + + public ChildInstanceExpression(ConfiguredInstance instance, string propertyName) + { + _instance = instance; + _propertyName = propertyName; + } + + public ChildInstanceExpression(ConfiguredInstance instance, string propertyName, + Type childType) + : this(instance, propertyName) + { + _childType = childType; + } + + internal Type ChildType + { + set { _childType = value; } + } + + /// <summary> + /// Use a previously configured and named instance for the child + /// </summary> + /// <param name="instanceKey"></param> + /// <returns></returns> + public ConfiguredInstance IsNamedInstance(string instanceKey) + { + ReferencedInstance instance = new ReferencedInstance(instanceKey); + _instance.setChild(_propertyName, instance); + + return _instance; + } + + /// <summary> + /// Start the definition of a child instance by defining the concrete type + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + public ConfiguredInstance IsConcreteType<T>() + { + Type pluggedType = typeof (T); + ExpressionValidator.ValidatePluggabilityOf(pluggedType).IntoPluginType(_childType); + + ConfiguredInstance childInstance = new ConfiguredInstance(); + childInstance._pluggedType = pluggedType; + _instance.setChild(_propertyName, childInstance); + + return _instance; + } + + + /// <summary> + /// Registers a configured instance to use as the argument to the parent's + /// constructor + /// </summary> + /// <param name="child"></param> + /// <returns></returns> + public ConfiguredInstance Is(Instance child) + { + _instance.setChild(_propertyName, child); + return _instance; + } + + public ConfiguredInstance Is(object value) + { + LiteralInstance instance = new LiteralInstance(value); + return Is(instance); + } + } + + #endregion + + #region Nested type: PropertyExpression + + /// <summary> + /// Defines the value of a primitive argument to a constructur argument + /// </summary> + public class PropertyExpression + { + private readonly ConfiguredInstance _instance; + private readonly string _propertyName; + + public PropertyExpression(ConfiguredInstance instance, string propertyName) + { + _instance = instance; + _propertyName = propertyName; + } + + /// <summary> + /// Sets the value of the constructor argument + /// </summary> + /// <param name="propertyValue"></param> + /// <returns></returns> + public ConfiguredInstance EqualTo(object propertyValue) + { + _instance.SetProperty(_propertyName, propertyValue.ToString()); + return _instance; + } + + /// <summary> + /// Sets the value of the constructor argument to the key/value in the + /// AppSettings + /// </summary> + /// <param name="appSettingKey"></param> + /// <returns></returns> + public ConfiguredInstance EqualToAppSetting(string appSettingKey) + { + string propertyValue = ConfigurationManager.AppSettings[appSettingKey]; + _instance.SetProperty(_propertyName, propertyValue); + return _instance; + } + } + + #endregion + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -1,13 +1,11 @@ using System; using System.Collections.Generic; -using System.Configuration; -using StructureMap.Configuration.DSL; using StructureMap.Graph; namespace StructureMap.Pipeline { - // TODO: Move the FI stuff into a partial class - public class ConfiguredInstance : ExpressedInstance<ConfiguredInstance>, IConfiguredInstance + public partial class ConfiguredInstance : ExpressedInstance<ConfiguredInstance>, IConfiguredInstance, + IStructuredInstance { private readonly Dictionary<string, Instance> _children = new Dictionary<string, Instance>(); private readonly Dictionary<string, string> _properties = new Dictionary<string, string>(); @@ -23,7 +21,7 @@ public ConfiguredInstance(InstanceMemento memento, PluginGraph graph, Type pluginType) { - Read(memento, graph, pluginType); + read(memento, graph, pluginType); } public ConfiguredInstance(string name) @@ -37,55 +35,36 @@ _pluggedType = pluggedType; } - public Type PluggedType - { - get { return _pluggedType; } - set { _pluggedType = value; } - } - protected override ConfiguredInstance thisInstance { get { return this; } } - #region IConfiguredInstance Members + #region IStructuredInstance Members - public string ConcreteKey + Instance IStructuredInstance.GetChild(string name) { - get - { - return _concreteKey; - } - set { _concreteKey = value; } + return _children[name]; } - Instance[] IConfiguredInstance.GetChildrenArray(string propertyName) + Instance[] IStructuredInstance.GetChildArray(string name) { - if (_arrays.ContainsKey(propertyName)) - { - return _arrays[propertyName]; - } - - return null; + return _arrays[name]; } - string IConfiguredInstance.GetProperty(string propertyName) + void IStructuredInstance.RemoveKey(string name) { - if (!_properties.ContainsKey(propertyName)) - { - throw new StructureMapException(205, propertyName, Name); - } - - return _properties[propertyName]; + _properties.Remove(name); } - object IConfiguredInstance.GetChild(string propertyName, Type pluginType, IBuildSession buildSession) + #endregion + + protected void setPluggedType(Type pluggedType) { - return getChild(propertyName, pluginType, buildSession); + _pluggedType = pluggedType; } - #endregion protected void mergeIntoThis(ConfiguredInstance instance) { @@ -114,39 +93,11 @@ protected override object build(Type pluginType, IBuildSession session) { InstanceBuilder builder = session.FindBuilderByType(pluginType, _pluggedType) ?? - session.FindBuilderByConcreteKey(pluginType, ConcreteKey); + session.FindBuilderByConcreteKey(pluginType, _concreteKey); - return Build(pluginType, session, builder); + return ((IConfiguredInstance) this).Build(pluginType, session, builder); } - // Only open for testing - public object Build(Type pluginType, IBuildSession session, InstanceBuilder builder) - { - if (builder == null) - { - throw new StructureMapException( - 201, ConcreteKey, Name, pluginType); - } - - - try - { - return builder.BuildInstance(this, session); - } - catch (StructureMapException) - { - throw; - } - catch (InvalidCastException ex) - { - throw new StructureMapException(206, ex, Name); - } - catch (Exception ex) - { - throw new StructureMapException(207, ex, Name, pluginType.FullName); - } - } - protected virtual object getChild(string propertyName, Type pluginType, IBuildSession buildSession) { Instance childInstance = _children.ContainsKey(propertyName) @@ -166,9 +117,9 @@ return family.Plugins.HasPlugin(_concreteKey); } - if (PluggedType != null) + if (_pluggedType != null) { - return TypeRules.CanBeCast(family.PluginType, PluggedType); + return TypeRules.CanBeCast(family.PluginType, _pluggedType); } return false; @@ -185,12 +136,12 @@ return this; } - public void Read(InstanceMemento memento, PluginGraph graph, Type pluginType) + private void read(InstanceMemento memento, PluginGraph graph, Type pluginType) { PluginFamily family = graph.FindFamily(pluginType); Plugin plugin = memento.FindPlugin(family); - PluggedType = plugin.PluggedType; + _pluggedType = plugin.PluggedType; _concreteKey = plugin.ConcreteKey; InstanceMementoPropertyReader reader = new InstanceMementoPropertyReader(this, memento, graph, pluginType); @@ -198,286 +149,17 @@ } - public void SetChild(string name, Instance instance) + private void setChild(string name, Instance instance) { _children.Add(name, instance); } - public Instance GetChild(string name) + private void setChildArray(string name, Instance[] array) { - return _children[name]; - } - - public void SetChildArray(string name, Instance[] array) - { _arrays.Add(name, array); } - public Instance[] GetChildArray(string name) - { - return _arrays[name]; - } - - public ConfiguredInstance WithConcreteKey(string concreteKey) - { - replaceNameIfNotAlreadySet(concreteKey); - _concreteKey = concreteKey; - return this; - } - - public void RemoveKey(string name) - { - _properties.Remove(name); - } - - /// <summary> - /// Start the definition of a primitive argument to a constructor argument - /// </summary> - /// <param name="propertyName"></param> - /// <returns></returns> - public PropertyExpression WithProperty(string propertyName) - { - return new PropertyExpression(this, propertyName); - } - - /// <summary> - /// Starts the definition of a child instance specifying the argument name - /// in the case of a constructor function that consumes more than one argument - /// of type T - /// </summary> - /// <typeparam name="CONSTRUCTORARGUMENTTYPE"></typeparam> - /// <param name="propertyName"></param> - /// <returns></returns> - public ChildInstanceExpression Child<CONSTRUCTORARGUMENTTYPE>(string propertyName) - { - ChildInstanceExpression child = new ChildInstanceExpression(this, propertyName); - child.ChildType = typeof (CONSTRUCTORARGUMENTTYPE); - - return child; - } - - /// <summary> - /// Start the definition of a child instance for type CONSTRUCTORARGUMENTTYPE - /// </summary> - /// <typeparam name="CONSTRUCTORARGUMENTTYPE"></typeparam> - /// <returns></returns> - public ChildInstanceExpression Child<CONSTRUCTORARGUMENTTYPE>() - { - string propertyName = findPropertyName<CONSTRUCTORARGUMENTTYPE>(); - - ChildInstanceExpression child = new ChildInstanceExpression(this, propertyName); - child.ChildType = typeof (CONSTRUCTORARGUMENTTYPE); - return child; - } - - private string findPropertyName<T>() - { - Plugin plugin = new Plugin(_pluggedType); - string propertyName = plugin.FindFirstConstructorArgumentOfType<T>(); - - if (string.IsNullOrEmpty(propertyName)) - { - throw new StructureMapException(305, typeof (T)); - } - - return propertyName; - } - - public ChildArrayExpression<PLUGINTYPE> ChildArray<PLUGINTYPE>() - { - validateTypeIsArray<PLUGINTYPE>(); - - string propertyName = findPropertyName<PLUGINTYPE>(); - return ChildArray<PLUGINTYPE>(propertyName); - } - - public ChildArrayExpression<PLUGINTYPE> ChildArray<PLUGINTYPE>(string propertyName) - { - validateTypeIsArray<PLUGINTYPE>(); - - ChildArrayExpression<PLUGINTYPE> expression = - new ChildArrayExpression<PLUGINTYPE>(this, propertyName); - - return expression; - } - - private static void validateTypeIsArray<PLUGINTYPE>() - { - if (!typeof (PLUGINTYPE).IsArray) - { - throw new StructureMapException(307); - } - } - - /// <summary> - /// Use type T for the concrete type of an instance - /// </summary> - /// <typeparam name="T"></typeparam> - /// <returns></returns> - public ConfiguredInstance UsingConcreteType<T>() - { - _pluggedType = typeof (T); - return this; - } - - /// <summary> - /// Use a named Plugin type denoted by a [Pluggable("Key")] attribute - /// </summary> - /// <param name="concreteKey"></param> - /// <returns></returns> - public ConfiguredInstance UsingConcreteTypeNamed(string concreteKey) - { - _concreteKey = concreteKey; - return this; - } - - #region Nested type: ChildArrayExpression - - public class ChildArrayExpression<PLUGINTYPE> - { - private readonly ConfiguredInstance _instance; - private readonly string _propertyName; - private Type _pluginType = typeof (PLUGINTYPE); - - public ChildArrayExpression(ConfiguredInstance instance, string propertyName) - { - _instance = instance; - _propertyName = propertyName; - - _pluginType = typeof (PLUGINTYPE).GetElementType(); - } - - public ConfiguredInstance Contains(params Instance[] instances) - { - _instance.SetChildArray(_propertyName, instances); - - return _instance; - } - } - - #endregion - - #region Nested type: ChildInstanceExpression - - /// <summary> - /// Part of the Fluent Interface, represents a nonprimitive argument to a - /// constructure function - /// </summary> - public class ChildInstanceExpression - { - private readonly ConfiguredInstance _instance; - private readonly string _propertyName; - private Type _childType; - - - public ChildInstanceExpression(ConfiguredInstance instance, string propertyName) - { - _instance = instance; - _propertyName = propertyName; - } - - public ChildInstanceExpression(ConfiguredInstance instance, string propertyName, - Type childType) - : this(instance, propertyName) - { - _childType = childType; - } - - internal Type ChildType - { - set { _childType = value; } - } - - /// <summary> - /// Use a previously configured and named instance for the child - /// </summary> - /// <param name="instanceKey"></param> - /// <returns></returns> - public ConfiguredInstance IsNamedInstance(string instanceKey) - { - ReferencedInstance instance = new ReferencedInstance(instanceKey); - _instance.SetChild(_propertyName, instance); - - return _instance; - } - - /// <summary> - /// Start the definition of a child instance by defining the concrete type - /// </summary> - /// <typeparam name="T"></typeparam> - /// <returns></returns> - public ConfiguredInstance IsConcreteType<T>() - { - Type pluggedType = typeof (T); - ExpressionValidator.ValidatePluggabilityOf(pluggedType).IntoPluginType(_childType); - - ConfiguredInstance childInstance = new ConfiguredInstance(); - childInstance.PluggedType = pluggedType; - _instance.SetChild(_propertyName, childInstance); - - return _instance; - } - - - /// <summary> - /// Registers a configured instance to use as the argument to the parent's - /// constructor - /// </summary> - /// <param name="child"></param> - /// <returns></returns> - public ConfiguredInstance Is(Instance child) - { - _instance.SetChild(_propertyName, child); - return _instance; - } - } - - #endregion - - #region Nested type: PropertyExpression - - /// <summary> - /// Defines the value of a primitive argument to a constructur argument - /// </summary> - public class PropertyExpression - { - private readonly ConfiguredInstance _instance; - private readonly string _propertyName; - - public PropertyExpression(ConfiguredInstance instance, string propertyName) - { - _instance = instance; - _propertyName = propertyName; - } - - /// <summary> - /// Sets the value of the constructor argument - /// </summary> - /// <param name="propertyValue"></param> - /// <returns></returns> - public ConfiguredInstance EqualTo(object propertyValue) - { - _instance.SetProperty(_propertyName, propertyValue.ToString()); - return _instance; - } - - /// <summary> - /// Sets the value of the constructor argument to the key/value in the - /// AppSettings - /// </summary> - /// <param name="appSettingKey"></param> - /// <returns></returns> - public ConfiguredInstance EqualToAppSetting(string appSettingKey) - { - string propertyValue = ConfigurationManager.AppSettings[appSettingKey]; - _instance.SetProperty(_propertyName, propertyValue); - return _instance; - } - } - - #endregion - protected override void preprocess(PluginFamily family) { if (_pluggedType != null) Modified: trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -47,7 +47,7 @@ foreach (KeyValuePair<string, object> arg in _args) { instance.SetProperty(arg.Key, arg.Value.ToString()); - instance.SetChild(arg.Key, new LiteralInstance(arg.Value)); + instance.Child(arg.Key).Is(arg.Value); } } @@ -78,7 +78,7 @@ } else { - PluggedType = typeof (PLUGINTYPE); + setPluggedType(typeof(PLUGINTYPE)); } } Modified: trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -6,8 +6,10 @@ { string Name { get; } string ConcreteKey { get; set; } + Type PluggedType { get; } Instance[] GetChildrenArray(string propertyName); string GetProperty(string propertyName); object GetChild(string propertyName, Type pluginType, IBuildSession buildSession); + object Build(Type pluginType, IBuildSession session, InstanceBuilder builder); } } \ No newline at end of file Added: trunk/Source/StructureMap/Pipeline/IStructuredInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/IStructuredInstance.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/IStructuredInstance.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -0,0 +1,9 @@ +namespace StructureMap.Pipeline +{ + public interface IStructuredInstance + { + Instance GetChild(string name); + Instance[] GetChildArray(string name); + void RemoveKey(string name); + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/Instance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Instance.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap/Pipeline/Instance.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -81,7 +81,7 @@ public virtual object Build(Type pluginType, IBuildSession session) { object rawValue = createRawObject(pluginType, session); - return applyInterception(rawValue); + return applyInterception(rawValue, pluginType); } private object createRawObject(Type pluginType, IBuildSession session) @@ -100,7 +100,7 @@ } } - private object applyInterception(object rawValue) + private object applyInterception(object rawValue, Type pluginType) { try { @@ -109,8 +109,7 @@ } catch (Exception e) { - throw new StructureMapException(308, e, Name, - TypePath.GetAssemblyQualifiedName(rawValue.GetType())); + throw new StructureMapException(270, e, Name, pluginType); } } Modified: trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -84,19 +84,13 @@ InstanceMemento child = _memento.GetChildMemento(name); Instance childInstance = child == null ? new DefaultInstance() : child.ReadInstance(_pluginGraph, childType); - _instance.SetChild(name, childInstance); + _instance.Child(name).Is(childInstance); } private void copyChildArray(string name, Type childType) { - InstanceMemento[] mementoes = _memento.GetChildrenArray(name); + InstanceMemento[] mementoes = _memento.GetChildrenArray(name) ?? new InstanceMemento[0]; - // TODO -- want to default to mementoes == null is all - if (mementoes == null) - { - mementoes = new InstanceMemento[0]; - } - Instance[] children = new Instance[mementoes.Length]; for (int i = 0; i < mementoes.Length; i++) { @@ -104,7 +98,7 @@ children[i] = memento.ReadInstance(_pluginGraph, childType); } - _instance.SetChildArray(name, children); + _instance.ChildArray(name, childType).Contains(children); } } } \ No newline at end of file Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-05-27 17:50:51 UTC (rev 102) @@ -147,6 +147,7 @@ <Compile Include="Pipeline\BuildPolicy.cs" /> <Compile Include="Pipeline\CacheInterceptor.cs" /> <Compile Include="Pipeline\ConfiguredInstance.cs" /> + <Compile Include="Pipeline\ConfiguredInstance.Expressions.cs" /> <Compile Include="Pipeline\ConstructorInstance.cs" /> <Compile Include="Pipeline\DefaultInstance.cs" /> <Compile Include="Pipeline\HttpContextBuildPolicy.cs" /> @@ -372,6 +373,8 @@ <None Include="..\structuremap.snk"> <Link>Properties\structuremap.snk</Link> </None> + <Compile Include="Pipeline\ConfiguredInstance.Building.cs" /> + <Compile Include="Pipeline\IStructuredInstance.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <PropertyGroup> Modified: trunk/Source/StructureMap/StructureMapConfiguration.cs =================================================================== --- trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -151,6 +151,11 @@ return _registry.BuildInstancesOf<PLUGINTYPE>(); } + public static GenericFamilyExpression ForRequestedType(Type pluginType) + { + return _registry.ForRequestedType(pluginType); + } + /// <summary> /// Adds a new configured instance of Type T /// </summary> Modified: trunk/Source/StructureMap/StructureMapException.resx =================================================================== --- trunk/Source/StructureMap/StructureMapException.resx 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap/StructureMapException.resx 2008-05-27 17:50:51 UTC (rev 102) @@ -253,4 +253,7 @@ <data name="196" xml:space="preserve"> <value>Could not find referenced instance named {0} of PluginType {1} for Profile {2}</value> </data> + <data name="270" xml:space="preserve"> + <value>Instance specific interception failed for {0} of PluginType {1}</value> + </data> </root> \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -101,13 +101,18 @@ Assert.AreSame(_lastService, interceptedService); } - [Test, - ExpectedException(typeof (StructureMapException), - ExpectedMessage = "StructureMap Exception Code: 308\nA configured instance interceptor has failed for Instance 'Bad' and concrete type 'StructureMap.Testing.Widget3.ColorService,StructureMap.Testing.Widget3'" - )] + [Test] public void TrapFailureInInterceptor() { - _manager.CreateInstance<IService>("Bad"); + try + { + _manager.CreateInstance<IService>("Bad"); + Assert.Fail("Should have thrown an error"); + } + catch (StructureMapException e) + { + Assert.AreEqual(270, e.ErrorCode); + } } } Modified: trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -13,7 +13,14 @@ [SetUp] public void SetUp() { - _graph = DataMother.GetPluginGraph("DefaultInstance.xml"); + string xml = @" +<StructureMap MementoStyle='Attribute'> + <DefaultInstance PluginType='StructureMap.Testing.Widget.IWidget,StructureMap.Testing.Widget' PluggedType='StructureMap.Testing.Widget.ColorWidget,StructureMap.Testing.Widget' Color='Red' /> + <DefaultInstance PluginType='StructureMap.Testing.Widget.Rule,StructureMap.Testing.Widget' PluggedType='StructureMap.Testing.Widget.ColorRule,StructureMap.Testing.Widget' Color='Blue' Scope='Singleton' Key='TheBlueOne'/> +</StructureMap> +"; + + _graph = DataMother.BuildPluginGraphFromXml(xml); _manager = new InstanceManager(_graph); } Modified: trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -40,41 +40,11 @@ private BuildSession _session; - [Test] - public void BuildRule1() - { - // TODO: Move to ConfiguredInstanceTester - ConfiguredInstance instance = new ConfiguredInstance().WithConcreteKey("Rule1"); - Rule rule = (Rule) instance.Build(typeof(Rule), _session); - Assert.IsNotNull(rule); - Assert.IsTrue(rule is Rule1); - } - [Test, ExpectedException(typeof (StructureMapException))] - public void BuildRuleWithABadValue() - { - // TODO -- move to ConfiguredInstanceTester - - ConfiguredInstance instance = (ConfiguredInstance) ComplexRule.GetInstance(); - instance.SetProperty("Int", "abc"); - ComplexRule rule = (ComplexRule)instance.Build(typeof(Rule), _session); - } - [Test, ExpectedException(typeof (StructureMapException))] - public void BuildRuleWithAMissingValue() - { - // TODO: Move to ConfiguredInstanceTester - - ConfiguredInstance instance = (ConfiguredInstance) ComplexRule.GetInstance(); - instance.RemoveKey("String"); - - ComplexRule rule = (ComplexRule)instance.Build(typeof(Rule), _session); - } - - [Test, ExpectedException(typeof (StructureMapException))] public void GetInstanceWithInvalidInstanceKey() { _manager.CreateInstance<Rule>("NonExistentRule"); @@ -100,18 +70,8 @@ } - [Test] - public void TestComplexRule() - { - // TODO: Move to ConfiguredInstanceTester - ConfiguredInstance instance = (ConfiguredInstance) ComplexRule.GetInstance(); - Rule rule = (Rule) instance.Build(typeof(Rule), _session); - Assert.IsNotNull(rule); - Assert.IsTrue(rule is ComplexRule); - } - } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -91,7 +91,7 @@ Assert.AreEqual(Plugin.DEFAULT, family.DefaultInstanceKey); Assert.AreEqual(1, family.PluginCount); Assert.AreEqual(1, family.GetAllInstances().Length); - ConfiguredInstance instance = (ConfiguredInstance) family.GetAllInstances()[0]; + IConfiguredInstance instance = (IConfiguredInstance) family.GetAllInstances()[0]; Assert.AreEqual(Plugin.DEFAULT, instance.Name); Assert.AreEqual(GetType(), instance.PluggedType); } Modified: trunk/Source/StructureMap.Testing/Graph/PluginTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/PluginTester.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap.Testing/Graph/PluginTester.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -157,7 +157,7 @@ Plugin plugin = new Plugin(typeof (DefaultGateway), "Default"); Assert.IsTrue(plugin.CanBeAutoFilled); - ConfiguredInstance instance = (ConfiguredInstance) plugin.CreateImplicitInstance(); + IConfiguredInstance instance = (ConfiguredInstance) plugin.CreateImplicitInstance(); Assert.AreEqual("Default", instance.Name); Assert.AreEqual(typeof(DefaultGateway), instance.PluggedType); Modified: trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -139,5 +139,45 @@ { Plugin plugin = new Plugin(typeof (BadSetterClass)); } + + + + [Test] + public void Log_240_when_a_designated_setter_does_not_exist() + { + string errorXml = @" + <StructureMap> + <PluginFamily Type='StructureMap.Testing.Widget5.IGridColumn' Assembly='StructureMap.Testing.Widget5' DefaultKey=''> + <Plugin Assembly='StructureMap.Testing.Widget5' Type='StructureMap.Testing.Widget5.OtherGridColumn' ConcreteKey='Other'> + <Setter Name='Does not exist' /> + </Plugin> + </PluginFamily> + </StructureMap> + "; + + + PluginGraph graph = DataMother.BuildPluginGraphFromXml(errorXml); + graph.Log.AssertHasError(240); + } + + + [Test] + public void Log_241_when_a_designated_setter_does_not_exist() + { + string errorXml = @" + <StructureMap> + <PluginFamily Type='StructureMap.Testing.Widget5.IGridColumn' Assembly='StructureMap.Testing.Widget5' DefaultKey=''> + <Plugin Assembly='StructureMap.Testing.Widget5' Type='StructureMap.Testing.Widget5.OtherGridColumn' ConcreteKey='Other'> + <Setter Name='ReadOnly' /> + </Plugin> + </PluginFamily> + </StructureMap> + "; + + + PluginGraph graph = DataMother.BuildPluginGraphFromXml(errorXml); + graph.Log.AssertHasError(241); + } + } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -187,7 +187,7 @@ MemoryInstanceMemento.CreateReferencedInstanceMemento("Dodge"), }); - ConfiguredInstance instance = (ConfiguredInstance)memento.ReadInstance(graph, typeof(Rule)); + IStructuredInstance instance = (IStructuredInstance)memento.ReadInstance(graph, typeof(Rule)); Instance[] instances = instance.GetChildArray("cars"); Assert.AreEqual(3, instances.Length); @@ -216,7 +216,7 @@ MemoryInstanceMemento carMemento = MemoryInstanceMemento.CreateReferencedInstanceMemento("GrandPrix"); memento.AddChild("car", carMemento); - ConfiguredInstance instance = (ConfiguredInstance) memento.ReadInstance(graph, typeof (Rule)); + IStructuredInstance instance = (IStructuredInstance)memento.ReadInstance(graph, typeof(Rule)); ReferencedInstance child = (ReferencedInstance) instance.GetChild("car"); Assert.AreEqual("GrandPrix", child.ReferenceKey); @@ -233,7 +233,7 @@ MemoryInstanceMemento memento = ComplexRule.GetMemento(); memento.SetProperty(XmlConstants.PLUGGED_TYPE, typeof (ComplexRule).AssemblyQualifiedName); - ConfiguredInstance instance = (ConfiguredInstance) memento.ReadInstance(graph, typeof (Rule)); + IStructuredInstance instance = (IStructuredInstance)memento.ReadInstance(graph, typeof(Rule)); Assert.IsInstanceOfType(typeof (DefaultInstance), instance.GetChild("car")); } Modified: trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -44,7 +44,24 @@ } } + [Test] + public void BuildPolicy_should_throw_270_if_interception_fails() + { + try + { + LiteralInstance instance = new LiteralInstance("something") + .OnCreation<object>(delegate(object o){throw new NotImplementedException();}); + BuildPolicy policy = new BuildPolicy(); + policy.Build(new StubBuildSession(), typeof (string), instance); + } + catch (StructureMapException e) + { + Assert.AreEqual(270, e.ErrorCode); + } + } + + [Test] public void Singleton_build_policy() { Modified: trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs 2008-05-27 15:36:33 UTC (rev 101) +++ trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs 2008-05-27 17:50:51 UTC (rev 102) @@ -1,9 +1,11 @@ using System; using NUnit.Framework; using Rhino.Mocks; +using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Pipeline; using StructureMap.Testing.Widget; +using StructureMap.Testing.Widget2; using StructureMap.Testing.Widget3; namespace StructureMap.Testing.Pipeline @@ -16,12 +18,24 @@ [SetUp] public void SetUp() { + PluginGraph graph = new PluginGraph(); + Registry registry = new Registry(graph); + registry.BuildInstancesOf<Rule>(); + registry.ScanAssemblies() + .IncludeAssembly("StructureMap.Testing.Widget") + .IncludeAssembly("StructureMap.Testing.Widget2"); + + registry.Build(); + + PipelineGraph pipelineGraph = new PipelineGraph(graph); + _session = new BuildSession(pipelineGraph, graph.InterceptorLibrary); instance = new ConfiguredInstance(); } #endregion private ConfiguredInstance instance; + private IBuildSession _session; private void assertActionThrowsErrorCode(int errorCode, Action action) @@ -38,29 +52,17 @@ } } - [Test] - public void Create_description_if_has_pluggedType_and_plugged_type_has_arguments() + public void TestComplexRule() { - ConfiguredInstance instance = new ConfiguredInstance(typeof(ColorService)); - TestUtility.AssertDescriptionIs(instance, "Configured " + TypePath.GetAssemblyQualifiedName(typeof(ColorService))); - } + ConfiguredInstance instance = (ConfiguredInstance)ComplexRule.GetInstance(); - [Test] - public void Create_description_if_has_only_concrete_key() - { - ConfiguredInstance instance = new ConfiguredInstance().WithConcreteKey("Concrete"); - TestUtility.AssertDescriptionIs(instance, "Configured 'Concrete'"); + Rule rule = (Rule)instance.Build(typeof(Rule), _session); + Assert.IsNotNull(rule); + Assert.IsTrue(rule is ComplexRule); } - [Test] - public void Create_description_if_has_plugged_type_and_plugged_type_has_no_arguments() - { - ConfiguredInstance instance = new ConfiguredInstance(GetType()); - TestUtility.AssertDescriptionIs(instance, TypePath.GetAssemblyQualifiedName(GetType())); - } - [Test] public void AttachDependencies_should_find_the_InstanceBuilder_by_ConcreteKey_if_PluggedType_does_not_exists() { @@ -104,29 +106,123 @@ using (mocks.Playback()) { - object actualObject = instance.Build(GetType(), session, builder); + object actualObject = ((IConfiguredInstance)instance).Build(GetType(), session, builder); Assert.AreSame(theObjectBuilt, actualObject); } } [Test] + public void BuildRule1() + { + ConfiguredInstance instance = new ConfiguredInstance().WithConcreteKey("Rule1"); + + Rule rule = (Rule) instance.Build(typeof (Rule), _session); + Assert.IsNotNull(rule); + Assert.IsTrue(rule is Rule1); + } + + + [Test, ExpectedException(typeof (StructureMapException))] + public void BuildRuleWithABadValue() + { + ConfiguredInstance instance = (ConfiguredInstance) ComplexRule.GetInstance(); + + instance.SetProperty("Int", "abc"); + ComplexRule rule = (ComplexRule) instance.Build(typeof (Rule), _session); + } + + [Test, ExpectedException(typeof (StructureMapException))] + public void BuildRuleWithAMissingValue() + { + IStructuredInstance instance = (IStructuredInstance)ComplexRule.GetInstance(); + instance.RemoveKey("String"); + + ComplexRule rule = (ComplexRule) ((Instance)instance).Build(typeof (Rule), _session); + } + + [Test] + public void Can_be_plugged_in_by_concrete_key() + { + ConfiguredInstance instance = new ConfiguredInstance().WithConcreteKey("Color"); + PluginFamily family = new PluginFamily(typeof (IWidget)); + family.AddPlugin(typeof (ColorWidget), "Color"); + + IDiagnosticInstance diagnosticInstance = instance; + Assert.IsTrue(diagnosticInstance.CanBePartOfPluginFamily(family)); + } + + [Test] + public void Can_be_plugged_in_if_there_is_a_plugged_type_and_the_plugged_type_can_be_cast_to_the_plugintype() + { + ConfiguredInstance instance = new ConfiguredInstance().UsingConcreteType<ColorWidget>(); + PluginFamily family = new PluginFamily(typeof (IWidget)); + + IDiagnosticInstance diagnosticInstance = instance; + Assert.IsTrue(diagnosticInstance.CanBePartOfPluginFamily(family)); + } + + [Test] + public void Can_NOT_be_plugged_in_if_no_plugged_type_and_concrete_key_cannot_be_found_in_family() + { + ConfiguredInstance instance = new ConfiguredInstance().WithConcreteKey("SomethingThatDoesNotExist"); + PluginFamily family = new PluginFamily(typeof (IWidget)); + + IDiagnosticInstance diagnosticInstance = instance; + Assert... [truncated message content] |