|
From: <jer...@us...> - 2008-05-04 02:28:20
|
Revision: 91
http://structuremap.svn.sourceforge.net/structuremap/?rev=91&view=rev
Author: jeremydmiller
Date: 2008-05-03 19:28:19 -0700 (Sat, 03 May 2008)
Log Message:
-----------
cleaned up PluginGraphBuilder
Modified Paths:
--------------
trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs
trunk/Source/StructureMap/Configuration/FamilyParser.cs
trunk/Source/StructureMap/Configuration/IGraphBuilder.cs
trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/PluginGraphBuilder.cs
trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs
Modified: trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs
===================================================================
--- trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-05-04 01:29:30 UTC (rev 90)
+++ trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-05-04 02:28:19 UTC (rev 91)
@@ -143,7 +143,8 @@
}
MementoSource source = CreateSource(exportedType);
- PluginFamily family = new PluginFamily(exportedType, DefaultKey);
+ PluginFamily family = new PluginFamily(exportedType);
+ family.DefaultInstanceKey = DefaultKey;
family.AddMementoSource(source);
family.SetScopeTo(Scope);
Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-04 01:29:30 UTC (rev 90)
+++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-04 02:28:19 UTC (rev 91)
@@ -19,7 +19,6 @@
_mementoCreator = mementoCreator;
}
- // TODO: Standard way in this class to get a PluginType, Maybe more into IGraphBuilder
public void ParseFamily(XmlElement familyElement)
{
TypePath typePath = TypePath.CreateFromXmlNode(familyElement);
@@ -40,7 +39,6 @@
public void ParseDefaultElement(XmlElement element)
{
TypePath pluginTypePath = new TypePath(element.GetAttribute(XmlConstants.PLUGIN_TYPE));
- // TODO: Gotta throw exception if the type cannot be found
_builder.ConfigureFamily(pluginTypePath,
Modified: trunk/Source/StructureMap/Configuration/IGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-05-04 01:29:30 UTC (rev 90)
+++ trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-05-04 02:28:19 UTC (rev 91)
@@ -22,7 +22,6 @@
void StartFamilies();
void FinishFamilies();
- PluginGraph CreatePluginGraph();
IProfileBuilder GetProfileBuilder();
Modified: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-05-04 01:29:30 UTC (rev 90)
+++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-05-04 02:28:19 UTC (rev 91)
@@ -1,15 +1,11 @@
using System;
using System.Reflection;
-using StructureMap.Attributes;
using StructureMap.Configuration.DSL;
using StructureMap.Graph;
using StructureMap.Pipeline;
namespace StructureMap.Configuration
{
- // TODO: Kill in 3.5
- public delegate void Action<T>(T subject);
-
public class NormalGraphBuilder : IGraphBuilder
{
private readonly PluginGraph _pluginGraph;
@@ -18,9 +14,13 @@
private InstanceManager _systemInstanceManager;
- public NormalGraphBuilder(Registry[] registries)
+ public NormalGraphBuilder(Registry[] registries) : this(registries, new PluginGraph())
{
- _pluginGraph = new PluginGraph();
+ }
+
+ public NormalGraphBuilder(Registry[] registries, PluginGraph pluginGraph)
+ {
+ _pluginGraph = pluginGraph;
foreach (Registry registry in registries)
{
registry.ConfigurePluginGraph(_pluginGraph);
@@ -37,11 +37,6 @@
_pluginGraph.Seal();
}
- [Obsolete("Do away?")] public PluginGraph CreatePluginGraph()
- {
- return _pluginGraph;
- }
-
public PluginGraph SystemGraph
{
get { return _systemGraph; }
@@ -87,21 +82,7 @@
}
}
- #endregion
- private object buildSystemObject(Type type, InstanceMemento memento)
- {
- Instance instance = memento.ReadInstance(_systemGraph, type);
-
- if (_systemInstanceManager == null)
- {
- _systemInstanceManager = new InstanceManager(_systemGraph);
- }
-
- return _systemInstanceManager.CreateInstance(type, instance);
- }
-
-
public void WithSystemObject<T>(InstanceMemento memento, string context, Action<T> action)
{
try
@@ -128,5 +109,19 @@
_pluginGraph.Log.RegisterError(131, ex, path.AssemblyQualifiedName, context);
}
}
+
+ #endregion
+
+ private object buildSystemObject(Type type, InstanceMemento memento)
+ {
+ Instance instance = memento.ReadInstance(_systemGraph, type);
+
+ if (_systemInstanceManager == null)
+ {
+ _systemInstanceManager = new InstanceManager(_systemGraph);
+ }
+
+ return _systemInstanceManager.CreateInstance(type, instance);
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-04 01:29:30 UTC (rev 90)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-04 02:28:19 UTC (rev 91)
@@ -27,24 +27,18 @@
private List<Instance> _instances = new List<Instance>();
private IBuildPolicy _buildPolicy = new BuildPolicy();
- #region constructors
- public PluginFamily(Type pluginType, string defaultInstanceKey)
- {
- _pluginType = pluginType;
- _pluginTypeName = TypePath.GetAssemblyQualifiedName(_pluginType);
- _defaultKey = defaultInstanceKey;
- _plugins = new PluginCollection(this);
- }
-
// TODO: Need to unit test the scope from the attribute
/// <summary>
/// Testing constructor
/// </summary>
/// <param name="pluginType"></param>
- public PluginFamily(Type pluginType) :
- this(pluginType, PluginFamilyAttribute.GetDefaultKey(pluginType))
+ public PluginFamily(Type pluginType)
{
+ _pluginType = pluginType;
+ _pluginTypeName = TypePath.GetAssemblyQualifiedName(_pluginType);
+ _plugins = new PluginCollection(this);
+
// TODO -- Merge functionality with PluginFamilyAttribute
PluginFamilyAttribute attribute = PluginFamilyAttribute.GetAttribute(pluginType);
if (attribute != null)
@@ -61,8 +55,6 @@
set { _parent = value; }
}
- #endregion
-
public InstanceInterceptor InstanceInterceptor
{
get { return _instanceInterceptor; }
@@ -103,12 +95,13 @@
return templatedFamily;
}
+ // TODO: Move this into TypeScanner
/// <summary>
/// Finds Plugin's that match the PluginType from the assembly and add to the internal
/// collection of Plugin's
/// </summary>
/// <param name="assembly"></param>
- public Plugin[] FindPlugins(AssemblyGraph assembly)
+ [Obsolete] public Plugin[] FindPlugins(AssemblyGraph assembly)
{
Predicate<Type> pluggedTypeFilter =
delegate(Type type) { return Plugin.IsAnExplicitPlugin(PluginType, type); };
@@ -143,17 +136,13 @@
_mementoList.AddRange(source.GetAllMementos());
}
- public InstanceMemento[] GetAllMementos()
- {
- return _mementoList.ToArray();
- }
-
// For testing
public InstanceMemento GetMemento(string instanceKey)
{
return _mementoList.Find(delegate(InstanceMemento m) { return m.InstanceKey == instanceKey; });
}
+ // TODO -- Move out into TypeScanner
public void DiscoverImplicitInstances()
{
List<Plugin> list = _plugins.FindAutoFillablePlugins();
Modified: trunk/Source/StructureMap/PluginGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/PluginGraphBuilder.cs 2008-05-04 01:29:30 UTC (rev 90)
+++ trunk/Source/StructureMap/PluginGraphBuilder.cs 2008-05-04 02:28:19 UTC (rev 91)
@@ -32,9 +32,9 @@
#endregion
+ private readonly ConfigurationParser[] _parsers;
private readonly Registry[] _registries = new Registry[0];
private PluginGraph _graph;
- private ConfigurationParser[] _parsers;
#region constructors
@@ -47,38 +47,9 @@
{
_parsers = parsers;
_registries = registries;
+ _graph = new PluginGraph();
}
-
- /// <summary>
- /// Creates a PluginGraphBuilder that reads configuration from the filePath
- /// </summary>
- /// <param name="filePath">The path to the configuration file</param>
- [Obsolete("Elimating direct usage of PluginGraphBuilder")]
- public PluginGraphBuilder(string filePath)
- {
- try
- {
- XmlDocument doc = new XmlDocument();
- doc.Load(filePath);
-
- _parsers = ConfigurationParser.GetParsers(doc, filePath);
- }
- catch (Exception ex)
- {
- throw new StructureMapException(100, filePath, ex);
- }
- }
-
- /// <summary>
- /// Default constructor reads configuration from the StructureMap.config file
- /// in the application folder
- /// </summary>
- [Obsolete("Elimating direct usage of PluginGraphBuilder")]
- public PluginGraphBuilder() : this(StructureMapConfiguration.GetStructureMapConfigurationPath())
- {
- }
-
#endregion
#region IPluginGraphSource Members
@@ -90,57 +61,33 @@
/// <returns></returns>
public PluginGraph Build()
{
- NormalGraphBuilder graphBuilder = new NormalGraphBuilder(_registries);
- PluginGraph pluginGraph = buildPluginGraph(graphBuilder);
- return pluginGraph;
+ NormalGraphBuilder graphBuilder = new NormalGraphBuilder(_registries, _graph);
+ buildPluginGraph(graphBuilder);
+ return _graph;
}
#endregion
- private PluginGraph buildPluginGraph(IGraphBuilder graphBuilder)
+ private void forAllParsers(Action<ConfigurationParser> action)
{
- readAssemblies(graphBuilder);
-
- readFamilies(graphBuilder);
-
foreach (ConfigurationParser parser in _parsers)
{
- parser.ParseInstances(graphBuilder);
+ action(parser);
}
-
- _graph = graphBuilder.CreatePluginGraph();
-
- return _graph;
}
- private void readInstanceDefaults(IGraphBuilder graphBuilder)
+ private void buildPluginGraph(IGraphBuilder graphBuilder)
{
- foreach (ConfigurationParser parser in _parsers)
- {
- parser.ParseProfilesAndMachines(graphBuilder);
- }
- }
+ forAllParsers(delegate(ConfigurationParser p) { p.ParseAssemblies(graphBuilder); });
- private void readFamilies(IGraphBuilder graphBuilder)
- {
graphBuilder.StartFamilies();
- foreach (ConfigurationParser parser in _parsers)
- {
- parser.ParseFamilies(graphBuilder);
- }
-
- readInstanceDefaults(graphBuilder);
-
-
+ forAllParsers(delegate(ConfigurationParser p)
+ {
+ p.ParseFamilies(graphBuilder);
+ p.ParseProfilesAndMachines(graphBuilder);
+ p.ParseInstances(graphBuilder);
+ });
}
-
- private void readAssemblies(IGraphBuilder graphBuilder)
- {
- foreach (ConfigurationParser parser in _parsers)
- {
- parser.ParseAssemblies(graphBuilder);
- }
- }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs 2008-05-04 01:29:30 UTC (rev 90)
+++ trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs 2008-05-04 02:28:19 UTC (rev 91)
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using NUnit.Framework;
using StructureMap.Graph;
+using StructureMap.Pipeline;
using StructureMap.Testing.TestData;
using StructureMap.Testing.Widget;
@@ -27,8 +28,10 @@
public void CreateTheInferredPluginCorrectly()
{
// Who needs the Law of Demeter?
- InstanceMemento[] mementoArray = _graph.FindFamily(typeof (IWidget)).GetAllMementos();
- Assert.AreEqual(4, mementoArray.Length);
+ _graph.Seal();
+
+ Instance[] instances = _graph.FindFamily(typeof (IWidget)).GetAllInstances();
+ Assert.AreEqual(4, instances.Length);
}
[Test]
Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-05-04 01:29:30 UTC (rev 90)
+++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-05-04 02:28:19 UTC (rev 91)
@@ -16,7 +16,8 @@
[Test]
public void AddAPluggedType()
{
- PluginFamily family = new PluginFamily(typeof (IWidget), "DefaultKey");
+ PluginFamily family = new PluginFamily(typeof (IWidget));
+ family.DefaultInstanceKey = "DefaultKey";
family.Plugins.Add(typeof (NotPluggableWidget), "NotPlugged");
Assert.AreEqual(1, family.Plugins.Count, "Plugin Count");
@@ -25,7 +26,8 @@
[Test, ExpectedException(typeof (StructureMapException))]
public void AddAWrongType()
{
- PluginFamily family = new PluginFamily(typeof (IWidget), "DefaultKey");
+ PluginFamily family = new PluginFamily(typeof(IWidget));
+ family.DefaultInstanceKey = "DefaultKey";
family.Plugins.Add(typeof (Rule), "Rule");
}
@@ -33,7 +35,8 @@
[Test]
public void GetPlugins()
{
- PluginFamily family = new PluginFamily(typeof (IWidget), "DefaultKey");
+ PluginFamily family = new PluginFamily(typeof(IWidget));
+ family.DefaultInstanceKey = "DefaultKey";
AssemblyGraph graph = new AssemblyGraph("StructureMap.Testing.Widget");
family.FindPlugins(graph);
Modified: trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2008-05-04 01:29:30 UTC (rev 90)
+++ trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2008-05-04 02:28:19 UTC (rev 91)
@@ -44,7 +44,7 @@
family.AddInstance(_memento);
- PluginGraph graph = builder.CreatePluginGraph();
+ PluginGraph graph = builder.PluginGraph;
InstanceManager manager = new InstanceManager(graph);
StubbedGateway gateway = (StubbedGateway) manager.CreateInstance(typeof (IGateway), _memento.InstanceKey);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|