|
From: <jer...@us...> - 2008-08-10 15:57:35
|
Revision: 134
http://structuremap.svn.sourceforge.net/structuremap/?rev=134&view=rev
Author: jeremydmiller
Date: 2008-08-10 15:57:29 +0000 (Sun, 10 Aug 2008)
Log Message:
-----------
refactoring away Plugin a bit
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
trunk/Source/StructureMap/Configuration/FamilyParser.cs
trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs
trunk/Source/StructureMap/Graph/Plugin.cs
trunk/Source/StructureMap/Graph/PluginCollection.cs
trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs
trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs
trunk/Source/StructureMap.Testing/Graph/SetterInjectionEmittingTester.cs
trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs
trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs
Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-08-10 04:18:32 UTC (rev 133)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-08-10 15:57:29 UTC (rev 134)
@@ -155,9 +155,8 @@
_alterations.Add(
family =>
{
- Plugin plugin = new Plugin(typeof (CONCRETETYPE));
- plugin.ConcreteKey = instanceName;
- family.AddPlugin(plugin);
+ ConfiguredInstance instance = new ConfiguredInstance(typeof(CONCRETETYPE)).WithName(instanceName);
+ family.AddInstance(instance);
}
);
Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-08-10 04:18:32 UTC (rev 133)
+++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-08-10 15:57:29 UTC (rev 134)
@@ -109,10 +109,9 @@
string context = "creating a Plugin for " + family.PluginType.AssemblyQualifiedName;
_builder.WithType(pluginPath, context, pluggedType =>
{
- Plugin plugin = new Plugin(pluggedType, concreteKey);
- family.AddPlugin(plugin);
+ Plugin plugin = family.AddPlugin(pluggedType, concreteKey);
- pluginElement.ForTextInChild("Setter/@Name").Do(prop => plugin.Setters.Add(prop));
+ pluginElement.ForTextInChild("Setter/@Name").Do(prop => plugin.Setters.MarkSetterAsMandatory(prop));
});
}
Modified: trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs
===================================================================
--- trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-08-10 04:18:32 UTC (rev 133)
+++ trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-08-10 15:57:29 UTC (rev 134)
@@ -109,7 +109,7 @@
{
if (CanBePluggedIntoGenericType(baseFamily.PluginType, plugin.PluggedType, templateTypes))
{
- Plugin templatedPlugin = CreateTemplatedClone(plugin, templateTypes);
+ Plugin templatedPlugin = plugin.CreateTemplatedClone(templateTypes);
templatedFamily.AddPlugin(templatedPlugin);
}
});
@@ -128,28 +128,7 @@
}
- public static Plugin CreateTemplatedClone(Plugin plugin, params Type[] types)
- {
- Type templatedType;
- if (plugin.PluggedType.IsGenericType)
- {
- templatedType = plugin.PluggedType.MakeGenericType(types);
- }
- else
- {
- templatedType = plugin.PluggedType;
- }
- Plugin templatedPlugin = new Plugin(templatedType, plugin.ConcreteKey);
- foreach (SetterProperty setter in plugin.Setters)
- {
- templatedPlugin.Setters.Add(setter.Name);
- }
-
- return templatedPlugin;
- }
-
-
public static bool CanBePluggedIntoGenericType(Type pluginType, Type pluggedType, params Type[] templateTypes)
{
bool isValid = true;
Modified: trunk/Source/StructureMap/Graph/Plugin.cs
===================================================================
--- trunk/Source/StructureMap/Graph/Plugin.cs 2008-08-10 04:18:32 UTC (rev 133)
+++ trunk/Source/StructureMap/Graph/Plugin.cs 2008-08-10 15:57:29 UTC (rev 134)
@@ -140,5 +140,19 @@
{
return _setters.OptionalCount > 0;
}
+
+ public Plugin CreateTemplatedClone(Type[] types)
+ {
+ Type templatedType = _pluggedType.IsGenericType ? _pluggedType.MakeGenericType(types) : _pluggedType;
+
+ Plugin templatedPlugin = new Plugin(templatedType, ConcreteKey);
+
+ foreach (SetterProperty setter in Setters)
+ {
+ templatedPlugin.Setters.MarkSetterAsMandatory(setter.Name);
+ }
+
+ return templatedPlugin;
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/PluginCollection.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginCollection.cs 2008-08-10 04:18:32 UTC (rev 133)
+++ trunk/Source/StructureMap/Graph/PluginCollection.cs 2008-08-10 15:57:29 UTC (rev 134)
@@ -81,25 +81,12 @@
public void Add(Plugin plugin)
{
- if (_plugins.Has(plugin.PluggedType))
- {
- Plugin peer = this[plugin.PluggedType];
- peer.MergeSetters(plugin);
-
- // Last ConcreteKey wins
- peer.ConcreteKey = plugin.ConcreteKey;
-
- return;
- }
-
-
// Reject if the PluggedType cannot be upcast to the PluginType
if (!TypeRules.CanBeCast(_family.PluginType, plugin.PluggedType))
{
throw new StructureMapException(104, plugin.PluggedType, _family.PluginType);
}
-
_plugins.Store(plugin.PluggedType, plugin);
}
Modified: trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs
===================================================================
--- trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs 2008-08-10 04:18:32 UTC (rev 133)
+++ trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs 2008-08-10 15:57:29 UTC (rev 134)
@@ -55,7 +55,7 @@
#endregion
- public SetterProperty Add(string propertyName)
+ public SetterProperty MarkSetterAsMandatory(string propertyName)
{
var setter = _properties.Find(p => p.Property.Name == propertyName);
if (setter == null)
@@ -87,7 +87,7 @@
{
if (!IsMandatory(setter.Name))
{
- Add(setter.Name);
+ MarkSetterAsMandatory(setter.Name);
}
}
}
Modified: trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2008-08-10 04:18:32 UTC (rev 133)
+++ trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2008-08-10 15:57:29 UTC (rev 134)
@@ -63,13 +63,13 @@
[Test]
public void CanCreatePluginForGenericTypeWithGenericParameter()
{
- Plugin plugin = new Plugin(typeof (GenericService<int>), "key");
+ Plugin plugin = new Plugin(typeof (GenericService<int>));
}
[Test]
public void CanCreatePluginForGenericTypeWithoutGenericParameter()
{
- Plugin plugin = new Plugin(typeof (GenericService<>), "key");
+ Plugin plugin = new Plugin(typeof (GenericService<>));
}
@@ -89,7 +89,7 @@
{
PluginGraph graph = new PluginGraph();
PluginFamily family = graph.FindFamily(typeof (ComplexType<int>));
- family.AddPlugin(new Plugin(typeof (ComplexType<int>), "complex"));
+ family.AddPlugin(typeof (ComplexType<int>), "complex");
Container manager = new Container(graph);
Modified: trunk/Source/StructureMap.Testing/Graph/SetterInjectionEmittingTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/SetterInjectionEmittingTester.cs 2008-08-10 04:18:32 UTC (rev 133)
+++ trunk/Source/StructureMap.Testing/Graph/SetterInjectionEmittingTester.cs 2008-08-10 15:57:29 UTC (rev 134)
@@ -94,8 +94,7 @@
{
PluginGraph graph = new PluginGraph();
PluginFamily family = graph.FindFamily(typeof (IGridColumn));
- Plugin plugin = new Plugin(typeof (EnumGridColumn));
- family.AddPlugin(plugin);
+ family.AddPlugin(typeof(EnumGridColumn));
family.AddInstance(_source.GetMemento("Enum"));
@@ -111,8 +110,7 @@
{
PluginGraph graph = new PluginGraph();
PluginFamily family = graph.FindFamily(typeof (IGridColumn));
- Plugin plugin = new Plugin(typeof (LongGridColumn));
- family.AddPlugin(plugin);
+ family.AddPlugin(typeof(LongGridColumn));
InstanceMemento memento = _source.GetMemento("Long");
long count = long.Parse(memento.GetProperty("Count"));
@@ -130,8 +128,7 @@
{
PluginGraph graph = new PluginGraph();
PluginFamily family = graph.FindFamily(typeof (IGridColumn));
- Plugin plugin = new Plugin(typeof (StringGridColumn));
- family.AddPlugin(plugin);
+ family.AddPlugin(typeof(StringGridColumn));
InstanceMemento memento = _source.GetMemento("String");
family.AddInstance(memento);
Modified: trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs 2008-08-10 04:18:32 UTC (rev 133)
+++ trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs 2008-08-10 15:57:29 UTC (rev 134)
@@ -117,11 +117,11 @@
Plugin plugin = new Plugin(typeof(OtherGridColumn));
plugin.Setters.OptionalCount.ShouldEqual(7);
- plugin.Setters.Add("Widget");
- plugin.Setters.Add("FontStyle");
- plugin.Setters.Add("ColumnName");
- plugin.Setters.Add("Rules");
- plugin.Setters.Add("WrapLines");
+ plugin.Setters.MarkSetterAsMandatory("Widget");
+ plugin.Setters.MarkSetterAsMandatory("FontStyle");
+ plugin.Setters.MarkSetterAsMandatory("ColumnName");
+ plugin.Setters.MarkSetterAsMandatory("Rules");
+ plugin.Setters.MarkSetterAsMandatory("WrapLines");
Assert.AreEqual(2, plugin.Setters.OptionalCount);
Assert.AreEqual(5, plugin.Setters.MandatoryCount);
@@ -210,14 +210,14 @@
public void TryToAddANonExistentSetterProperty()
{
Plugin plugin = new Plugin(typeof (BasicGridColumn), "Basic");
- plugin.Setters.Add("NonExistentPropertyName");
+ plugin.Setters.MarkSetterAsMandatory("NonExistentPropertyName");
}
[Test, ExpectedException(typeof (StructureMapException))]
public void TryToAddASetterPropertyThatDoesNotHaveASetter()
{
Plugin plugin = new Plugin(typeof (BasicGridColumn), "Basic");
- plugin.Setters.Add("HeaderText");
+ plugin.Setters.MarkSetterAsMandatory("HeaderText");
}
}
Modified: trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs 2008-08-10 04:18:32 UTC (rev 133)
+++ trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs 2008-08-10 15:57:29 UTC (rev 134)
@@ -176,9 +176,8 @@
public void ReadChildArrayProperty()
{
PluginGraph graph = new PluginGraph();
- Plugin plugin = new Plugin(typeof (ComplexRule));
- graph.FindFamily(typeof (Rule)).AddPlugin(plugin);
+ graph.FindFamily(typeof(Rule)).AddPlugin(typeof(ComplexRule));
MemoryInstanceMemento memento = ComplexRule.GetMemento();
memento.SetProperty(XmlConstants.PLUGGED_TYPE, typeof (ComplexRule).AssemblyQualifiedName);
@@ -202,9 +201,8 @@
public void ReadChildProperty_child_property_is_defined_build_child()
{
PluginGraph graph = new PluginGraph();
- Plugin plugin = new Plugin(typeof (ComplexRule));
- graph.FindFamily(typeof(Rule)).AddPlugin(plugin);
+ graph.FindFamily(typeof(Rule)).AddPlugin(typeof(ComplexRule));
MemoryInstanceMemento memento = ComplexRule.GetMemento();
memento.SetProperty(XmlConstants.PLUGGED_TYPE, typeof (ComplexRule).AssemblyQualifiedName);
@@ -221,9 +219,8 @@
public void ReadPrimitivePropertiesHappyPath()
{
PluginGraph graph = new PluginGraph();
- Plugin plugin = new Plugin(typeof (ComplexRule));
- graph.FindFamily(typeof(Rule)).AddPlugin(plugin);
+ graph.FindFamily(typeof(Rule)).AddPlugin(typeof(ComplexRule));
MemoryInstanceMemento memento = ComplexRule.GetMemento();
memento.SetProperty(XmlConstants.PLUGGED_TYPE, typeof (ComplexRule).AssemblyQualifiedName);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|