|
From: <jer...@us...> - 2007-03-27 11:18:51
|
Revision: 31
http://structuremap.svn.sourceforge.net/structuremap/?rev=31&view=rev
Author: jeremydmiller
Date: 2007-03-27 04:18:48 -0700 (Tue, 27 Mar 2007)
Log Message:
-----------
Integrated Registry into ObjectFactory
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/DSL/Registry.cs
trunk/Source/StructureMap/Configuration/DiagnosticGraphBuilder.cs
trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
trunk/Source/StructureMap/Configuration/Tokens/FamilyToken.cs
trunk/Source/StructureMap/Graph/AssemblyGraph.cs
trunk/Source/StructureMap/Graph/PluginGraph.cs
trunk/Source/StructureMap/PluginGraphBuilder.cs
trunk/Source/StructureMap/StructureMapConfiguration.cs
trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/ScanAssembliesTester.cs
trunk/Source/StructureMap.Testing/Configuration/DiagnosticGraphBuilderTester.cs
trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs
trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs
Added Paths:
-----------
trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs
trunk/Source/StructureMap.Testing.Widget5/WidgetRegistry.cs
Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-03-26 14:31:28 UTC (rev 30)
+++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-03-27 11:18:48 UTC (rev 31)
@@ -9,7 +9,7 @@
private List<IExpression> _expressions = new List<IExpression>();
private PluginGraph _graph;
- public Registry(PluginGraph graph)
+ public Registry(PluginGraph graph) : this()
{
_graph = graph;
}
@@ -17,6 +17,7 @@
public Registry()
{
_graph = new PluginGraph();
+ configure();
}
@@ -28,12 +29,12 @@
// no-op;
}
- protected void addExpression(IExpression expression)
+ protected internal void addExpression(IExpression expression)
{
_expressions.Add(expression);
}
- private void configurePluginGraph(PluginGraph graph)
+ internal void ConfigurePluginGraph(PluginGraph graph)
{
foreach (IExpression expression in _expressions)
{
@@ -44,17 +45,10 @@
public void Dispose()
{
- configurePluginGraph(_graph);
+ ConfigurePluginGraph(_graph);
}
- public ScanAssembliesExpression ScanAssemblies()
- {
- ScanAssembliesExpression expression = new ScanAssembliesExpression();
- addExpression(expression);
- return expression;
- }
-
public CreatePluginFamilyExpression BuildInstancesOf<T>()
{
CreatePluginFamilyExpression expression = new CreatePluginFamilyExpression(typeof (T));
@@ -65,7 +59,7 @@
public IInstanceManager BuildInstanceManager()
{
- configurePluginGraph(_graph);
+ ConfigurePluginGraph(_graph);
_graph.ReadDefaults();
return new InstanceManager(_graph);
}
@@ -116,5 +110,20 @@
return expression;
}
+
+ public static bool IsPublicRegistry(Type type)
+ {
+ if (!typeof(Registry).IsAssignableFrom(type))
+ {
+ return false;
+ }
+
+ if (type.IsInterface || type.IsAbstract || type.IsGenericType)
+ {
+ return false;
+ }
+
+ return (type.GetConstructor(new Type[0]) != null);
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/DiagnosticGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DiagnosticGraphBuilder.cs 2007-03-26 14:31:28 UTC (rev 30)
+++ trunk/Source/StructureMap/Configuration/DiagnosticGraphBuilder.cs 2007-03-27 11:18:48 UTC (rev 31)
@@ -1,5 +1,6 @@
using System;
using StructureMap.Attributes;
+using StructureMap.Configuration.DSL;
using StructureMap.Configuration.Tokens;
using StructureMap.Graph;
using StructureMap.Graph.Configuration;
@@ -14,9 +15,9 @@
private PluginGraphReport _systemReport;
private PluginGraphReport _report;
- public DiagnosticGraphBuilder()
+ public DiagnosticGraphBuilder(Registry[] registries)
{
- _innerBuilder = new NormalGraphBuilder();
+ _innerBuilder = new NormalGraphBuilder(registries);
_systemReport = new PluginGraphReport();
_report = _innerBuilder.PluginGraph.Report;
}
Modified: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2007-03-26 14:31:28 UTC (rev 30)
+++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2007-03-27 11:18:48 UTC (rev 31)
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using StructureMap.Attributes;
+using StructureMap.Configuration.DSL;
using StructureMap.Graph;
using StructureMap.Graph.Configuration;
using StructureMap.Interceptors;
@@ -17,14 +18,20 @@
private MachineOverride _machine;
- public NormalGraphBuilder() : this(new InterceptorChainBuilder())
+ public NormalGraphBuilder(Registry[] registries) : this(new InterceptorChainBuilder(), registries)
{
}
- public NormalGraphBuilder(IInterceptorChainBuilder builder)
+ public NormalGraphBuilder(IInterceptorChainBuilder builder, Registry[] registries)
{
_builder = builder;
+
_pluginGraph = new PluginGraph();
+ foreach (Registry registry in registries)
+ {
+ registry.ConfigurePluginGraph(_pluginGraph);
+ }
+
_systemGraph = new PluginGraph();
_systemGraph.Assemblies.Add(Assembly.GetExecutingAssembly());
}
Modified: trunk/Source/StructureMap/Configuration/Tokens/FamilyToken.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/Tokens/FamilyToken.cs 2007-03-26 14:31:28 UTC (rev 30)
+++ trunk/Source/StructureMap/Configuration/Tokens/FamilyToken.cs 2007-03-27 11:18:48 UTC (rev 31)
@@ -16,11 +16,14 @@
PluginFamilyAttribute att = PluginFamilyAttribute.GetAttribute(family.PluginType);
- if (att.Scope != InstanceScope.PerRequest)
+ if (att != null)
{
- token.Scope = att.Scope;
- InterceptorInstanceToken interceptor = new InterceptorInstanceToken(att.Scope);
- token.AddInterceptor(interceptor);
+ if (att.Scope != InstanceScope.PerRequest)
+ {
+ token.Scope = att.Scope;
+ InterceptorInstanceToken interceptor = new InterceptorInstanceToken(att.Scope);
+ token.AddInterceptor(interceptor);
+ }
}
return token;
Modified: trunk/Source/StructureMap/Graph/AssemblyGraph.cs
===================================================================
--- trunk/Source/StructureMap/Graph/AssemblyGraph.cs 2007-03-26 14:31:28 UTC (rev 30)
+++ trunk/Source/StructureMap/Graph/AssemblyGraph.cs 2007-03-27 11:18:48 UTC (rev 31)
@@ -1,8 +1,10 @@
using System;
using System.Collections;
+using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
+using StructureMap.Configuration.DSL;
namespace StructureMap.Graph
{
@@ -91,17 +93,9 @@
return new PluginFamily[0];
}
- ArrayList list = new ArrayList();
+ List<PluginFamily> list = new List<PluginFamily>();
- Type[] exportedTypes = null;
- try
- {
- exportedTypes = _assembly.GetExportedTypes();
- }
- catch (Exception ex)
- {
- throw new StructureMapException(170, ex, AssemblyName);
- }
+ Type[] exportedTypes = getExportedTypes();
foreach (Type exportedType in exportedTypes)
{
@@ -112,9 +106,24 @@
}
}
- return (PluginFamily[]) list.ToArray(typeof (PluginFamily));
+ return list.ToArray();
}
+ private Type[] getExportedTypes()
+ {
+ Type[] exportedTypes = null;
+ try
+ {
+ exportedTypes = _assembly.GetExportedTypes();
+ }
+ catch (Exception ex)
+ {
+ throw new StructureMapException(170, ex, AssemblyName);
+ }
+ return exportedTypes;
+ }
+
+
/// <summary>
/// Returns an array of possible Plugin's from the Assembly that match
/// the requested type
@@ -165,5 +174,23 @@
{
return _assembly.GetType(fullName, false);
}
+
+ public List<Registry> FindRegistries()
+ {
+ Type[] exportedTypes = getExportedTypes();
+ List<Registry> returnValue = new List<Registry>();
+
+ foreach (Type type in exportedTypes)
+ {
+ if (Registry.IsPublicRegistry(type))
+ {
+ Registry registry = (Registry)Activator.CreateInstance(type);
+ returnValue.Add(registry);
+ }
+
+ }
+
+ return returnValue;
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginGraph.cs 2007-03-26 14:31:28 UTC (rev 30)
+++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2007-03-27 11:18:48 UTC (rev 31)
@@ -1,7 +1,9 @@
using System;
using System.Collections;
+using System.Collections.Generic;
using System.Reflection;
using StructureMap.Configuration;
+using StructureMap.Configuration.DSL;
namespace StructureMap.Graph
{
@@ -54,6 +56,8 @@
return;
}
+ searchAssembliesForRegistries();
+
foreach (AssemblyGraph assembly in _assemblies)
{
addImplicitPluginFamilies(assembly);
@@ -67,6 +71,20 @@
_sealed = true;
}
+ private void searchAssembliesForRegistries()
+ {
+ List<Registry> list = new List<Registry>();
+ foreach (AssemblyGraph assembly in _assemblies)
+ {
+ list.AddRange(assembly.FindRegistries());
+ }
+
+ foreach (Registry registry in list)
+ {
+ registry.ConfigurePluginGraph(this);
+ }
+ }
+
private void attachImplicitPlugins(PluginFamily family)
{
foreach (AssemblyGraph assembly in _assemblies)
Modified: trunk/Source/StructureMap/PluginGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/PluginGraphBuilder.cs 2007-03-26 14:31:28 UTC (rev 30)
+++ trunk/Source/StructureMap/PluginGraphBuilder.cs 2007-03-27 11:18:48 UTC (rev 31)
@@ -1,6 +1,7 @@
using System;
using System.Xml;
using StructureMap.Configuration;
+using StructureMap.Configuration.DSL;
using StructureMap.Graph;
using StructureMap.Graph.Configuration;
@@ -17,7 +18,7 @@
public static PluginGraph BuildFromXml(XmlDocument document)
{
ConfigurationParser[] parsers = ConfigurationParser.GetParsers(document, "");
- PluginGraphBuilder builder = new PluginGraphBuilder(parsers);
+ PluginGraphBuilder builder = new PluginGraphBuilder(parsers, new Registry[0]);
return builder.BuildDiagnosticPluginGraph();
}
@@ -49,21 +50,22 @@
private PluginGraph _graph;
private PluginGraphReport _report;
private ConfigurationParser[] _parsers;
+ private readonly Registry[] _registries = new Registry[0];
#region constructors
public PluginGraphBuilder(ConfigurationParser parser)
- : this(new ConfigurationParser[] {parser})
+ : this(new ConfigurationParser[] {parser}, new Registry[0])
{
}
- public PluginGraphBuilder(ConfigurationParser[] parsers)
+ public PluginGraphBuilder(ConfigurationParser[] parsers, Registry[] registries)
{
_parsers = parsers;
+ _registries = registries;
}
-
/// <summary>
/// Creates a PluginGraphBuilder that reads configuration from the filePath
/// </summary>
@@ -102,7 +104,7 @@
/// <returns></returns>
public PluginGraph Build()
{
- NormalGraphBuilder graphBuilder = new NormalGraphBuilder();
+ NormalGraphBuilder graphBuilder = new NormalGraphBuilder(_registries);
PluginGraph pluginGraph = buildPluginGraph(graphBuilder);
return pluginGraph;
}
@@ -162,7 +164,7 @@
/// <returns></returns>
public PluginGraph BuildDiagnosticPluginGraph()
{
- DiagnosticGraphBuilder graphBuilder = new DiagnosticGraphBuilder();
+ DiagnosticGraphBuilder graphBuilder = new DiagnosticGraphBuilder(_registries);
buildPluginGraph(graphBuilder);
_report = graphBuilder.Report;
Modified: trunk/Source/StructureMap/StructureMapConfiguration.cs
===================================================================
--- trunk/Source/StructureMap/StructureMapConfiguration.cs 2007-03-26 14:31:28 UTC (rev 30)
+++ trunk/Source/StructureMap/StructureMapConfiguration.cs 2007-03-27 11:18:48 UTC (rev 31)
@@ -1,7 +1,9 @@
using System;
+using System.Collections.Generic;
using System.IO;
using System.Xml;
using StructureMap.Configuration;
+using StructureMap.Configuration.DSL;
using StructureMap.Graph;
namespace StructureMap
@@ -10,7 +12,15 @@
{
private const string CONFIG_FILE_NAME = "StructureMap.config";
private static ConfigurationParserCollection _collection = new ConfigurationParserCollection();
+ private static Registry _registry = new Registry();
+ private static List<Registry> _registries = new List<Registry>();
+ static StructureMapConfiguration()
+ {
+ ResetAll();
+ }
+
+
/// <summary>
/// Returns the path to the StructureMap.config file
/// </summary>
@@ -38,6 +48,9 @@
public static void ResetAll()
{
_collection = new ConfigurationParserCollection();
+ _registry = new Registry();
+ _registries = new List<Registry>();
+ _registries.Add(_registry);
}
public static PluginGraph GetPluginGraph()
@@ -49,7 +62,7 @@
private static PluginGraphBuilder createBuilder()
{
ConfigurationParser[] parsers = _collection.GetParsers();
- return new PluginGraphBuilder(parsers);
+ return new PluginGraphBuilder(parsers, _registries.ToArray());
}
public static PluginGraph GetDiagnosticPluginGraph()
@@ -80,5 +93,58 @@
get { return _collection.UseDefaultFile; }
set { _collection.UseDefaultFile = value; }
}
+
+ public static ScanAssembliesExpression ScanAssemblies()
+ {
+ ScanAssembliesExpression expression = new ScanAssembliesExpression();
+ _registry.addExpression(expression);
+
+ return expression;
+ }
+
+ public static CreatePluginFamilyExpression BuildInstancesOf<T>()
+ {
+ return _registry.BuildInstancesOf<T>();
+ }
+
+ public static InstanceExpression.InstanceTypeExpression AddInstanceOf<T>()
+ {
+ return _registry.AddInstanceOf<T>();
+ }
+
+ public static InstanceExpression.InstanceTypeExpression Instance<T>()
+ {
+ return Registry.Instance<T>();
+ }
+
+ public static PrototypeExpression<T> Prototype<T>(T prototype)
+ {
+ return new PrototypeExpression<T>(prototype);
+ }
+
+ public static LiteralExpression<T> Object<T>(T instance)
+ {
+ return new LiteralExpression<T>(instance);
+ }
+
+ public static LiteralExpression<T> AddInstanceOf<T>(T target)
+ {
+ return _registry.AddInstanceOf(target);
+ }
+
+ public static PrototypeExpression<T> AddPrototypeInstanceOf<T>(T prototype)
+ {
+ return _registry.AddPrototypeInstanceOf(prototype);
+ }
+
+ public static ProfileExpression CreateProfile(string profileName)
+ {
+ return _registry.CreateProfile(profileName);
+ }
+
+ public static void AddRegistry(Registry registry)
+ {
+ _registries.Add(registry);
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs 2007-03-26 14:31:28 UTC (rev 30)
+++ trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs 2007-03-27 11:18:48 UTC (rev 31)
@@ -2,6 +2,7 @@
using System.Xml;
using NUnit.Framework;
using StructureMap.Configuration;
+using StructureMap.Configuration.DSL;
using StructureMap.Graph;
using StructureMap.Source;
using StructureMap.Testing.TestData;
@@ -45,7 +46,7 @@
ConfigurationParser parser = new ConfigurationParser(doc.DocumentElement);
- NormalGraphBuilder builder = new NormalGraphBuilder();
+ NormalGraphBuilder builder = new NormalGraphBuilder(new Registry[0]);
parser.ParseProfilesAndMachines(builder);
_defaults = builder.DefaultManager;
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-03-26 14:31:28 UTC (rev 30)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-03-27 11:18:48 UTC (rev 31)
@@ -178,13 +178,15 @@
{
Registry registry = new Registry();
- registry.ScanAssemblies().IncludeAssemblyContainingType<IWidget>();
+ //registry.ScanAssemblies().IncludeAssemblyContainingType<IWidget>();
+
+
registry.AddInstanceOf<Rule>().UsingConcreteType<ARule>().WithName("Alias");
// Add an instance by specifying the ConcreteKey
registry.AddInstanceOf<IWidget>()
- .UsingConcreteTypeNamed("Color")
+ .UsingConcreteType<ColorWidget>()
.WithName("Purple")
.WithProperty("Color").EqualTo("Purple");
Added: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs 2007-03-27 11:18:48 UTC (rev 31)
@@ -0,0 +1,86 @@
+using System.Collections.Generic;
+using NUnit.Framework;
+using StructureMap.Configuration.DSL;
+using StructureMap.Graph;
+using StructureMap.Testing.Widget;
+using StructureMap.Testing.Widget5;
+
+namespace StructureMap.Testing.Configuration.DSL
+{
+ [TestFixture]
+ public class RegistryIntegratedTester
+ {
+ [SetUp]
+ public void SetUp()
+ {
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ StructureMapConfiguration.ResetAll();
+ ObjectFactory.Reset();
+ }
+
+
+ [Test]
+ public void FindRegistries()
+ {
+ AssemblyGraph assembly = new AssemblyGraph("StructureMap.Testing.Widget5");
+ List<Registry> list = assembly.FindRegistries();
+
+ Assert.AreEqual(3, list.Count);
+ Assert.Contains(new RedGreenRegistry(), list);
+ Assert.Contains(new YellowBlueRegistry(), list);
+ Assert.Contains(new BrownBlackRegistry(), list);
+ }
+
+ [Test]
+ public void FindRegistriesWithinPluginGraphSeal()
+ {
+ PluginGraph graph = new PluginGraph();
+ graph.Assemblies.Add("StructureMap.Testing.Widget5");
+ graph.Seal();
+
+ List<string> colors = new List<string>();
+ foreach (InstanceMemento memento in graph.PluginFamilies[typeof(IWidget)].Source.GetAllMementos() )
+ {
+ colors.Add(memento.InstanceKey);
+ }
+
+ Assert.Contains("Red", colors);
+ Assert.Contains("Green", colors);
+ Assert.Contains("Yellow", colors);
+ Assert.Contains("Blue", colors);
+ Assert.Contains("Brown", colors);
+ Assert.Contains("Black", colors);
+ }
+
+ [Test]
+ public void AutomaticallyFindRegistryFromAssembly()
+ {
+ StructureMapConfiguration.ResetAll();
+ StructureMapConfiguration.ScanAssemblies().IncludeAssemblyContainingType<RedGreenRegistry>();
+ ObjectFactory.Reset();
+
+ List<string> colors = new List<string>();
+ foreach (IWidget widget in ObjectFactory.GetAllInstances<IWidget>())
+ {
+ if (!(widget is ColorWidget))
+ {
+ continue;
+ }
+
+ ColorWidget color = (ColorWidget) widget;
+ colors.Add(color.Color);
+ }
+
+ Assert.Contains("Red", colors);
+ Assert.Contains("Green", colors);
+ Assert.Contains("Yellow", colors);
+ Assert.Contains("Blue", colors);
+ Assert.Contains("Brown", colors);
+ Assert.Contains("Black", colors);
+ }
+ }
+}
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ScanAssembliesTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/ScanAssembliesTester.cs 2007-03-26 14:31:28 UTC (rev 30)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/ScanAssembliesTester.cs 2007-03-27 11:18:48 UTC (rev 31)
@@ -1,7 +1,5 @@
using System.Reflection;
using NUnit.Framework;
-using Rhino.Mocks;
-using StructureMap.Configuration.DSL;
using StructureMap.Graph;
using StructureMap.Testing.Widget3;
@@ -13,19 +11,22 @@
[SetUp]
public void SetUp()
{
+ ObjectFactory.Reset();
}
+ [TearDown]
+ public void TearDown()
+ {
+ StructureMapConfiguration.ResetAll();
+ ObjectFactory.Reset();
+ }
+
[Test]
public void ScanCallingAssembly()
{
- PluginGraph graph = new PluginGraph();
+ StructureMapConfiguration.ScanAssemblies().IncludeTheCallingAssembly();
+ PluginGraph graph = StructureMapConfiguration.GetPluginGraph();
-
- using (Registry registry = new Registry(graph))
- {
- registry.ScanAssemblies().IncludeTheCallingAssembly();
- }
-
AssemblyGraph assembly = new AssemblyGraph(Assembly.GetExecutingAssembly());
Assert.IsTrue(graph.Assemblies.Contains(assembly.AssemblyName));
}
@@ -33,15 +34,9 @@
[Test]
public void ScanAssemblyContainingType()
{
- PluginGraph graph = new PluginGraph();
+ StructureMapConfiguration.ScanAssemblies().IncludeAssemblyContainingType<IGateway>();
+ PluginGraph graph = StructureMapConfiguration.GetPluginGraph();
-
- using (Registry registry = new Registry(graph))
- {
- registry.ScanAssemblies()
- .IncludeAssemblyContainingType<IGateway>();
- }
-
AssemblyGraph assembly = AssemblyGraph.ContainingType<IGateway>();
Assert.IsTrue(graph.Assemblies.Contains(assembly.AssemblyName));
}
@@ -49,16 +44,11 @@
[Test]
public void Combination1()
{
- PluginGraph graph = new PluginGraph();
+ StructureMapConfiguration.ScanAssemblies()
+ .IncludeAssemblyContainingType<IGateway>()
+ .IncludeTheCallingAssembly();
+ PluginGraph graph = StructureMapConfiguration.GetPluginGraph();
-
- using (Registry registry = new Registry(graph))
- {
- registry.ScanAssemblies()
- .IncludeAssemblyContainingType<IGateway>()
- .IncludeTheCallingAssembly();
- }
-
AssemblyGraph assembly = AssemblyGraph.ContainingType<IGateway>();
Assert.IsTrue(graph.Assemblies.Contains(assembly.AssemblyName));
@@ -70,23 +60,16 @@
[Test]
public void Combination2()
{
- PluginGraph graph = new PluginGraph();
+ StructureMapConfiguration.ScanAssemblies()
+ .IncludeTheCallingAssembly()
+ .IncludeAssemblyContainingType<IGateway>();
+ PluginGraph graph = StructureMapConfiguration.GetPluginGraph();
-
- using (Registry registry = new Registry(graph))
- {
- registry.ScanAssemblies()
- .IncludeTheCallingAssembly()
- .IncludeAssemblyContainingType<IGateway>();
-
- }
-
AssemblyGraph assembly = AssemblyGraph.ContainingType<IGateway>();
Assert.IsTrue(graph.Assemblies.Contains(assembly.AssemblyName));
assembly = new AssemblyGraph(Assembly.GetExecutingAssembly());
Assert.IsTrue(graph.Assemblies.Contains(assembly.AssemblyName));
}
-
}
-}
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Configuration/DiagnosticGraphBuilderTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DiagnosticGraphBuilderTester.cs 2007-03-26 14:31:28 UTC (rev 30)
+++ trunk/Source/StructureMap.Testing/Configuration/DiagnosticGraphBuilderTester.cs 2007-03-27 11:18:48 UTC (rev 31)
@@ -3,6 +3,7 @@
using NUnit.Framework;
using StructureMap.Attributes;
using StructureMap.Configuration;
+using StructureMap.Configuration.DSL;
using StructureMap.Configuration.Tokens;
using StructureMap.Graph;
using StructureMap.Testing.Configuration.Tokens;
@@ -22,7 +23,7 @@
XmlDocument document = new XmlDocument();
document.LoadXml("<StructureMap/>");
- _builder = new DiagnosticGraphBuilder();
+ _builder = new DiagnosticGraphBuilder(new Registry[0]);
_report = _builder.Report;
}
Modified: trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs 2007-03-26 14:31:28 UTC (rev 30)
+++ trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs 2007-03-27 11:18:48 UTC (rev 31)
@@ -2,6 +2,7 @@
using NUnit.Framework;
using StructureMap.Attributes;
using StructureMap.Configuration;
+using StructureMap.Configuration.DSL;
using StructureMap.Graph;
using StructureMap.Interceptors;
@@ -19,7 +20,7 @@
builderMock.ExpectAndReturn("Build", chain, theScope);
NormalGraphBuilder graphBuilder =
- new NormalGraphBuilder((IInterceptorChainBuilder) builderMock.MockInstance);
+ new NormalGraphBuilder((IInterceptorChainBuilder) builderMock.MockInstance, new Registry[0]);
TypePath typePath = new TypePath(GetType());
@@ -36,7 +37,7 @@
[Test]
public void AddProfile()
{
- NormalGraphBuilder graphBuilder = new NormalGraphBuilder();
+ NormalGraphBuilder graphBuilder = new NormalGraphBuilder(new Registry[0]);
string profileName = "blue";
graphBuilder.AddProfile(profileName);
@@ -49,7 +50,7 @@
[Test]
public void AddDefaultForAProfile()
{
- NormalGraphBuilder graphBuilder = new NormalGraphBuilder();
+ NormalGraphBuilder graphBuilder = new NormalGraphBuilder(new Registry[0]);
string profileName = "blue";
string theTypeName = "the name of the type";
string theKey = "Key1";
@@ -67,7 +68,7 @@
[Test]
public void AddMachineWithExistingProfile()
{
- NormalGraphBuilder graphBuilder = new NormalGraphBuilder();
+ NormalGraphBuilder graphBuilder = new NormalGraphBuilder(new Registry[0]);
string theMachineName = "some machine";
string theProfileName = "some profile";
graphBuilder.AddProfile(theProfileName);
@@ -85,7 +86,7 @@
)]
public void AddMachineWithProfileThatDoesNotExist()
{
- NormalGraphBuilder graphBuilder = new NormalGraphBuilder();
+ NormalGraphBuilder graphBuilder = new NormalGraphBuilder(new Registry[0]);
string theMachineName = "some machine";
string theProfileName = "some profile";
@@ -95,7 +96,7 @@
[Test]
public void AddMachineWithoutProfile()
{
- NormalGraphBuilder graphBuilder = new NormalGraphBuilder();
+ NormalGraphBuilder graphBuilder = new NormalGraphBuilder(new Registry[0]);
string theMachineName = "some machine";
graphBuilder.AddMachine(theMachineName, string.Empty);
@@ -109,7 +110,7 @@
[Test]
public void AddAnOverrideToMachine()
{
- NormalGraphBuilder graphBuilder = new NormalGraphBuilder();
+ NormalGraphBuilder graphBuilder = new NormalGraphBuilder(new Registry[0]);
string theMachineName = "some machine";
graphBuilder.AddMachine(theMachineName, string.Empty);
Modified: trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2007-03-26 14:31:28 UTC (rev 30)
+++ trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2007-03-27 11:18:48 UTC (rev 31)
@@ -5,6 +5,7 @@
using Rhino.Mocks;
using StructureMap.Attributes;
using StructureMap.Configuration;
+using StructureMap.Configuration.DSL;
using StructureMap.Graph;
using StructureMap.Testing.TestData;
using StructureMap.Testing.Widget;
@@ -42,7 +43,7 @@
[Test]
public void NormalGraphBuilderHandlesTheInferredPlugin()
{
- NormalGraphBuilder builder = new NormalGraphBuilder();
+ NormalGraphBuilder builder = new NormalGraphBuilder(new Registry[0]);
TypePath pluginTypePath = new TypePath(typeof(IGateway));
builder.AddPluginFamily(pluginTypePath, "", new string[0], InstanceScope.PerRequest);
@@ -61,7 +62,7 @@
[Test]
public void CanBuildTheInstance()
{
- NormalGraphBuilder builder = new NormalGraphBuilder();
+ NormalGraphBuilder builder = new NormalGraphBuilder(new Registry[0]);
TypePath pluginTypePath = new TypePath(typeof(IGateway));
builder.AddPluginFamily(pluginTypePath, _memento.InstanceKey, new string[0], InstanceScope.PerRequest);
Added: trunk/Source/StructureMap.Testing.Widget5/WidgetRegistry.cs
===================================================================
--- trunk/Source/StructureMap.Testing.Widget5/WidgetRegistry.cs (rev 0)
+++ trunk/Source/StructureMap.Testing.Widget5/WidgetRegistry.cs 2007-03-27 11:18:48 UTC (rev 31)
@@ -0,0 +1,78 @@
+using StructureMap.Configuration.DSL;
+using StructureMap.Testing.Widget;
+
+namespace StructureMap.Testing.Widget5
+{
+ public class RedGreenRegistry : Registry
+ {
+ protected override void configure()
+ {
+ AddInstanceOf<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo("Red").WithName("Red");
+ AddInstanceOf<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo("Green").WithName("Green");
+ }
+
+
+ public override bool Equals(object obj)
+ {
+ if (this == obj) return true;
+ RedGreenRegistry redGreenRegistry = obj as RedGreenRegistry;
+ if (redGreenRegistry == null) return false;
+ return true;
+ }
+
+ public override int GetHashCode()
+ {
+ return 0;
+ }
+ }
+
+ public class YellowBlueRegistry : Registry
+ {
+ protected override void configure()
+ {
+ AddInstanceOf<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo("Yellow").WithName("Yellow");
+ AddInstanceOf<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo("Blue").WithName("Blue");
+ }
+
+
+ public override bool Equals(object obj)
+ {
+ if (this == obj) return true;
+ YellowBlueRegistry yellowBlueRegistry = obj as YellowBlueRegistry;
+ if (yellowBlueRegistry == null) return false;
+ return true;
+ }
+
+ public override int GetHashCode()
+ {
+ return 0;
+ }
+ }
+
+ public class BrownBlackRegistry : Registry
+ {
+ protected override void configure()
+ {
+ AddInstanceOf<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo("Brown").WithName("Brown");
+ AddInstanceOf<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo("Black").WithName("Black");
+ }
+
+
+ public override bool Equals(object obj)
+ {
+ if (this == obj) return true;
+ BrownBlackRegistry brownBlackRegistry = obj as BrownBlackRegistry;
+ if (brownBlackRegistry == null) return false;
+ return true;
+ }
+
+ public override int GetHashCode()
+ {
+ return 0;
+ }
+ }
+
+ public abstract class PurpleRegistry : Registry
+ {
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|