Permalink
Browse files

Added the <DefaultInstance> node capability, documentation, set the d…

…efault profile from code
  • Loading branch information...
1 parent c3de67b commit 692d94cd47ec2309d23ab526519917b63998800c @jeremydmiller jeremydmiller committed Apr 1, 2007
Showing with 252 additions and 83 deletions.
  1. +95 −5 Docs/Configuration.htm
  2. +26 −40 Docs/Default.htm
  3. +1 −1 Source/StructureMap.Testing.Widget/IWidget.cs
  4. +0 −2 Source/StructureMap.Testing.Widget/Rule.cs
  5. +7 −7 Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs
  6. +59 −0 Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs
  7. +2 −1 Source/StructureMap.Testing/Configuration/FamilyParserTester.cs
  8. +1 −2 Source/StructureMap.Testing/GenericsAcceptanceTester.cs
  9. +0 −1 Source/StructureMap.Testing/ObjectMother.cs
  10. +2 −0 Source/StructureMap.Testing/StructureMap.Testing.csproj
  11. +5 −5 Source/StructureMap.Testing/StructureMapConfigurationTester.cs
  12. +1 −1 Source/StructureMap.Testing/TestData/DataMother.cs
  13. +4 −0 Source/StructureMap.Testing/TestData/DefaultInstance.xml
  14. +9 −6 Source/StructureMap/Configuration/ConfigurationParser.cs
  15. +22 −1 Source/StructureMap/Configuration/FamilyParser.cs
  16. +0 −1 Source/StructureMap/Configuration/GraphObject.cs
  17. +0 −1 Source/StructureMap/Configuration/PluginGraphReport.cs
  18. +2 −5 Source/StructureMap/Configuration/StructureMapConfigurationSection.cs
  19. +1 −1 Source/StructureMap/Configuration/UserControlMemento.cs
  20. +2 −0 Source/StructureMap/Configuration/XmlConstants.cs
  21. +0 −1 Source/StructureMap/Graph/PluginGraph.cs
  22. +6 −1 Source/StructureMap/InstanceMemento.cs
  23. +6 −0 Source/StructureMap/Source/XmlNodeInstanceMemento.cs
  24. +1 −1 Source/StructureMap/Verification/StartUp.cs
View
@@ -54,6 +54,7 @@ <h1>Configuration Schema</h1>
<A href="#log4net">log4net</A><BR>
<A href="#Machine">Machine</A><BR>
<A href="#PluginFamily">PluginFamily</A><BR>
+ <A href="#DefaultInstance">DefaultInstance</A><BR>
<A href="#Profile">Profile</A><BR>
<A href="#Instance">Instance</A><BR>
<A href="#Interceptors">Interceptors</A><BR>
@@ -63,6 +64,7 @@ <h1>Configuration Schema</h1>
<A href="#Setter">Setter</A><BR>
<A href="#Source">Source</A><BR>
<A href="#Property">Property</A></P>
+
<HR width="100%" SIZE="1">
<!--StructureMap node-->
<A name="StructureMap"></A>
@@ -81,6 +83,10 @@ <H4>Sample</H4>
<TD>Directs StructureMap to use the named
Profile as the default profile at runtime</TD>
</TR>
+ <tr>
+ <td>MementoStyle</td>
+ <td>Specifies the type of Instance Memento definition between "Node" normalized and "Attribute" normalized. For backwards compatibility, the default value is "Node"</td>
+ </tr>
</TABLE>
</DIV>
<p><A href="#TopOfPage">Back to Top</A><BR>
@@ -175,11 +181,19 @@ <H3>&lt;log4net&gt; Element</H3>
<HR>
<A name="Machine"></A>
<H3>&lt;Machine&gt; Element</H3>
- <P>Machine level overrides for default instances of one or more PluginFamily’s</P>
+ <P>Machine level overrides for default instances of one or more PluginFamily’s. New in version 2.0 is the ability to define the instance for the type specified by the Type attribute inline in an embedded &lt;Instance&gt; node</P>
<H4>Sample</H4>
- <pre class="xml-sample">&lt;Machine Name="SERVER" Profile="Local"&gt;
+ <pre class="xml-sample">
+&lt;Machine Name="SERVER" Profile="Local"&gt;
&lt;Override Type="StructureMap.Testing.Widget.IWidget" DefaultKey="Orange"/&gt;
-&lt;/Machine&gt;</pre>
+&lt;/Machine&gt;
+
+ &lt;Override Type="StructureMap.Testing.Widget.Rule"&gt;
+ &lt;Instance Type="Color" Color="Green"/&gt;
+ &lt;/Override>
+
+
+</pre>
<H4>Required Attributes</H4>
<DIV class="schema-table"><TABLE width="100%" border="1" cellPadding="1" cellSpacing="1" ID="Table3">
<TR>
@@ -253,6 +267,62 @@ <H4>Optional Attributes</H4>
<A href="#TopOfPage">Back to Top</A><BR>
<BR>
<HR>
+
+
+
+
+ <A name="DefaultInstance"></A>
+ <H3>&lt;DefaultInstance&gt; Element</H3>
+ <P>Shorthand way to explicitly define the default instance of a PluginType in one element. Explicitly directs and
+ configures StructureMap to create instances of the CLR Type specified by the "PluginType" attribute. The DefaultInstance node also represents an Instance node, and the arguments to the constructor function and setter properties follow the same rules as an Instance node.</P>
+ <H4>Sample</H4>
+ <pre class="xml-sample">&lt;DefaultInstance PluginType="StructureMap.Testing.Widget.Rule,StructureMap.Testing" PluggedType="StructureMap.Testing.Widget.ColorRule,StructureMap.Testing" Scope=&quot;Singleton"&gt; Color=&quot;Red&quot;
+ <BR> &lt;/DefaultInstance&gt;</pre>
+ <H4>Required Attributes</H4>
+ <DIV class="schema-table"><TABLE width="100%" border="1" cellPadding="1" cellSpacing="1" ID="Table19">
+ <TR>
+ <TH width="25%">
+ Attribute</TH><TH width="75%">Description</TH></TR>
+ <TR>
+ <TD>PluginType</TD>
+ <TD>Assembly qualified name of the PluginType, as in PluginType instance = ObjectFactory.GetInstance&lt;PluginType&gt;()</TD>
+ </TR>
+ <TR>
+ <TD>PluggedType</TD>
+ <TD>The assembly qualified name of the concrete type</TD>
+ </TR>
+ </TABLE>
+ </DIV>
+ <H4>Optional Attributes</H4>
+ <DIV class="schema-table"><TABLE width="100%" border="1" cellPadding="1" cellSpacing="1" ID="Table20">
+ <TR>
+ <TH width="25%">
+ Attribute</TH><TH width="75%">Description</TH></TR>
+ <TR>
+ <TD>Name</TD>
+ <TD>The InstanceKey of the default instance. If unspecified, StructureMap will create a default name. This is mostly for diagnostics.</TD>
+ </TR>
+ <TR>
+ <TD>Scope</TD>
+ <TD>Controls the &quot;scope&quot; of the requested
+ instance.&nbsp; The default value is
+ PerRequest.&nbsp; Valid values are
+ PerRequest, Singleton, ThreadLocal,
+ HttpContext, and Hybrid (uses HttpContext if
+ available, otherwise ThreadLocal)</TD>
+ </TR>
+ </TABLE>
+ </DIV>
+ <BR>
+ <A href="#TopOfPage">Back to Top</A><BR>
+ <BR>
+ <HR>
+
+
+
+
+
+
<A name="Profile"></A>
<H3>&lt;Profile&gt; Element</H3>
<P>Models a named set of overrides for default instances of one or more
@@ -261,7 +331,14 @@ <H4>Sample</H4>
<pre class="xml-sample">&lt;Profile Name="Blue"&gt;
&lt;Override Type="StructureMap.Testing.Widget.Rule" DefaultKey="Blue"/&gt;
&lt;Override Type="StructureMap.Testing.Widget.IWidget" DefaultKey="Blue"/&gt;
-&lt;/Profile&gt;</pre>
+&lt;/Profile&gt;
+
+&lt;Override Type="StructureMap.Testing.Widget.Rule"&gt;
+ &lt;Instance Type="Color" Color="Green"/&gt;
+&lt;/Override&gt;
+
+
+</pre>
<H4>Required Attributes</H4>
<DIV class="schema-table"><TABLE width="100%" border="1" cellPadding="1" cellSpacing="1" ID="Table7">
<TR>
@@ -285,7 +362,16 @@ <H4>Sample</H4>
&lt;Property Name="Attribute" Value="MyDad" /&gt;
&lt;Property Name="Value" Value="10" /&gt;
&lt;/Instance&gt;<BR>
-&lt;/PluginFamily&gt;</pre>
+&lt;/PluginFamily&gt;
+
+* OR *
+
+&lt;PluginFamily&gt;<BR> &lt;Instance Key="Bigger" PluggedType="Assembly Qualified Name"&gt;
+ &lt;Property Name="Attribute" Value="MyDad" /&gt;
+ &lt;Property Name="Value" Value="10" /&gt;
+ &lt;/Instance&gt;<BR>
+&lt;/PluginFamily&gt;
+</pre>
<H4>Required Attributes</H4>
<DIV class="schema-table"><TABLE width="100%" border="1" cellPadding="1" cellSpacing="1" ID="Table8">
<TR>
@@ -308,6 +394,10 @@ <H4>Optional Attributes</H4>
<TR>
<TH width="25%">
Attribute</TH><TH width="75%">Description</TH></TR>
+ <tr>
+ <td>PluggedType</td>
+ <td>An alternative to the Type attribute. Allows you to specify the assembly qualified type of the concrete class directly</td>
+ </tr>
<TR>
<TD>Template</TD>
<TD>When using the
View
@@ -15,7 +15,7 @@
border="0" alt="SourceForge.net Logo"></A>
</p>
<P style="LINE-HEIGHT: 25px">
- <A href="default.htm">Home</A><BR>
+ <A href="Default.htm">Home</A><BR>
<a href="http://sourceforge.net/projects/structuremap">StructureMap on SourceForge</a><br>
<A href="Basic Architecture.htm">Basic Architecture</A><BR>
<A href="Concepts.htm">Concepts</A><BR>
@@ -53,10 +53,26 @@ <h3>Description</h3>
generic flexibility mechanisms. Used judiciously, StructureMap can greatly
enhance the opportunities for code reuse by minimizing direct coupling between
classes and configuration mechanisms.</p>
+ <p>
+ StructureMap is released under the permissive Apache 2 OSS license.&nbsp; You are
+ free to download, modify, or redistribute StructureMap in any way you see fit.</p>
<p>
- New in version 1.0 is the ability to create
- self-diagnostic deployment configurations</p>
- <p>Consider using StructureMap if you…</p>
+ New for version 2.0</p>
+ <ul>
+ <li>Full support for pluggable generic types.&nbsp; IService&lt;T&gt; and Service&lt;T&gt;.&nbsp;
+ Auto wiring support for generic arguments</li>
+ <li>Simpler, more terse Xml configuration.&nbsp; Fewer steps and less Xml.</li>
+ <li>Define Profile instances inline for less Xml</li>
+ <li>New Fluent Interface API for programmatic configuration.&nbsp; If so desired, all configuration can now be done in code at application startup</li>
+ <li>The default StructureMap.config file is now optional</li>
+ <li>Use multiple configuration files additively for easier configuration of composite
+ applications</li>
+ <li>Pluggable ASP.Net UserControl's</li>
+ <li>Inject prototype instances</li>
+ <li>Inject prebuilt singleton instances </li>
+ </ul>
+ <p>
+ Consider using StructureMap if you…</p>
<ul>
<li>
Require significant extensibility
@@ -72,44 +88,14 @@ <h3>Description</h3>
<p>Do not use StructureMap if an application or process requires little
flexibility. The abstraction and indirection afforded by StructureMap is
unnecessary and even harmful in simpler systems or processes.&nbsp;</p>
- <p>New for version 1.0</p>
- <ul>
- <li>New terser <a href="AttributeNormalized.htm">
- Attribute Normalized Xml</a> configuration style</li>
- <li>The ability to <a href="Configuration.htm#Include">
- include secondary configuration files</a></li>
- <li>Set a default profile at the top level of
- configuration</li>
- <li><a href="StructureMapDoctor.htm">
- StructureMapExplorer</a>, a WinForms tool to explore and
- debug StructureMap configurations</li>
- <li>New <a href="NAnt%20Tasks.htm">ancillary NAnt tasks</a>,
- including functionality to create a file &quot;manifest&quot; to
- verify the contents of an application deployment</li>
- <li>New <a href="MementoSources.htm">configuration
- storage choices</a></li>
- <li>New Instance <a href="Scoping.htm">lifecycle scoping
- </a>options</li>
- <li>The &quot;<a href="MementoSources.htm">TemplatedMementoSource</a>&quot;
- option for large instance graphs</li>
- <li>Streamlined codebase with less coupling and greater
- test coverage.&nbsp; Greatly improved diagnostics.</li>
- <li>New methods on ObjectFactory<ul>
- <li>GetAllInstances() - returns all instances of a
- certain type</li>
- <li>WhatDoIHave() - for runtime troubleshooting</li>
- <li>GetInstance(Type, InstanceMemento)</li>
- </ul>
- </li>
- </ul>
<h3>Status</h3>
- <p>StructureMap has been in multiple production systems
+ <p>StructureMap is the oldest IoC/DI tool for .Net development and has been used in multiple production systems
since
- June 2004.&nbsp; The current version 1.0 was released in
- May 2006.&nbsp; StructureMap is maintained and developed by
+ June 2004.&nbsp; The current version 2.0 was released in April 2007.&nbsp; StructureMap is maintained and developed by
<a href="mailto:jeremydmiller@yahoo.com?subject=StructureMap">Jeremy D. Miller</a>,
<a href="http://codebetter.com/blogs/jeremy.miller">The
- Shade Tree Developer</a></p>
+ Shade Tree Developer</a>.&nbsp;
+ </p>
<p>Recent Articles</p>
<ul>
<li>
@@ -123,9 +109,9 @@ <h3>Status</h3>
</ul>
<h3>Feature List</h3>
<UL>
- <LI>
+ <li>
Creates objects using the <a href="http://picocontainer.codehaus.org/Constructor+Injection">
- Constructor Injection pattern</a>
+ Constructor Injection pattern</a> </li>
<LI>
Optionally, attach dependencies and other properties through Setter Injection
(v0.90)
@@ -47,7 +47,7 @@ public override int GetHashCode()
public object Clone()
{
- return this.MemberwiseClone();
+ return MemberwiseClone();
}
}
@@ -152,6 +152,4 @@ public int Value
get { return _Value; }
}
}
-
-
}
@@ -1,5 +1,4 @@
using NUnit.Framework;
-using Rhino.Mocks;
using StructureMap.Configuration;
using StructureMap.Configuration.DSL;
using StructureMap.Graph;
@@ -19,9 +18,10 @@ public void CreateMementoHappyPath()
{
string theUrl = "alskdjf";
- UserControlExpression expression = new UserControlExpression(typeof(IControl), theUrl);
+ UserControlExpression expression = new UserControlExpression(typeof (IControl), theUrl);
- UserControlMemento memento = (UserControlMemento) ((IMementoBuilder) expression).BuildMemento(new PluginGraph());
+ UserControlMemento memento =
+ (UserControlMemento) ((IMementoBuilder) expression).BuildMemento(new PluginGraph());
Assert.IsNotNull(memento);
Assert.AreEqual(theUrl, memento.Url);
@@ -35,10 +35,11 @@ public void CreateMementoHappyPathWithName()
string theUrl = "alskdjf";
string theName = "the name";
- UserControlExpression expression = new UserControlExpression(typeof(IControl), theUrl);
+ UserControlExpression expression = new UserControlExpression(typeof (IControl), theUrl);
expression.WithName(theName);
- UserControlMemento memento = (UserControlMemento)((IMementoBuilder)expression).BuildMemento(new PluginGraph());
+ UserControlMemento memento =
+ (UserControlMemento) ((IMementoBuilder) expression).BuildMemento(new PluginGraph());
Assert.IsNotNull(memento);
Assert.AreEqual(theUrl, memento.Url);
@@ -48,6 +49,5 @@ public void CreateMementoHappyPathWithName()
public interface IControl
{
-
}
-}
+}
@@ -0,0 +1,59 @@
+using NUnit.Framework;
+using Rhino.Mocks;
+using StructureMap.Attributes;
+using StructureMap.Graph;
+using StructureMap.Testing.TestData;
+using StructureMap.Testing.Widget;
+
+namespace StructureMap.Testing.Configuration
+{
+ [TestFixture]
+ public class DefaultInstanceNodeTester
+ {
+ private InstanceManager _manager;
+ private PluginGraph _graph;
+
+ [SetUp]
+ public void SetUp()
+ {
+ _graph = DataMother.GetPluginGraph("DefaultInstance.xml");
+ _manager = new InstanceManager(_graph);
+ }
+
+ [Test]
+ public void CreateTheInferredPluginCorrectly()
+ {
+ // Who needs the Law of Demeter?
+ InstanceMemento memento = _graph.PluginFamilies[typeof (IWidget)].Source.GetAllMementos()[0];
+ Assert.IsNotEmpty(memento.ConcreteKey);
+ Assert.IsNotNull(memento.ConcreteKey);
+ }
+
+ [Test]
+ public void DefaultNameOfRule()
+ {
+ PluginFamily family = _graph.PluginFamilies[typeof (Rule)];
+ Assert.AreEqual("TheBlueOne", family.DefaultInstanceKey);
+ }
+
+ [Test]
+ public void GetTheWidget()
+ {
+ ColorWidget widget = (ColorWidget) _manager.CreateInstance<IWidget>();
+ Assert.AreEqual("Red", widget.Color);
+
+ ColorWidget widget2 = (ColorWidget)_manager.CreateInstance<IWidget>();
+ Assert.AreNotSame(widget, widget2);
+ }
+
+ [Test]
+ public void GetTheRule()
+ {
+ ColorRule rule = (ColorRule) _manager.CreateInstance<Rule>();
+ Assert.AreEqual("Blue", rule.Color);
+
+ ColorRule rule2 = (ColorRule)_manager.CreateInstance<Rule>();
+ Assert.AreSame(rule, rule2);
+ }
+ }
+}
@@ -6,6 +6,7 @@
using StructureMap.Configuration;
using StructureMap.Graph;
using StructureMap.Graph.Configuration;
+using StructureMap.Source;
using StructureMap.Testing.Widget3;
namespace StructureMap.Testing.Configuration
@@ -23,7 +24,7 @@ public class FamilyParserTester
public void SetUp()
{
_builderMock = new DynamicMock(typeof (IGraphBuilder));
- _parser = new FamilyParser((IGraphBuilder) _builderMock.MockInstance);
+ _parser = new FamilyParser((IGraphBuilder) _builderMock.MockInstance, new XmlMementoCreator(XmlMementoStyle.NodeNormalized, XmlConstants.TYPE_ATTRIBUTE, XmlConstants.ATTRIBUTE_STYLE));
_document = new XmlDocument();
_document.LoadXml("<PluginFamily />");
Oops, something went wrong.

0 comments on commit 692d94c

Please sign in to comment.