|
From: <jer...@us...> - 2008-05-03 17:52:07
|
Revision: 88
http://structuremap.svn.sourceforge.net/structuremap/?rev=88&view=rev
Author: jeremydmiller
Date: 2008-05-03 10:52:03 -0700 (Sat, 03 May 2008)
Log Message:
-----------
cleaning up NormalGraphBuilder
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/ConfigurationParser.cs
trunk/Source/StructureMap/Configuration/FamilyParser.cs
trunk/Source/StructureMap/Configuration/IGraphBuilder.cs
trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs
trunk/Source/StructureMap/StructureMapException.resx
trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs
Modified: trunk/Source/StructureMap/Configuration/ConfigurationParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-05-03 04:15:51 UTC (rev 87)
+++ trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-05-03 17:52:03 UTC (rev 88)
@@ -128,10 +128,12 @@
{
TypePath typePath = TypePath.CreateFromXmlNode(familyElement);
- // TODO: Edge case if the PluginType cannot be found
- Type pluginType = typePath.FindType();
+ builder.ConfigureFamily(typePath, delegate(PluginFamily family)
+ {
+ attachInstances(family, familyElement, builder);
+ });
- attachInstances(pluginType, familyElement, builder);
+
}
}
@@ -176,7 +178,7 @@
}
- private void attachInstances(Type pluginType, XmlElement familyElement, IGraphBuilder builder)
+ private void attachInstances(PluginFamily family, XmlElement familyElement, IGraphBuilder builder)
{
foreach (XmlNode instanceNode in familyElement.ChildNodes)
{
@@ -186,7 +188,7 @@
}
InstanceMemento memento = _mementoCreator.CreateMemento(instanceNode);
- builder.RegisterMemento(pluginType, memento);
+ family.AddInstance(memento);
}
}
Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-03 04:15:51 UTC (rev 87)
+++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-03 17:52:03 UTC (rev 88)
@@ -2,6 +2,8 @@
using System.Xml;
using StructureMap.Attributes;
using StructureMap.Graph;
+using StructureMap.Interceptors;
+using StructureMap.Pipeline;
using StructureMap.Source;
namespace StructureMap.Configuration
@@ -29,11 +31,9 @@
InstanceScope scope = findScope(familyElement);
family.SetScopeTo(scope);
- // TODO: Very temporary
- Type pluginType = family.PluginType;
- attachMementoSource(pluginType, familyElement);
- attachPlugins(pluginType, familyElement);
- attachInterceptors(pluginType, familyElement);
+ attachMementoSource(family, familyElement);
+ attachPlugins(family, familyElement);
+ attachInterceptors(family, familyElement);
});
}
@@ -63,21 +63,19 @@
family.DefaultInstanceKey = name;
- _builder.RegisterMemento(pluginType, memento);
+ family.AddInstance(memento);
});
}
public void ParseInstanceElement(XmlElement element)
{
TypePath pluginTypePath = new TypePath(element.GetAttribute(XmlConstants.PLUGIN_TYPE));
- // TODO: gotta throw if type cannot be found
- Type pluginType = pluginTypePath.FindType();
-
- InstanceScope scope = findScope(element);
-
- InstanceMemento memento = _mementoCreator.CreateMemento(element);
-
- _builder.RegisterMemento(pluginType, memento);
+
+ _builder.ConfigureFamily(pluginTypePath, delegate(PluginFamily family)
+ {
+ InstanceMemento memento = _mementoCreator.CreateMemento(element);
+ family.AddInstance(memento);
+ });
}
private InstanceScope findScope(XmlElement familyElement)
@@ -94,17 +92,24 @@
}
// TODO: change to many
- private void attachMementoSource(Type pluginType, XmlElement familyElement)
+ private void attachMementoSource(PluginFamily family, XmlElement familyElement)
{
XmlNode sourceNode = familyElement[XmlConstants.MEMENTO_SOURCE_NODE];
if (sourceNode != null)
{
InstanceMemento sourceMemento = new XmlAttributeInstanceMemento(sourceNode);
- _builder.AttachSource(pluginType, sourceMemento);
+
+ string context = "MementoSource for " + TypePath.GetAssemblyQualifiedName(family.PluginType);
+ _builder.WithSystemObject<MementoSource>(sourceMemento, context, delegate (MementoSource source)
+ {
+ family.AddMementoSource(source);
+ });
+
+
}
}
- private void attachPlugins(Type pluginType, XmlElement familyElement)
+ private void attachPlugins(PluginFamily family, XmlElement familyElement)
{
// TODO: 3.5 lambda cleanup
XmlNodeList pluginNodes = familyElement.SelectNodes(XmlConstants.PLUGIN_NODE);
@@ -113,18 +118,26 @@
TypePath pluginPath = TypePath.CreateFromXmlNode(pluginElement);
string concreteKey = pluginElement.GetAttribute(XmlConstants.CONCRETE_KEY_ATTRIBUTE);
- _builder.AddPlugin(pluginType, pluginPath, concreteKey);
+ string context = "creating a Plugin for " + family.PluginTypeName;
+ _builder.WithType(pluginPath, context, delegate(Type pluggedType)
+ {
+ Plugin plugin =
+ Plugin.CreateExplicitPlugin(pluggedType, concreteKey, "");
+ family.Plugins.Add(plugin);
- foreach (XmlElement setterElement in pluginElement.ChildNodes)
- {
- string setterName = setterElement.GetAttribute("Name");
- _builder.AddSetter(pluginType, concreteKey, setterName);
- }
+ foreach (XmlElement setterElement in pluginElement.ChildNodes)
+ {
+ string setterName = setterElement.GetAttribute("Name");
+ plugin.Setters.Add(setterName);
+ }
+ });
+
+
}
}
// TODO: 3.5 lambda cleanup
- private void attachInterceptors(Type pluginType, XmlElement familyElement)
+ private void attachInterceptors(PluginFamily family, XmlElement familyElement)
{
XmlNode interceptorChainNode = familyElement[XmlConstants.INTERCEPTORS_NODE];
if (interceptorChainNode == null)
@@ -132,10 +145,17 @@
return;
}
+ string context = "Creating an InstanceInterceptor for " + TypePath.GetAssemblyQualifiedName(family.PluginType);
foreach (XmlNode interceptorNode in interceptorChainNode.ChildNodes)
{
XmlAttributeInstanceMemento interceptorMemento = new XmlAttributeInstanceMemento(interceptorNode);
- _builder.AddInterceptor(pluginType, interceptorMemento);
+
+
+ _builder.WithSystemObject<IInstanceInterceptor>(interceptorMemento, context, delegate(IInstanceInterceptor interceptor)
+ {
+ family.AddInterceptor(interceptor);
+ });
+
}
}
}
Modified: trunk/Source/StructureMap/Configuration/IGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-05-03 04:15:51 UTC (rev 87)
+++ trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-05-03 17:52:03 UTC (rev 88)
@@ -24,20 +24,12 @@
void FinishFamilies();
PluginGraph CreatePluginGraph();
-
- // All of these need to DIE!
- //void AddPluginFamily(Type pluginType, string defaultKey, InstanceScope scope);
- void AttachSource(Type pluginType, InstanceMemento sourceMemento);
- void AttachSource(Type pluginType, MementoSource source);
- Plugin AddPlugin(Type pluginType, TypePath pluginPath, string concreteKey);
- SetterProperty AddSetter(Type pluginType, string concreteKey, string setterName);
- void AddInterceptor(Type pluginType, InstanceMemento interceptorMemento);
- void RegisterMemento(Type pluginType, InstanceMemento memento);
-
-
-
IProfileBuilder GetProfileBuilder();
void ConfigureFamily(TypePath pluginTypePath, Action<PluginFamily> action);
+
+ void WithSystemObject<T>(InstanceMemento memento, string context, Action<T> action);
+ void WithType(TypePath path, string context, Action<Type> action);
}
+
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-05-03 04:15:51 UTC (rev 87)
+++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-05-03 17:52:03 UTC (rev 88)
@@ -64,116 +64,69 @@
public void StartFamilies()
{
+ // TODO: is this a problem here?
_systemGraph.Seal();
- _systemInstanceManager = new InstanceManager(_systemGraph);
}
- // TODO: Cleanup
- //public void AddPluginFamily(Type pluginType, string defaultKey, InstanceScope scope)
- //{
- // PluginFamily family = _pluginGraph.FindFamily(pluginType);
+ public IProfileBuilder GetProfileBuilder()
+ {
+ return new ProfileBuilder(_pluginGraph);
+ }
- // // Xml configuration wins
- // family.DefaultInstanceKey = defaultKey;
- // family.SetScopeTo(scope);
- //}
-
- public virtual void AttachSource(Type pluginType, InstanceMemento sourceMemento)
+ public void ConfigureFamily(TypePath pluginTypePath, Action<PluginFamily> action)
{
try
{
- MementoSource source = (MementoSource) buildSystemObject(typeof (MementoSource), sourceMemento);
- AttachSource(pluginType, source);
+ Type pluginType = pluginTypePath.FindType();
+ PluginFamily family = _pluginGraph.FindFamily(pluginType);
+ action(family);
}
catch (Exception ex)
{
- // TODO: put error in PluginGraph
- throw new StructureMapException(120, ex, TypePath.GetAssemblyQualifiedName(pluginType));
+ _pluginGraph.Log.RegisterError(103, ex, pluginTypePath.ClassName, pluginTypePath.AssemblyName);
}
}
- public void AttachSource(Type pluginType, MementoSource source)
- {
- PluginFamily family = _pluginGraph.PluginFamilies[pluginType];
- family.AddMementoSource(source);
- }
+ #endregion
- public Plugin AddPlugin(Type pluginType, TypePath pluginPath, string concreteKey)
+ private object buildSystemObject(Type type, InstanceMemento memento)
{
- // TODO: Make this go through PluginGraph.FindFamily()
- PluginFamily family = _pluginGraph.PluginFamilies[pluginType];
- if (family == null)
- {
- string message =
- string.Format("Could not find a PluginFamily for {0}", pluginType.AssemblyQualifiedName);
+ Instance instance = memento.ReadInstance(_systemGraph, type);
- // TODO: put error in PluginGraph
- throw new ApplicationException(message);
+ if (_systemInstanceManager == null)
+ {
+ _systemInstanceManager = new InstanceManager(_systemGraph);
}
- Plugin plugin = new Plugin(pluginPath, concreteKey);
- family.Plugins.Add(plugin);
-
- return plugin;
+ return _systemInstanceManager.CreateInstance(type, instance);
}
- public SetterProperty AddSetter(Type pluginType, string concreteKey, string setterName)
- {
- // TODO: Make this go through PluginGraph.FindFamily()
- PluginFamily family = _pluginGraph.PluginFamilies[pluginType];
- Plugin plugin = family.Plugins[concreteKey];
- return plugin.Setters.Add(setterName);
- }
- public virtual void AddInterceptor(Type pluginType, InstanceMemento interceptorMemento)
+ public void WithSystemObject<T>(InstanceMemento memento, string context, Action<T> action)
{
- PluginFamily family = _pluginGraph.PluginFamilies[pluginType];
try
{
- IInstanceInterceptor interceptor =
- (IInstanceInterceptor)
- buildSystemObject(typeof (IInstanceInterceptor), interceptorMemento);
-
- family.AddInterceptor(interceptor);
+ T systemObject = (T) buildSystemObject(typeof (T), memento);
+ action(systemObject);
}
catch (Exception ex)
{
- // TODO: put error in PluginGraph
- throw new StructureMapException(121, ex, TypePath.GetAssemblyQualifiedName(pluginType));
+ _pluginGraph.Log.RegisterError(130, ex, context);
}
}
- public void RegisterMemento(Type pluginType, InstanceMemento memento)
- {
- PluginFamily family = _pluginGraph.FindFamily(pluginType);
- family.AddInstance(memento);
- }
- public IProfileBuilder GetProfileBuilder()
+ public void WithType(TypePath path, string context, Action<Type> action)
{
- return new ProfileBuilder(_pluginGraph);
- }
-
- public void ConfigureFamily(TypePath pluginTypePath, Action<PluginFamily> action)
- {
try
{
- Type pluginType = pluginTypePath.FindType();
- PluginFamily family = _pluginGraph.FindFamily(pluginType);
- action(family);
+ Type type = path.FindType();
+ action(type);
}
catch (Exception ex)
{
- _pluginGraph.Log.RegisterError(103, ex, pluginTypePath.ClassName, pluginTypePath.AssemblyName);
+ _pluginGraph.Log.RegisterError(131, ex, path.AssemblyQualifiedName, context);
}
}
-
- #endregion
-
- private object buildSystemObject(Type type, InstanceMemento memento)
- {
- Instance instance = memento.ReadInstance(_systemGraph, type);
- return _systemInstanceManager.CreateInstance(type, instance);
- }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2008-05-03 04:15:51 UTC (rev 87)
+++ trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2008-05-03 17:52:03 UTC (rev 88)
@@ -85,12 +85,15 @@
memento.InstanceKey = key;
TypePath familyPath = new TypePath(fullName);
- // TODO: failure point
- Type pluginType = familyPath.FindType();
- _graphBuilder.RegisterMemento(pluginType, memento);
+ _graphBuilder.ConfigureFamily(familyPath, delegate(PluginFamily family)
+ {
+ family.AddInstance(memento);
+ function(fullName, key);
+ });
- function(fullName, key);
+
+
}
private XmlNodeList findNodes(string nodeName)
Modified: trunk/Source/StructureMap/StructureMapException.resx
===================================================================
--- trunk/Source/StructureMap/StructureMapException.resx 2008-05-03 04:15:51 UTC (rev 87)
+++ trunk/Source/StructureMap/StructureMapException.resx 2008-05-03 17:52:03 UTC (rev 88)
@@ -267,4 +267,10 @@
<data name="107" xml:space="preserve">
<value>Type named {0} cannot be resolved. Make sure the type is defined in Assembly Qualified Name form</value>
</data>
+ <data name="130" xml:space="preserve">
+ <value>System object for {0} could not be created</value>
+ </data>
+ <data name="131" xml:space="preserve">
+ <value>Requested type {0} could not be found while {1}</value>
+ </data>
</root>
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2008-05-03 04:15:51 UTC (rev 87)
+++ trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2008-05-03 17:52:03 UTC (rev 88)
@@ -42,7 +42,7 @@
PluginFamily family = builder.PluginGraph.FindFamily(thePluginType);
family.DefaultInstanceKey = _memento.InstanceKey;
- builder.RegisterMemento(thePluginType, _memento);
+ family.AddInstance(_memento);
PluginGraph graph = builder.CreatePluginGraph();
InstanceManager manager = new InstanceManager(graph);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|