From: <jer...@us...> - 2008-05-28 03:35:04
|
Revision: 106 http://structuremap.svn.sourceforge.net/structuremap/?rev=106&view=rev Author: jeremydmiller Date: 2008-05-27 20:35:02 -0700 (Tue, 27 May 2008) Log Message: ----------- minor refactoring of Registry Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-28 03:15:34 UTC (rev 105) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-28 03:35:02 UTC (rev 106) @@ -10,16 +10,9 @@ public class Registry : RegistryExpressions { private readonly List<Action<PluginGraph>> _actions = new List<Action<PluginGraph>>(); - private readonly PluginGraph _graph; - public Registry(PluginGraph graph) : this() - { - _graph = graph; - } - public Registry() { - _graph = new PluginGraph(); configure(); } @@ -79,10 +72,11 @@ public PluginGraph Build() { - ConfigurePluginGraph(_graph); - _graph.Seal(); + PluginGraph graph = new PluginGraph(); + ConfigurePluginGraph(graph); + graph.Seal(); - return _graph; + return graph; } /// <summary> @@ -95,10 +89,7 @@ ConfiguredInstance instance = new ConfiguredInstance(); addExpression( - delegate(PluginGraph pluginGraph) - { - pluginGraph.FindFamily(typeof (PLUGINTYPE)).AddInstance(instance); - }); + delegate(PluginGraph pluginGraph) { pluginGraph.FindFamily(typeof (PLUGINTYPE)).AddInstance(instance); }); return instance; } @@ -113,7 +104,7 @@ public LiteralInstance AddInstanceOf<PLUGINTYPE>(PLUGINTYPE target) { LiteralInstance literal = new LiteralInstance(target); - _graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(literal); + _actions.Add(delegate(PluginGraph graph) { graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(literal); }); return literal; } @@ -126,10 +117,13 @@ /// <returns></returns> public PrototypeInstance AddPrototypeInstanceOf<PLUGINTYPE>(PLUGINTYPE prototype) { - PrototypeInstance expression = new PrototypeInstance((ICloneable) prototype); - _graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(expression); + PrototypeInstance instance = new PrototypeInstance((ICloneable) prototype); + _actions.Add(delegate(PluginGraph graph) + { + graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(instance); + }); - return expression; + return instance; } /// <summary> @@ -138,7 +132,7 @@ /// <typeparam name="PLUGINTYPE"></typeparam> /// <param name="url"></param> /// <returns></returns> - public static UserControlInstance LoadUserControlFrom<PLUGINTYPE>(string url) + public static UserControlInstance LoadUserControlFrom(string url) { return new UserControlInstance(url); } Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2008-05-28 03:15:34 UTC (rev 105) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2008-05-28 03:35:02 UTC (rev 106) @@ -24,11 +24,6 @@ public class TestRegistry : Registry { - public TestRegistry(PluginGraph graph) : base(graph) - { - } - - public TestRegistry() { } Modified: trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs 2008-05-28 03:15:34 UTC (rev 105) +++ trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs 2008-05-28 03:35:02 UTC (rev 106) @@ -18,23 +18,20 @@ [SetUp] public void SetUp() { - PluginGraph graph = new PluginGraph(); - Registry registry = new Registry(graph); + Registry registry = new Registry(); registry.BuildInstancesOf<Rule>(); registry.ScanAssemblies() .IncludeAssembly("StructureMap.Testing.Widget") .IncludeAssembly("StructureMap.Testing.Widget2"); - registry.Build(); + PluginGraph graph = registry.Build(); PipelineGraph pipelineGraph = new PipelineGraph(graph); _session = new BuildSession(pipelineGraph, graph.InterceptorLibrary); - instance = new ConfiguredInstance(); } #endregion - private ConfiguredInstance instance; private IBuildSession _session; @@ -52,17 +49,7 @@ } } - [Test] - public void TestComplexRule() - { - ConfiguredInstance instance = (ConfiguredInstance)ComplexRule.GetInstance(); - Rule rule = (Rule)instance.Build(typeof(Rule), _session); - Assert.IsNotNull(rule); - Assert.IsTrue(rule is ComplexRule); - } - - [Test] public void AttachDependencies_should_find_the_InstanceBuilder_by_ConcreteKey_if_PluggedType_does_not_exists() { @@ -106,7 +93,7 @@ using (mocks.Playback()) { - object actualObject = ((IConfiguredInstance)instance).Build(GetType(), session, builder); + object actualObject = ((IConfiguredInstance) instance).Build(GetType(), session, builder); Assert.AreSame(theObjectBuilt, actualObject); } } @@ -134,10 +121,10 @@ [Test, ExpectedException(typeof (StructureMapException))] public void BuildRuleWithAMissingValue() { - IStructuredInstance instance = (IStructuredInstance)ComplexRule.GetInstance(); + IStructuredInstance instance = (IStructuredInstance) ComplexRule.GetInstance(); instance.RemoveKey("String"); - ComplexRule rule = (ComplexRule) ((Instance)instance).Build(typeof (Rule), _session); + ComplexRule rule = (ComplexRule) ((Instance) instance).Build(typeof (Rule), _session); } [Test] @@ -225,7 +212,8 @@ [Test] public void GetProperty_happy_path() { - instance.SetProperty("Color", "Red") + ConfiguredInstance instance = new ConfiguredInstance() + .SetProperty("Color", "Red") .SetProperty("Age", "34"); IConfiguredInstance configuredInstance = instance; @@ -242,7 +230,7 @@ { try { - IConfiguredInstance configuredInstance = instance; + IConfiguredInstance configuredInstance = new ConfiguredInstance(); configuredInstance.GetProperty("anything"); Assert.Fail("Did not throw exception"); } @@ -277,6 +265,16 @@ } [Test] + public void TestComplexRule() + { + ConfiguredInstance instance = (ConfiguredInstance) ComplexRule.GetInstance(); + + Rule rule = (Rule) instance.Build(typeof (Rule), _session); + Assert.IsNotNull(rule); + Assert.IsTrue(rule is ComplexRule); + } + + [Test] public void Trying_to_build_with_an_InvalidCastException_will_throw_error_206() { MockRepository mocks = new MockRepository(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |