From: <jer...@us...> - 2008-05-28 03:58:53
|
Revision: 107 http://structuremap.svn.sourceforge.net/structuremap/?rev=107&view=rev Author: jeremydmiller Date: 2008-05-27 20:58:49 -0700 (Tue, 27 May 2008) Log Message: ----------- Renaming CreateInstance to GetInstance in InstanceManager to be consistent with ObjectFactory, renaming IInstanceManager.cs to IContainer Modified Paths: -------------- trunk/Source/StructureMap/Configuration/GraphBuilder.cs trunk/Source/StructureMap/ExplicitArgsExpression.cs trunk/Source/StructureMap/InstanceManager.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs trunk/Source/StructureMap.Testing/BuildSessionTester.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs trunk/Source/StructureMap.Testing/Container/ExceptionHandling/StructureMapExceptionTester.cs trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs trunk/Source/StructureMap.Testing/Container/FillDependenciesTester.cs trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs trunk/Source/StructureMap.Testing/Container/IntegratedTester.cs trunk/Source/StructureMap.Testing/Container/Interceptors/TypeInterceptionTester.cs trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs trunk/Source/StructureMap.Testing/Container/TypeFindingTester.cs trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs trunk/Source/StructureMap.Testing/Graph/PluginTester.cs trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs Added Paths: ----------- trunk/Source/StructureMap/IContainer.cs Removed Paths: ------------- trunk/Source/StructureMap/IInstanceManager.cs Modified: trunk/Source/StructureMap/Configuration/GraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -115,7 +115,7 @@ _systemInstanceManager = new InstanceManager(_systemGraph); } - return _systemInstanceManager.CreateInstance(type, instance); + return _systemInstanceManager.GetInstance(type, instance); } } } \ No newline at end of file Modified: trunk/Source/StructureMap/ExplicitArgsExpression.cs =================================================================== --- trunk/Source/StructureMap/ExplicitArgsExpression.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap/ExplicitArgsExpression.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -10,10 +10,10 @@ public class ExplicitArgsExpression : IExplicitProperty { private readonly ExplicitArguments _args = new ExplicitArguments(); - private readonly IInstanceManager _manager; + private readonly IContainer _manager; private string _lastArgName; - internal ExplicitArgsExpression(IInstanceManager manager) + internal ExplicitArgsExpression(IContainer manager) { _manager = manager; } @@ -43,7 +43,7 @@ public T GetInstance<T>() { - return _manager.CreateInstance<T>(_args); + return _manager.GetInstance<T>(_args); } } } \ No newline at end of file Added: trunk/Source/StructureMap/IContainer.cs =================================================================== --- trunk/Source/StructureMap/IContainer.cs (rev 0) +++ trunk/Source/StructureMap/IContainer.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -0,0 +1,82 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using StructureMap.Pipeline; + +namespace StructureMap +{ + public interface IContainer + { + T GetInstance<T>(string instanceKey); + T GetInstance<T>(); + T FillDependencies<T>(); + object FillDependencies(Type type); + void InjectStub<T>(T instance); + IList<T> GetAllInstances<T>(); + void SetDefaultsToProfile(string profile); + + T GetInstance<T>(Instance instance); + + /// <summary> + /// Sets up the InstanceManager to return the object in the "stub" argument anytime + /// any instance of the PluginType is requested + /// </summary> + /// <param name="pluginType"></param> + /// <param name="stub"></param> + void InjectStub(Type pluginType, object stub); + + IList GetAllInstances(Type type); + void AddInstance<T>(Instance instance); + void AddInstance<PLUGINTYPE, CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE; + void AddDefaultInstance<PLUGINTYPE, CONCRETETYPE>(); + void Inject<PLUGINTYPE>(PLUGINTYPE instance); + void InjectByName<PLUGINTYPE>(PLUGINTYPE instance, string instanceKey); + void InjectByName<PLUGINTYPE, CONCRETETYPE>(string instanceKey); + + string WhatDoIHave(); + + /// <summary> + /// Sets the default instance for the PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instance"></param> + void SetDefault(Type pluginType, Instance instance); + + /// <summary> + /// Sets the default instance for the PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instanceKey"></param> + void SetDefault(Type pluginType, string instanceKey); + + /// <summary> + /// Creates a new object instance of the requested type + /// </summary> + /// <param name="pluginType"></param> + /// <returns></returns> + object GetInstance(Type pluginType); + + + /// <summary> + /// Creates a new instance of the requested type using the InstanceMemento. Mostly used from other + /// classes to link children members + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instance"></param> + /// <returns></returns> + object GetInstance(Type pluginType, Instance instance); + + /// <summary> + /// Creates the named instance of the PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instanceKey"></param> + /// <returns></returns> + object GetInstance(Type pluginType, string instanceKey); + + PLUGINTYPE GetInstance<PLUGINTYPE>(ExplicitArguments args); + + ExplicitArgsExpression With<T>(T arg); + IExplicitProperty With(string argName); + } +} \ No newline at end of file Deleted: trunk/Source/StructureMap/IInstanceManager.cs =================================================================== --- trunk/Source/StructureMap/IInstanceManager.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap/IInstanceManager.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -1,82 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using StructureMap.Pipeline; - -namespace StructureMap -{ - public interface IInstanceManager - { - T CreateInstance<T>(string instanceKey); - T CreateInstance<T>(); - T FillDependencies<T>(); - object FillDependencies(Type type); - void InjectStub<T>(T instance); - IList<T> GetAllInstances<T>(); - void SetDefaultsToProfile(string profile); - - T CreateInstance<T>(Instance instance); - - /// <summary> - /// Sets up the InstanceManager to return the object in the "stub" argument anytime - /// any instance of the PluginType is requested - /// </summary> - /// <param name="pluginType"></param> - /// <param name="stub"></param> - void InjectStub(Type pluginType, object stub); - - IList GetAllInstances(Type type); - void AddInstance<T>(Instance instance); - void AddInstance<PLUGINTYPE, CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE; - void AddDefaultInstance<PLUGINTYPE, CONCRETETYPE>(); - void Inject<PLUGINTYPE>(PLUGINTYPE instance); - void InjectByName<PLUGINTYPE>(PLUGINTYPE instance, string instanceKey); - void InjectByName<PLUGINTYPE, CONCRETETYPE>(string instanceKey); - - string WhatDoIHave(); - - /// <summary> - /// Sets the default instance for the PluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instance"></param> - void SetDefault(Type pluginType, Instance instance); - - /// <summary> - /// Sets the default instance for the PluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instanceKey"></param> - void SetDefault(Type pluginType, string instanceKey); - - /// <summary> - /// Creates a new object instance of the requested type - /// </summary> - /// <param name="pluginType"></param> - /// <returns></returns> - object CreateInstance(Type pluginType); - - - /// <summary> - /// Creates a new instance of the requested type using the InstanceMemento. Mostly used from other - /// classes to link children members - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instance"></param> - /// <returns></returns> - object CreateInstance(Type pluginType, Instance instance); - - /// <summary> - /// Creates the named instance of the PluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instanceKey"></param> - /// <returns></returns> - object CreateInstance(Type pluginType, string instanceKey); - - PLUGINTYPE CreateInstance<PLUGINTYPE>(ExplicitArguments args); - - ExplicitArgsExpression With<T>(T arg); - IExplicitProperty With(string argName); - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceManager.cs =================================================================== --- trunk/Source/StructureMap/InstanceManager.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap/InstanceManager.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -14,7 +14,7 @@ /// <summary> /// A collection of IInstanceFactory's. /// </summary> - public class InstanceManager : TypeRules, IInstanceManager + public class InstanceManager : TypeRules, IContainer { private InterceptorLibrary _interceptorLibrary; private PipelineGraph _pipelineGraph; @@ -65,24 +65,24 @@ set { _pipelineGraph.OnMissingFactory = value; } } - #region IInstanceManager Members + #region IContainer Members - public T CreateInstance<T>(string instanceKey) + public T GetInstance<T>(string instanceKey) { - return (T) CreateInstance(typeof (T), instanceKey); + return (T) GetInstance(typeof (T), instanceKey); } - public T CreateInstance<T>(Instance instance) + public T GetInstance<T>(Instance instance) { - return (T) CreateInstance(typeof (T), instance); + return (T) GetInstance(typeof (T), instance); } - public PLUGINTYPE CreateInstance<PLUGINTYPE>(ExplicitArguments args) + public PLUGINTYPE GetInstance<PLUGINTYPE>(ExplicitArguments args) { Instance defaultInstance = _pipelineGraph.GetDefault(typeof (PLUGINTYPE)); ExplicitInstance<PLUGINTYPE> instance = new ExplicitInstance<PLUGINTYPE>(args, defaultInstance); - return CreateInstance<PLUGINTYPE>(instance); + return GetInstance<PLUGINTYPE>(instance); } public void Inject<PLUGINTYPE>(PLUGINTYPE instance) @@ -106,9 +106,9 @@ AddInstance<PLUGINTYPE>(instance); } - public T CreateInstance<T>() + public T GetInstance<T>() { - return (T) CreateInstance(typeof (T)); + return (T) GetInstance(typeof (T)); } public T FillDependencies<T>() @@ -146,7 +146,7 @@ /// <param name="pluginType"></param> /// <param name="instanceKey"></param> /// <returns></returns> - public object CreateInstance(Type pluginType, string instanceKey) + public object GetInstance(Type pluginType, string instanceKey) { return withNewSession().CreateInstance(pluginType, instanceKey); } @@ -157,7 +157,7 @@ /// </summary> /// <param name="pluginType"></param> /// <returns></returns> - public object CreateInstance(Type pluginType) + public object GetInstance(Type pluginType) { return withNewSession().CreateInstance(pluginType); } @@ -170,7 +170,7 @@ /// <param name="pluginType"></param> /// <param name="instance"></param> /// <returns></returns> - public object CreateInstance(Type pluginType, Instance instance) + public object GetInstance(Type pluginType, Instance instance) { return withNewSession().CreateInstance(pluginType, instance); } @@ -216,7 +216,7 @@ throw new StructureMapException(230, type.FullName); } - return CreateInstance(type); + return GetInstance(type); } /// <summary> Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -16,7 +16,7 @@ public class ObjectFactory { private static readonly object _lockObject = new object(); - private static IInstanceManager _manager; + private static IContainer _manager; private static string _profile = string.Empty; private static event Notify _notify; @@ -131,7 +131,7 @@ #region InstanceManager and setting defaults - private static IInstanceManager manager + private static IContainer manager { get { @@ -184,7 +184,7 @@ /// Strictly used for testing scenarios /// </summary> /// <param name="manager"></param> - internal static void ReplaceManager(IInstanceManager manager) + internal static void ReplaceManager(IContainer manager) { _manager = manager; } @@ -246,7 +246,7 @@ /// <returns></returns> public static object GetInstance(Type TargetType) { - return manager.CreateInstance(TargetType); + return manager.GetInstance(TargetType); } /// <summary> @@ -256,7 +256,7 @@ /// <returns></returns> public static TargetType GetInstance<TargetType>() { - return (TargetType) manager.CreateInstance(typeof (TargetType)); + return (TargetType) manager.GetInstance(typeof (TargetType)); } /// <summary> @@ -267,7 +267,7 @@ /// <returns></returns> public static object GetInstance(Type TargetType, Instance instance) { - return manager.CreateInstance(TargetType, instance); + return manager.GetInstance(TargetType, instance); } /// <summary> @@ -278,7 +278,7 @@ /// <returns></returns> public static TargetType GetInstance<TargetType>(Instance instance) { - return (TargetType) manager.CreateInstance(typeof (TargetType), instance); + return (TargetType) manager.GetInstance(typeof (TargetType), instance); } /// <summary> @@ -289,7 +289,7 @@ /// <returns></returns> public static object GetNamedInstance(Type TargetType, string InstanceName) { - return manager.CreateInstance(TargetType, InstanceName); + return manager.GetInstance(TargetType, InstanceName); } /// <summary> @@ -300,7 +300,7 @@ /// <returns></returns> public static TargetType GetNamedInstance<TargetType>(string InstanceName) { - return (TargetType) manager.CreateInstance(typeof (TargetType), InstanceName); + return (TargetType) manager.GetInstance(typeof (TargetType), InstanceName); } /// <summary> Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-05-28 03:58:49 UTC (rev 107) @@ -285,7 +285,7 @@ <Compile Include="IInstanceFactory.cs"> <SubType>Code</SubType> </Compile> - <Compile Include="IInstanceManager.cs" /> + <Compile Include="IContainer.cs" /> <Compile Include="InstanceBuilder.cs"> <SubType>Code</SubType> </Compile> Modified: trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -60,7 +60,7 @@ foreach (ParameterInfo parameterInfo in ctor.GetParameters()) { Type dependencyType = parameterInfo.ParameterType; - object dependency = _manager.CreateInstance(dependencyType); + object dependency = _manager.GetInstance(dependencyType); list.Add(dependency); } @@ -71,7 +71,7 @@ // of the ClassUnderTest public T Get<T>() { - return _manager.CreateInstance<T>(); + return _manager.GetInstance<T>(); } // Set the auto mocking container to use a Stub for Type T Modified: trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -132,9 +132,9 @@ [Test] public void AutoFillAConcreteClassWithMocks() { - IMockedService service = _instanceManager.CreateInstance<IMockedService>(); - IMockedService2 service2 = _instanceManager.CreateInstance<IMockedService2>(); - IMockedService3 service3 = _instanceManager.CreateInstance<IMockedService3>(); + IMockedService service = _instanceManager.GetInstance<IMockedService>(); + IMockedService2 service2 = _instanceManager.GetInstance<IMockedService2>(); + IMockedService3 service3 = _instanceManager.GetInstance<IMockedService3>(); ConcreteClass concreteClass = _instanceManager.FillDependencies<ConcreteClass>(); @@ -146,7 +146,7 @@ [Test] public void GetAFullMockForAServiceThatHasNotPreviouslyBeenRequested() { - IMockedService service = _instanceManager.CreateInstance<IMockedService>(); + IMockedService service = _instanceManager.GetInstance<IMockedService>(); Assert.IsNotNull(service); @@ -171,19 +171,19 @@ StubService stub = new StubService(); _instanceManager.InjectStub<IMockedService>(stub); - Assert.AreSame(stub, _instanceManager.CreateInstance<IMockedService>()); - Assert.AreSame(stub, _instanceManager.CreateInstance<IMockedService>()); - Assert.AreSame(stub, _instanceManager.CreateInstance<IMockedService>()); + Assert.AreSame(stub, _instanceManager.GetInstance<IMockedService>()); + Assert.AreSame(stub, _instanceManager.GetInstance<IMockedService>()); + Assert.AreSame(stub, _instanceManager.GetInstance<IMockedService>()); } [Test] public void RequestTheServiceTwiceAndGetTheExactSameMockObject() { - IMockedService service = _instanceManager.CreateInstance<IMockedService>(); - Assert.AreSame(service, _instanceManager.CreateInstance<IMockedService>()); - Assert.AreSame(service, _instanceManager.CreateInstance<IMockedService>()); - Assert.AreSame(service, _instanceManager.CreateInstance<IMockedService>()); - Assert.AreSame(service, _instanceManager.CreateInstance<IMockedService>()); + IMockedService service = _instanceManager.GetInstance<IMockedService>(); + Assert.AreSame(service, _instanceManager.GetInstance<IMockedService>()); + Assert.AreSame(service, _instanceManager.GetInstance<IMockedService>()); + Assert.AreSame(service, _instanceManager.GetInstance<IMockedService>()); + Assert.AreSame(service, _instanceManager.GetInstance<IMockedService>()); } [Test] Modified: trunk/Source/StructureMap.Testing/BuildSessionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -138,14 +138,14 @@ [Test] public void If_no_child_array_is_explicitly_defined_return_all_instances() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.AddInstanceOf<IWidget>(new ColorWidget("Red")); registry.AddInstanceOf<IWidget>(new ColorWidget("Blue")); registry.AddInstanceOf<IWidget>(new ColorWidget("Green")); }); - WidgetHolder holder = manager.CreateInstance<WidgetHolder>(); + WidgetHolder holder = manager.GetInstance<WidgetHolder>(); Assert.AreEqual(3, holder.Widgets.Length); } Modified: trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -62,11 +62,11 @@ InstanceManager manager = new InstanceManager(graph); - GrandChild tommy = (GrandChild) manager.CreateInstance(typeof (GrandChild), "Tommy"); + GrandChild tommy = (GrandChild) manager.GetInstance(typeof (GrandChild), "Tommy"); Assert.AreEqual(false, tommy.RightHanded); Assert.AreEqual(1972, tommy.BirthYear); - ColorWidget blue = (ColorWidget) manager.CreateInstance(typeof (IWidget), "Blue"); + ColorWidget blue = (ColorWidget) manager.GetInstance(typeof (IWidget), "Blue"); Assert.AreEqual("Blue", blue.Color); } } Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -46,33 +46,33 @@ #endregion - private IInstanceManager manager; + private IContainer manager; [Test] public void AddAnInstanceWithANameAndAPropertySpecifyingConcreteKey() { - ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>("Purple"); + ColorWidget widget = (ColorWidget) manager.GetInstance<IWidget>("Purple"); Assert.AreEqual("Purple", widget.Color); } [Test] public void AddAnInstanceWithANameAndAPropertySpecifyingConcreteType() { - ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>("DarkGreen"); + ColorWidget widget = (ColorWidget) manager.GetInstance<IWidget>("DarkGreen"); Assert.AreEqual("DarkGreen", widget.Color); } [Test] public void AddInstanceAndOverrideTheConcreteTypeForADependency() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { // Specify a new Instance that specifies the concrete type used for a dependency registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName("AWidgetRule") .Child<IWidget>().IsConcreteType<AWidget>(); }); - WidgetRule rule = (WidgetRule) manager.CreateInstance<Rule>("AWidgetRule"); + WidgetRule rule = (WidgetRule) manager.GetInstance<Rule>("AWidgetRule"); Assert.IsInstanceOfType(typeof (AWidget), rule.Widget); } @@ -80,7 +80,7 @@ public void CreateAnInstancePullAPropertyFromTheApplicationConfig() { Assert.AreEqual("Blue", ConfigurationManager.AppSettings["Color"]); - ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>("AppSetting"); + ColorWidget widget = (ColorWidget) manager.GetInstance<IWidget>("AppSetting"); Assert.AreEqual("Blue", widget.Color); } @@ -93,7 +93,7 @@ registry.AddInstanceOf<IWidget>().UsingConcreteType<AWidget>().WithName("MyInstance"); }); - AWidget widget = (AWidget) manager.CreateInstance<IWidget>("MyInstance"); + AWidget widget = (AWidget) manager.GetInstance<IWidget>("MyInstance"); Assert.IsNotNull(widget); } @@ -115,9 +115,9 @@ .Child<IWidget>("widget").IsNamedInstance("Purple"); }); - Assert.IsInstanceOfType(typeof (ARule), manager.CreateInstance<Rule>("Alias")); + Assert.IsInstanceOfType(typeof (ARule), manager.GetInstance<Rule>("Alias")); - WidgetRule rule = (WidgetRule) manager.CreateInstance<Rule>("RuleThatUsesMyInstance"); + WidgetRule rule = (WidgetRule) manager.GetInstance<Rule>("RuleThatUsesMyInstance"); ColorWidget widget = (ColorWidget) rule.Widget; Assert.AreEqual("Purple", widget.Color); } @@ -128,7 +128,7 @@ // Specify a new Instance, create an instance for a dependency on the fly string instanceKey = "OrangeWidgetRule"; - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName(instanceKey) .Child<IWidget>().Is( @@ -139,7 +139,7 @@ }); - WidgetRule rule = (WidgetRule) manager.CreateInstance<Rule>(instanceKey); + WidgetRule rule = (WidgetRule) manager.GetInstance<Rule>(instanceKey); ColorWidget widget = (ColorWidget) rule.Widget; Assert.AreEqual("Orange", widget.Color); } @@ -157,9 +157,9 @@ registry.AddPrototypeInstanceOf<IWidget>(theWidget).WithName("Jeremy"); }); - CloneableWidget widget1 = (CloneableWidget) manager.CreateInstance<IWidget>("Jeremy"); - CloneableWidget widget2 = (CloneableWidget) manager.CreateInstance<IWidget>("Jeremy"); - CloneableWidget widget3 = (CloneableWidget) manager.CreateInstance<IWidget>("Jeremy"); + CloneableWidget widget1 = (CloneableWidget) manager.GetInstance<IWidget>("Jeremy"); + CloneableWidget widget2 = (CloneableWidget) manager.GetInstance<IWidget>("Jeremy"); + CloneableWidget widget3 = (CloneableWidget) manager.GetInstance<IWidget>("Jeremy"); Assert.AreEqual("Jeremy", widget1.Name); Assert.AreEqual("Jeremy", widget2.Name); @@ -182,9 +182,9 @@ registry.AddInstanceOf<IWidget>(julia).WithName("Julia"); }); - CloneableWidget widget1 = (CloneableWidget) manager.CreateInstance<IWidget>("Julia"); - CloneableWidget widget2 = (CloneableWidget) manager.CreateInstance<IWidget>("Julia"); - CloneableWidget widget3 = (CloneableWidget) manager.CreateInstance<IWidget>("Julia"); + CloneableWidget widget1 = (CloneableWidget) manager.GetInstance<IWidget>("Julia"); + CloneableWidget widget2 = (CloneableWidget) manager.GetInstance<IWidget>("Julia"); + CloneableWidget widget3 = (CloneableWidget) manager.GetInstance<IWidget>("Julia"); Assert.AreSame(julia, widget1); Assert.AreSame(julia, widget2); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -30,7 +30,7 @@ [Test] public void A_concrete_type_is_available_by_name_when_it_is_added_by_the_shorthand_mechanism() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<IAddTypes>() .AddConcreteType<RedAddTypes>("Red") @@ -39,15 +39,15 @@ .AddConcreteType<PurpleAddTypes>(); }); - Assert.IsInstanceOfType(typeof (RedAddTypes), manager.CreateInstance<IAddTypes>("Red")); - Assert.IsInstanceOfType(typeof (GreenAddTypes), manager.CreateInstance<IAddTypes>("Green")); - Assert.IsInstanceOfType(typeof (BlueAddTypes), manager.CreateInstance<IAddTypes>("Blue")); + Assert.IsInstanceOfType(typeof (RedAddTypes), manager.GetInstance<IAddTypes>("Red")); + Assert.IsInstanceOfType(typeof (GreenAddTypes), manager.GetInstance<IAddTypes>("Green")); + Assert.IsInstanceOfType(typeof (BlueAddTypes), manager.GetInstance<IAddTypes>("Blue")); } [Test] public void A_concrete_type_is_available_when_it_is_added_by_the_shorthand_mechanism() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<IAddTypes>() .AddConcreteType<RedAddTypes>() @@ -64,7 +64,7 @@ [Test] public void Make_sure_that_we_dont_double_dip_instances_when_we_register_a_type_with_a_name() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<IAddTypes>() .AddConcreteType<RedAddTypes>("Red") Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -31,7 +31,7 @@ Concretion concretion1 = new Concretion(); Concretion concretion2 = new Concretion(); - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<Abstraction>() .AddInstances( @@ -40,8 +40,8 @@ ); }); - Assert.AreSame(concretion1, manager.CreateInstance<Abstraction>("One")); - Assert.AreSame(concretion2, manager.CreateInstance<Abstraction>("Two")); + Assert.AreSame(concretion1, manager.GetInstance<Abstraction>("One")); + Assert.AreSame(concretion2, manager.GetInstance<Abstraction>("Two")); } [Test] @@ -49,14 +49,14 @@ { Concretion concretion = new Concretion(); - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<Abstraction>().TheDefaultIs( ConstructedBy<Abstraction>(delegate { return concretion; }) ); }); - Assert.AreSame(concretion, manager.CreateInstance<Abstraction>()); + Assert.AreSame(concretion, manager.GetInstance<Abstraction>()); } [Test] @@ -65,7 +65,7 @@ Concretion concretion1 = new Concretion(); Concretion concretion2 = new Concretion(); - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<Abstraction>().AddInstance( ConstructedBy<Abstraction>(delegate { return concretion1; }).WithName("One") @@ -76,8 +76,8 @@ ); }); - Assert.AreSame(concretion1, manager.CreateInstance<Abstraction>("One")); - Assert.AreSame(concretion2, manager.CreateInstance<Abstraction>("Two")); + Assert.AreSame(concretion1, manager.GetInstance<Abstraction>("One")); + Assert.AreSame(concretion2, manager.GetInstance<Abstraction>("Two")); } [Test] @@ -85,7 +85,7 @@ { Concretion concretion = new Concretion(); - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<Abstraction>().AddInstance( ConstructedBy<Abstraction>(delegate { return concretion; }) Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -60,7 +60,7 @@ [Test] public void AddInstanceByNameOnlyAddsOneInstanceToStructureMap() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<Something>().AddInstance( RegistryExpressions.Instance<Something>().UsingConcreteType<RedSomething>().WithName("Red") @@ -73,7 +73,7 @@ [Test] public void AddInstanceWithNameOnlyAddsOneInstanceToStructureMap() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.AddInstanceOf<Something>().UsingConcreteType<RedSomething>().WithName("Red"); }); @@ -144,7 +144,7 @@ Assert.IsTrue(pluginGraph.ContainsFamily(typeof (IGateway))); InstanceManager manager = new InstanceManager(pluginGraph); - IGateway gateway = (IGateway) manager.CreateInstance(typeof (IGateway)); + IGateway gateway = (IGateway) manager.GetInstance(typeof (IGateway)); Assert.IsInstanceOfType(typeof (StubbedGateway), gateway); } @@ -159,7 +159,7 @@ Assert.IsTrue(pluginGraph.ContainsFamily(typeof (IGateway))); InstanceManager manager = new InstanceManager(pluginGraph); - IGateway gateway = (IGateway) manager.CreateInstance(typeof (IGateway)); + IGateway gateway = (IGateway) manager.GetInstance(typeof (IGateway)); Assert.IsInstanceOfType(typeof (FakeGateway), gateway); } @@ -167,7 +167,7 @@ [Test] public void CreatePluginFamilyWithADefault() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.BuildInstancesOf<IWidget>().TheDefaultIs( RegistryExpressions.Instance<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo( @@ -175,7 +175,7 @@ ); }); - ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>(); + ColorWidget widget = (ColorWidget) manager.GetInstance<IWidget>(); Assert.AreEqual("Red", widget.Color); } @@ -199,7 +199,7 @@ new InstanceManager( delegate(Registry registry) { registry.ForRequestedType<IWidget>().TheDefaultIs(delegate { return new AWidget(); }); }); - Assert.IsInstanceOfType(typeof (AWidget), manager.CreateInstance<IWidget>()); + Assert.IsInstanceOfType(typeof (AWidget), manager.GetInstance<IWidget>()); } [Test] @@ -211,19 +211,19 @@ new InstanceManager( delegate(Registry registry) { registry.ForRequestedType<IWidget>().TheDefaultIs(aWidget); }); - Assert.AreSame(aWidget, manager.CreateInstance<IWidget>()); + Assert.AreSame(aWidget, manager.GetInstance<IWidget>()); } [Test] public void TheDefaultInstanceIsConcreteType() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { // Needs to blow up if the concrete type can't be used registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<ARule>(); }); - Assert.IsInstanceOfType(typeof (ARule), manager.CreateInstance<Rule>()); + Assert.IsInstanceOfType(typeof (ARule), manager.GetInstance<Rule>()); } [Test] @@ -238,7 +238,7 @@ Assert.IsTrue(pluginGraph.ContainsFamily(typeof (IGateway))); InstanceManager manager = new InstanceManager(pluginGraph); - IGateway gateway = (IGateway) manager.CreateInstance(typeof (IGateway)); + IGateway gateway = (IGateway) manager.GetInstance(typeof (IGateway)); Assert.IsInstanceOfType(typeof (DefaultGateway), gateway); } Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -12,8 +12,8 @@ private void assertThingMatches(Action<Registry> action) { - IInstanceManager manager = new InstanceManager(action); - Thing actual = manager.CreateInstance<Thing>(); + IContainer manager = new InstanceManager(action); + Thing actual = manager.GetInstance<Thing>(); Assert.AreEqual(_prototype, actual); } Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -65,9 +65,9 @@ }); - Assert.IsInstanceOfType(typeof(Target1), manager.CreateInstance<ITarget>("1")); - Assert.IsInstanceOfType(typeof(Target2), manager.CreateInstance<ITarget>("2")); - Assert.IsInstanceOfType(typeof(Target3), manager.CreateInstance<ITarget>("3")); + Assert.IsInstanceOfType(typeof(Target1), manager.GetInstance<ITarget>("1")); + Assert.IsInstanceOfType(typeof(Target2), manager.GetInstance<ITarget>("2")); + Assert.IsInstanceOfType(typeof(Target3), manager.GetInstance<ITarget>("3")); } [Test] @@ -78,7 +78,7 @@ r.ForRequestedType(typeof (ITarget)).TheDefaultIsConcreteType(typeof (Target3)); }); - Assert.IsInstanceOfType(typeof(Target3), manager.CreateInstance<ITarget>()); + Assert.IsInstanceOfType(typeof(Target3), manager.GetInstance<ITarget>()); } [Test] @@ -89,7 +89,7 @@ r.ForRequestedType(typeof(ITarget)).TheDefaultIs(Instance<Target2>()); }); - Assert.IsInstanceOfType(typeof(Target2), manager.CreateInstance<ITarget>()); + Assert.IsInstanceOfType(typeof(Target2), manager.GetInstance<ITarget>()); } [Test] @@ -100,7 +100,7 @@ r.ForRequestedType(typeof(ITarget)).TheDefaultIs(delegate() { return new Target1(); }); }); - Assert.IsInstanceOfType(typeof(Target1), manager.CreateInstance<ITarget>()); + Assert.IsInstanceOfType(typeof(Target1), manager.GetInstance<ITarget>()); } [Test] @@ -125,7 +125,7 @@ .EnrichWith(delegate(object raw){ return new WrappedTarget((ITarget) raw);}); }); - WrappedTarget target = (WrappedTarget) manager.CreateInstance<ITarget>(); + WrappedTarget target = (WrappedTarget) manager.GetInstance<ITarget>(); Assert.IsInstanceOfType(typeof(Target1), target.Inner); } @@ -171,7 +171,7 @@ .OnCreation(delegate(object raw) { created = (ITarget) raw; }); }); - manager.CreateInstance<ITarget>(); + manager.GetInstance<ITarget>(); Assert.IsInstanceOfType(typeof(Target3), created); } Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -82,7 +82,7 @@ [Test] public void CanStillAddOtherPropertiesAfterTheCallToChildArray() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<Processor>() .TheDefaultIs( @@ -96,14 +96,14 @@ ); }); - Processor processor = manager.CreateInstance<Processor>(); + Processor processor = manager.GetInstance<Processor>(); Assert.AreEqual("Jeremy", processor.Name); } [Test] public void InjectPropertiesByName() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<Processor2>() .TheDefaultIs( @@ -120,7 +120,7 @@ }); - Processor2 processor = manager.CreateInstance<Processor2>(); + Processor2 processor = manager.GetInstance<Processor2>(); Assert.IsInstanceOfType(typeof (Handler1), processor.First[0]); Assert.IsInstanceOfType(typeof (Handler2), processor.First[1]); @@ -153,7 +153,7 @@ [Test] public void PlaceMemberInArrayByReference() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.AddInstanceOf<IHandler>().UsingConcreteType<Handler1>().WithName("One"); registry.AddInstanceOf<IHandler>().UsingConcreteType<Handler2>().WithName("Two"); @@ -169,7 +169,7 @@ ); }); - Processor processor = manager.CreateInstance<Processor>(); + Processor processor = manager.GetInstance<Processor>(); Assert.IsInstanceOfType(typeof (Handler2), processor.Handlers[0]); Assert.IsInstanceOfType(typeof (Handler1), processor.Handlers[1]); @@ -178,7 +178,7 @@ [Test] public void ProgrammaticallyInjectArrayAllInline() { - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.ForRequestedType<Processor>() .TheDefaultIs( @@ -192,7 +192,7 @@ ); }); - Processor processor = manager.CreateInstance<Processor>(); + Processor processor = manager.GetInstance<Processor>(); Assert.IsInstanceOfType(typeof (Handler1), processor.Handlers[0]); Assert.IsInstanceOfType(typeof (Handler2), processor.Handlers[1]); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -31,7 +31,7 @@ #endregion private IService _lastService; - private IInstanceManager _manager; + private IContainer _manager; private Action<Registry> _defaultRegistry; private IService getService(Action<Registry> action, string name) @@ -45,7 +45,7 @@ }); } - return _manager.CreateInstance<IService>(name); + return _manager.GetInstance<IService>(name); } [Test] Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -47,12 +47,12 @@ private ColorService _lastService; - private IInstanceManager _manager; + private IContainer _manager; [Test] public void DecorateAConstructedService() { - IService service = _manager.CreateInstance<IService>("Purple"); + IService service = _manager.GetInstance<IService>("Purple"); DecoratorService decoratorService = (DecoratorService) service; ColorService innerService = (ColorService) decoratorService.Inner; @@ -62,7 +62,7 @@ [Test] public void DecorateInline() { - IService service = _manager.CreateInstance<IService>("Decorated"); + IService service = _manager.GetInstance<IService>("Decorated"); DecoratorService decoratorService = (DecoratorService) service; ColorService innerService = (ColorService) decoratorService.Inner; @@ -74,7 +74,7 @@ public void OnCreationWithAConstructedService() { Assert.IsNull(_lastService); - IService interceptedService = _manager.CreateInstance<IService>("Yellow"); + IService interceptedService = _manager.GetInstance<IService>("Yellow"); Assert.AreSame(_lastService, interceptedService); } @@ -85,10 +85,10 @@ // "NotIntercepted" should not. Assert.IsNull(_lastService); - _manager.CreateInstance<IService>("NotIntercepted"); + _manager.GetInstance<IService>("NotIntercepted"); Assert.IsNull(_lastService); - IService interceptedService = _manager.CreateInstance<IService>("Intercepted"); + IService interceptedService = _manager.GetInstance<IService>("Intercepted"); Assert.AreSame(_lastService, interceptedService); } @@ -97,7 +97,7 @@ { try { - _manager.CreateInstance<IService>("Bad"); + _manager.GetInstance<IService>("Bad"); Assert.Fail("Should have thrown an error"); } catch (StructureMapException e) Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -58,7 +58,7 @@ InstanceManager manager = new InstanceManager(graph); manager.SetDefaultsToProfile(theProfileName); - AWidget widget = (AWidget)manager.CreateInstance<IWidget>(); + AWidget widget = (AWidget)manager.GetInstance<IWidget>(); Assert.IsNotNull(widget); } @@ -83,7 +83,7 @@ { string theProfileName = "something"; - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.CreateProfile(theProfileName) .For<IWidget>().UseConcreteType<AWidget>() @@ -91,8 +91,8 @@ }); manager.SetDefaultsToProfile(theProfileName); - Assert.IsInstanceOfType(typeof(AWidget), manager.CreateInstance<IWidget>()); - Assert.IsInstanceOfType(typeof(DefaultRule), manager.CreateInstance<Rule>()); + Assert.IsInstanceOfType(typeof(AWidget), manager.GetInstance<IWidget>()); + Assert.IsInstanceOfType(typeof(DefaultRule), manager.GetInstance<Rule>()); } @@ -101,7 +101,7 @@ { string theProfileName = "something"; - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.CreateProfile(theProfileName) .For<IWidget>().Use(delegate() { return new AWidget(); }) @@ -112,8 +112,8 @@ manager.SetDefaultsToProfile(theProfileName); - Assert.IsInstanceOfType(typeof(AWidget), manager.CreateInstance<IWidget>()); - Assert.IsInstanceOfType(typeof(DefaultRule), manager.CreateInstance<Rule>()); + Assert.IsInstanceOfType(typeof(AWidget), manager.GetInstance<IWidget>()); + Assert.IsInstanceOfType(typeof(DefaultRule), manager.GetInstance<Rule>()); } [Test] @@ -122,7 +122,7 @@ string theProfileName = "something"; IWidget theTemplate = new AWidget(); - IInstanceManager manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new InstanceManager(delegate(Registry registry) { registry.CreateProfile(theProfileName) .For<IWidget>().UsePrototypeOf(theTemplate); @@ -130,8 +130,8 @@ manager.SetDefaultsToProfile(theProfileName); - IWidget widget1 = manager.CreateInstance<IWidget>(); - IWidget widget2 = manager.CreateInstance<IWidget>(); + IWidget widget1 = manager.GetInstance<IWidget>(); + IWidget widget2 = manager.GetInstance<IWidget>(); Assert.IsNotNull(widget1); Assert.IsNotNull(widget2); Modified: trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -39,20 +39,20 @@ [Test] public void GetTheRule() { - ColorRule rule = (ColorRule) _manager.CreateInstance<Rule>(); + ColorRule rule = (ColorRule) _manager.GetInstance<Rule>(); Assert.AreEqual("Blue", rule.Color); - ColorRule rule2 = (ColorRule) _manager.CreateInstance<Rule>(); + ColorRule rule2 = (ColorRule) _manager.GetInstance<Rule>(); Assert.AreSame(rule, rule2); } [Test] public void GetTheWidget() { - ColorWidget widget = (ColorWidget) _manager.CreateInstance<IWidget>(); + ColorWidget widget = (ColorWidget) _manager.GetInstance<IWidget>(); Assert.AreEqual("Red", widget.Color); - ColorWidget widget2 = (ColorWidget) _manager.CreateInstance<IWidget>(); + ColorWidget widget2 = (ColorWidget) _manager.GetInstance<IWidget>(); Assert.AreNotSame(widget, widget2); } } Modified: trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -87,7 +87,7 @@ ProfileBuilder.OverrideMachineName("GREEN-BOX"); InstanceManager manager = new InstanceManager(graph); - ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>(); + ColorWidget widget = (ColorWidget) manager.GetInstance<IWidget>(); Assert.AreEqual("Green", widget.Color); } @@ -97,7 +97,7 @@ ProfileBuilder.OverrideMachineName("ORANGE-BOX"); InstanceManager manager = new InstanceManager(graph); - ColorWidget widget = (ColorWidget)manager.CreateInstance<IWidget>(); + ColorWidget widget = (ColorWidget)manager.GetInstance<IWidget>(); Assert.AreEqual("Orange", widget.Color); } @@ -108,7 +108,7 @@ manager.SetDefaultsToProfile("Green"); - ColorWidget widget = (ColorWidget)manager.CreateInstance<IWidget>(); + ColorWidget widget = (ColorWidget)manager.GetInstance<IWidget>(); Assert.AreEqual("Green", widget.Color); } @@ -118,10 +118,10 @@ InstanceManager manager = new InstanceManager(graph); manager.SetDefaultsToProfile("Blue"); - ColorRule rule = (ColorRule) manager.CreateInstance<Rule>(); + ColorRule rule = (ColorRule) manager.GetInstance<Rule>(); Assert.AreEqual("Blue", rule.Color); - ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>(); + ColorWidget widget = (ColorWidget) manager.GetInstance<IWidget>(); Assert.AreEqual("Blue", widget.Color); } @@ -133,7 +133,7 @@ ProfileBuilder.OverrideMachineName("ORANGE-BOX"); InstanceManager manager = new InstanceManager(graph); - ColorWidget widget = (ColorWidget)manager.CreateInstance(typeof(IWidget)); + ColorWidget widget = (ColorWidget)manager.GetInstance(typeof(IWidget)); Assert.AreEqual("Orange", widget.Color); } @@ -143,7 +143,7 @@ ProfileBuilder.OverrideMachineName("GREEN-BOX"); InstanceManager manager = new InstanceManager(graph); - ColorWidget widget = (ColorWidget)manager.CreateInstance(typeof(IWidget)); + ColorWidget widget = (ColorWidget)manager.GetInstance(typeof(IWidget)); Assert.AreEqual("Green", widget.Color); } @@ -153,12 +153,12 @@ InstanceManager manager = new InstanceManager(graph); manager.SetDefaultsToProfile("Green"); - ColorRule greenRule = (ColorRule)manager.CreateInstance(typeof(Rule)); + ColorRule greenRule = (ColorRule)manager.GetInstance(typeof(Rule)); Assert.AreEqual("Green", greenRule.Color); manager.SetDefaultsToProfile("Blue"); - ColorRule blueRule = (ColorRule)manager.CreateInstance(typeof(Rule)); + ColorRule blueRule = (ColorRule)manager.GetInstance(typeof(Rule)); Assert.AreEqual("Blue", blueRule.Color); } } Modified: trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs 2008-05-28 03:35:02 UTC (rev 106) +++ trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs 2008-05-28 03:58:49 UTC (rev 107) @@ -49,17 +49,17 @@ [Test] public void GetTheRule() { - ColorRule rule = (ColorRule) _manager.CreateInstance<Rule>("Blue"); + ColorRule rule = (ColorRule) _manager.GetInstance<Rule>("Blue"); ... [truncated message content] |
From: <jer...@us...> - 2008-05-28 04:02:57
|
Revision: 108 http://structuremap.svn.sourceforge.net/structuremap/?rev=108&view=rev Author: jeremydmiller Date: 2008-05-27 21:02:54 -0700 (Tue, 27 May 2008) Log Message: ----------- renaming InstanceManager to Container Modified Paths: -------------- trunk/Source/StructureMap/Configuration/GraphBuilder.cs trunk/Source/StructureMap/IContainer.cs trunk/Source/StructureMap/InstanceBuilder.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/PluginGraphBuilder.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs trunk/Source/StructureMap.Testing/BuildSessionTester.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs trunk/Source/StructureMap.Testing/Container/ExceptionHandling/StructureMapExceptionTester.cs trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs trunk/Source/StructureMap.Testing/Container/FillDependenciesTester.cs trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs trunk/Source/StructureMap.Testing/Container/IntegratedTester.cs trunk/Source/StructureMap.Testing/Container/Interceptors/TypeInterceptionTester.cs trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs trunk/Source/StructureMap.Testing/Container/TypeFindingTester.cs trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs trunk/Source/StructureMap.Testing/Graph/PluginTester.cs trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs trunk/Source/StructureMap.Testing/ObjectMother.cs Added Paths: ----------- trunk/Source/StructureMap/Container.cs Modified: trunk/Source/StructureMap/Configuration/GraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -11,7 +11,7 @@ private readonly PluginGraph _pluginGraph; private readonly PluginGraph _systemGraph; private Profile _profile; - private InstanceManager _systemInstanceManager; + private Container _systemContainer; public GraphBuilder(Registry[] registries) : this(registries, new PluginGraph()) @@ -110,12 +110,12 @@ { Instance instance = memento.ReadInstance(_systemGraph, type); - if (_systemInstanceManager == null) + if (_systemContainer == null) { - _systemInstanceManager = new InstanceManager(_systemGraph); + _systemContainer = new Container(_systemGraph); } - return _systemInstanceManager.GetInstance(type, instance); + return _systemContainer.GetInstance(type, instance); } } } \ No newline at end of file Added: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs (rev 0) +++ trunk/Source/StructureMap/Container.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -0,0 +1,291 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Text; +using StructureMap.Configuration.DSL; +using StructureMap.Diagnostics; +using StructureMap.Graph; +using StructureMap.Interceptors; +using StructureMap.Pipeline; + +namespace StructureMap +{ + /// <summary> + /// A collection of IInstanceFactory's. + /// </summary> + public class Container : TypeRules, IContainer + { + private InterceptorLibrary _interceptorLibrary; + private PipelineGraph _pipelineGraph; + + public Container(Action<Registry> action) + { + Registry registry = new Registry(); + action(registry); + + construct(registry.Build()); + } + + public Container(Registry registry) : this(registry.Build()) + { + } + + public Container() : this(new PluginGraph()) + { + } + + /// <summary> + /// Constructor to create an Container + /// </summary> + /// <param name="pluginGraph">PluginGraph containing the instance and type definitions + /// for the Container</param> + /// <param name="failOnException">Flags the Container to fail or trap exceptions</param> + public Container(PluginGraph pluginGraph) + { + construct(pluginGraph); + } + + private void construct(PluginGraph pluginGraph) + { + _interceptorLibrary = pluginGraph.InterceptorLibrary; + + if (!pluginGraph.IsSealed) + { + pluginGraph.Seal(); + } + + pluginGraph.Log.AssertFailures(); + + _pipelineGraph = new PipelineGraph(pluginGraph); + } + + protected MissingFactoryFunction onMissingFactory + { + set { _pipelineGraph.OnMissingFactory = value; } + } + + #region IContainer Members + + public T GetInstance<T>(string instanceKey) + { + return (T) GetInstance(typeof (T), instanceKey); + } + + public T GetInstance<T>(Instance instance) + { + return (T) GetInstance(typeof (T), instance); + } + + public PLUGINTYPE GetInstance<PLUGINTYPE>(ExplicitArguments args) + { + Instance defaultInstance = _pipelineGraph.GetDefault(typeof (PLUGINTYPE)); + + ExplicitInstance<PLUGINTYPE> instance = new ExplicitInstance<PLUGINTYPE>(args, defaultInstance); + return GetInstance<PLUGINTYPE>(instance); + } + + public void Inject<PLUGINTYPE>(PLUGINTYPE instance) + { + _pipelineGraph.Inject(instance); + } + + public void InjectByName<PLUGINTYPE>(PLUGINTYPE instance, string instanceKey) + { + LiteralInstance literalInstance = new LiteralInstance(instance); + literalInstance.Name = instanceKey; + + AddInstance<PLUGINTYPE>(literalInstance); + } + + public void InjectByName<PLUGINTYPE, CONCRETETYPE>(string instanceKey) + { + ConfiguredInstance instance = new ConfiguredInstance(typeof(CONCRETETYPE)); + instance.Name = instanceKey; + + AddInstance<PLUGINTYPE>(instance); + } + + public T GetInstance<T>() + { + return (T) GetInstance(typeof (T)); + } + + public T FillDependencies<T>() + { + return (T) FillDependencies(typeof (T)); + } + + public void InjectStub<T>(T instance) + { + InjectStub(typeof (T), instance); + } + + public IList<T> GetAllInstances<T>() + { + List<T> list = new List<T>(); + + IBuildSession session = withNewSession(); + + foreach (T instance in forType(typeof (T)).GetAllInstances(session)) + { + list.Add(instance); + } + + return list; + } + + public void SetDefaultsToProfile(string profile) + { + _pipelineGraph.CurrentProfile = profile; + } + + /// <summary> + /// Creates the named instance of the PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instanceKey"></param> + /// <returns></returns> + public object GetInstance(Type pluginType, string instanceKey) + { + return withNewSession().CreateInstance(pluginType, instanceKey); + } + + + /// <summary> + /// Creates a new object instance of the requested type + /// </summary> + /// <param name="pluginType"></param> + /// <returns></returns> + public object GetInstance(Type pluginType) + { + return withNewSession().CreateInstance(pluginType); + } + + + /// <summary> + /// Creates a new instance of the requested type using the InstanceMemento. Mostly used from other + /// classes to link children members + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instance"></param> + /// <returns></returns> + public object GetInstance(Type pluginType, Instance instance) + { + return withNewSession().CreateInstance(pluginType, instance); + } + + /// <summary> + /// Sets the default instance for the PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instance"></param> + public void SetDefault(Type pluginType, Instance instance) + { + _pipelineGraph.SetDefault(pluginType, instance); + } + + /// <summary> + /// Sets the default instance for the PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instanceKey"></param> + public void SetDefault(Type pluginType, string instanceKey) + { + ReferencedInstance reference = new ReferencedInstance(instanceKey); + _pipelineGraph.SetDefault(pluginType, reference); + } + + + /// <summary> + /// Attempts to create a new instance of the requested type. Automatically inserts the default + /// configured instance for each dependency in the StructureMap constructor function. + /// </summary> + /// <param name="type"></param> + /// <returns></returns> + public object FillDependencies(Type type) + { + if (!IsConcrete(type)) + { + throw new StructureMapException(230, type.FullName); + } + + Plugin plugin = new Plugin(type); + if (!plugin.CanBeAutoFilled) + { + throw new StructureMapException(230, type.FullName); + } + + return GetInstance(type); + } + + /// <summary> + /// Sets up the Container to return the object in the "stub" argument anytime + /// any instance of the PluginType is requested + /// </summary> + /// <param name="pluginType"></param> + /// <param name="stub"></param> + public void InjectStub(Type pluginType, object stub) + { + if (!CanBeCast(pluginType, stub.GetType())) + { + throw new StructureMapException(220, pluginType.FullName, + stub.GetType().FullName); + } + + + LiteralInstance instance = new LiteralInstance(stub); + _pipelineGraph.SetDefault(pluginType, instance); + } + + public IList GetAllInstances(Type type) + { + return forType(type).GetAllInstances(withNewSession()); + } + + public void AddInstance<T>(Instance instance) + { + _pipelineGraph.AddInstance<T>(instance); + } + + public void AddInstance<PLUGINTYPE, CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE + { + _pipelineGraph.AddInstance<PLUGINTYPE, CONCRETETYPE>(); + } + + public void AddDefaultInstance<PLUGINTYPE, CONCRETETYPE>() + { + _pipelineGraph.AddDefaultInstance<PLUGINTYPE, CONCRETETYPE>(); + } + + public string WhatDoIHave() + { + WhatDoIHaveWriter writer = new WhatDoIHaveWriter(_pipelineGraph); + return writer.GetText(); + } + + public ExplicitArgsExpression With<T>(T arg) + { + return new ExplicitArgsExpression(this).With<T>(arg); + } + + public IExplicitProperty With(string argName) + { + return new ExplicitArgsExpression(this).With(argName); + } + + #endregion + + private IBuildSession withNewSession() + { + return new BuildSession(_pipelineGraph, _interceptorLibrary); + } + + + protected IInstanceFactory forType(Type type) + { + return _pipelineGraph.ForType(type); + } + + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/IContainer.cs =================================================================== --- trunk/Source/StructureMap/IContainer.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap/IContainer.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -18,7 +18,7 @@ T GetInstance<T>(Instance instance); /// <summary> - /// Sets up the InstanceManager to return the object in the "stub" argument anytime + /// Sets up the Container to return the object in the "stub" argument anytime /// any instance of the PluginType is requested /// </summary> /// <param name="pluginType"></param> Modified: trunk/Source/StructureMap/InstanceBuilder.cs =================================================================== --- trunk/Source/StructureMap/InstanceBuilder.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap/InstanceBuilder.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -9,7 +9,7 @@ /// </summary> public abstract class InstanceBuilder { - private InstanceManager _manager; + private Container _manager; public InstanceBuilder() { Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -129,7 +129,7 @@ manager.AddInstance<PLUGINTYPE, CONCRETETYPE>(); } - #region InstanceManager and setting defaults + #region Container and setting defaults private static IContainer manager { @@ -226,14 +226,14 @@ } - private static InstanceManager buildManager() + private static Container buildManager() { PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); - InstanceManager instanceManager = new InstanceManager(graph); - instanceManager.SetDefaultsToProfile(_profile); + Container container = new Container(graph); + container.SetDefaultsToProfile(_profile); - return instanceManager; + return container; } #endregion Modified: trunk/Source/StructureMap/PluginGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/PluginGraphBuilder.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap/PluginGraphBuilder.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -9,7 +9,7 @@ { /// <summary> /// Reads configuration XML documents and builds the structures necessary to initialize - /// the InstanceManager/IInstanceFactory/InstanceBuilder/ObjectInstanceActivator objects + /// the Container/IInstanceFactory/InstanceBuilder/ObjectInstanceActivator objects /// </summary> public class PluginGraphBuilder { Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-05-28 04:02:54 UTC (rev 108) @@ -292,7 +292,7 @@ <Compile Include="InstanceFactory.cs"> <SubType>Code</SubType> </Compile> - <Compile Include="InstanceManager.cs"> + <Compile Include="Container.cs"> <SubType>Code</SubType> </Compile> <Compile Include="InstanceMemento.cs"> Modified: trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -4,7 +4,7 @@ namespace StructureMap.AutoMocking { - public class AutoMockedInstanceManager : InstanceManager + public class AutoMockedInstanceManager : Container { private readonly ServiceLocator _locator; Modified: trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -22,8 +22,8 @@ _manager = new AutoMockedInstanceManager(locator); } - // Replaces the inner InstanceManager in ObjectFactory with the mocked - // InstanceManager from the auto mocking container. This will make ObjectFactory + // Replaces the inner Container in ObjectFactory with the mocked + // Container from the auto mocking container. This will make ObjectFactory // return mocks for everything. Use cautiously!!!!!!!!!!!!!!! // Gets the ClassUnderTest with mock objects (or stubs) pushed in Modified: trunk/Source/StructureMap.Testing/BuildSessionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -138,7 +138,7 @@ [Test] public void If_no_child_array_is_explicitly_defined_return_all_instances() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.AddInstanceOf<IWidget>(new ColorWidget("Red")); registry.AddInstanceOf<IWidget>(new ColorWidget("Blue")); Modified: trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -60,7 +60,7 @@ PluginGraphBuilder builder = new PluginGraphBuilder(parser); PluginGraph graph = builder.Build(); - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); GrandChild tommy = (GrandChild) manager.GetInstance(typeof (GrandChild), "Tommy"); Assert.AreEqual(false, tommy.RightHanded); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -16,7 +16,7 @@ public void SetUp() { - manager = new InstanceManager(delegate(Registry registry) + manager = new StructureMap.Container(delegate(Registry registry) { registry.ScanAssemblies().IncludeAssemblyContainingType<ColorWidget>(); @@ -65,7 +65,7 @@ [Test] public void AddInstanceAndOverrideTheConcreteTypeForADependency() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { // Specify a new Instance that specifies the concrete type used for a dependency registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName("AWidgetRule") @@ -87,7 +87,7 @@ [Test] public void SimpleCaseWithNamedInstance() { - manager = new InstanceManager(delegate(Registry registry) + manager = new StructureMap.Container(delegate(Registry registry) { // Specify a new Instance and override the Name registry.AddInstanceOf<IWidget>().UsingConcreteType<AWidget>().WithName("MyInstance"); @@ -100,7 +100,7 @@ [Test] public void SpecifyANewInstanceOverrideADependencyWithANamedInstance() { - manager = new InstanceManager(delegate(Registry registry) + manager = new StructureMap.Container(delegate(Registry registry) { registry.AddInstanceOf<Rule>().UsingConcreteType<ARule>().WithName("Alias"); @@ -128,7 +128,7 @@ // Specify a new Instance, create an instance for a dependency on the fly string instanceKey = "OrangeWidgetRule"; - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName(instanceKey) .Child<IWidget>().Is( @@ -152,7 +152,7 @@ CloneableWidget theWidget = new CloneableWidget("Jeremy"); - manager = new InstanceManager(delegate(Registry registry) + manager = new StructureMap.Container(delegate(Registry registry) { registry.AddPrototypeInstanceOf<IWidget>(theWidget).WithName("Jeremy"); }); @@ -177,7 +177,7 @@ // Return the specific instance when an IWidget named "Julia" is requested CloneableWidget julia = new CloneableWidget("Julia"); - manager = new InstanceManager(delegate(Registry registry) + manager = new StructureMap.Container(delegate(Registry registry) { registry.AddInstanceOf<IWidget>(julia).WithName("Julia"); }); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -30,7 +30,7 @@ [Test] public void A_concrete_type_is_available_by_name_when_it_is_added_by_the_shorthand_mechanism() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<IAddTypes>() .AddConcreteType<RedAddTypes>("Red") @@ -47,7 +47,7 @@ [Test] public void A_concrete_type_is_available_when_it_is_added_by_the_shorthand_mechanism() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<IAddTypes>() .AddConcreteType<RedAddTypes>() @@ -64,7 +64,7 @@ [Test] public void Make_sure_that_we_dont_double_dip_instances_when_we_register_a_type_with_a_name() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<IAddTypes>() .AddConcreteType<RedAddTypes>("Red") Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -31,7 +31,7 @@ Concretion concretion1 = new Concretion(); Concretion concretion2 = new Concretion(); - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<Abstraction>() .AddInstances( @@ -49,7 +49,7 @@ { Concretion concretion = new Concretion(); - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<Abstraction>().TheDefaultIs( ConstructedBy<Abstraction>(delegate { return concretion; }) @@ -65,7 +65,7 @@ Concretion concretion1 = new Concretion(); Concretion concretion2 = new Concretion(); - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<Abstraction>().AddInstance( ConstructedBy<Abstraction>(delegate { return concretion1; }).WithName("One") @@ -85,7 +85,7 @@ { Concretion concretion = new Concretion(); - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<Abstraction>().AddInstance( ConstructedBy<Abstraction>(delegate { return concretion; }) Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -38,8 +38,8 @@ [Test] public void Add_an_instance_by_lambda() { - InstanceManager manager = - new InstanceManager( + StructureMap.Container manager = + new StructureMap.Container( delegate(Registry registry) { registry.ForRequestedType<IWidget>().AddInstance(delegate { return new AWidget(); }); }); Assert.IsInstanceOfType(typeof (AWidget), manager.GetAllInstances<IWidget>()[0]); @@ -50,8 +50,8 @@ { AWidget aWidget = new AWidget(); - InstanceManager manager = - new InstanceManager( + StructureMap.Container manager = + new StructureMap.Container( delegate(Registry registry) { registry.ForRequestedType<IWidget>().AddInstance(aWidget); }); Assert.IsInstanceOfType(typeof (AWidget), manager.GetAllInstances<IWidget>()[0]); @@ -60,7 +60,7 @@ [Test] public void AddInstanceByNameOnlyAddsOneInstanceToStructureMap() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<Something>().AddInstance( RegistryExpressions.Instance<Something>().UsingConcreteType<RedSomething>().WithName("Red") @@ -73,7 +73,7 @@ [Test] public void AddInstanceWithNameOnlyAddsOneInstanceToStructureMap() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.AddInstanceOf<Something>().UsingConcreteType<RedSomething>().WithName("Red"); }); @@ -143,7 +143,7 @@ PluginGraph pluginGraph = registry.Build(); Assert.IsTrue(pluginGraph.ContainsFamily(typeof (IGateway))); - InstanceManager manager = new InstanceManager(pluginGraph); + StructureMap.Container manager = new StructureMap.Container(pluginGraph); IGateway gateway = (IGateway) manager.GetInstance(typeof (IGateway)); Assert.IsInstanceOfType(typeof (StubbedGateway), gateway); @@ -158,7 +158,7 @@ Assert.IsTrue(pluginGraph.ContainsFamily(typeof (IGateway))); - InstanceManager manager = new InstanceManager(pluginGraph); + StructureMap.Container manager = new StructureMap.Container(pluginGraph); IGateway gateway = (IGateway) manager.GetInstance(typeof (IGateway)); Assert.IsInstanceOfType(typeof (FakeGateway), gateway); @@ -167,7 +167,7 @@ [Test] public void CreatePluginFamilyWithADefault() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.BuildInstancesOf<IWidget>().TheDefaultIs( RegistryExpressions.Instance<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo( @@ -195,8 +195,8 @@ [Test] public void Set_the_default_by_a_lambda() { - InstanceManager manager = - new InstanceManager( + StructureMap.Container manager = + new StructureMap.Container( delegate(Registry registry) { registry.ForRequestedType<IWidget>().TheDefaultIs(delegate { return new AWidget(); }); }); Assert.IsInstanceOfType(typeof (AWidget), manager.GetInstance<IWidget>()); @@ -207,8 +207,8 @@ { AWidget aWidget = new AWidget(); - InstanceManager manager = - new InstanceManager( + StructureMap.Container manager = + new StructureMap.Container( delegate(Registry registry) { registry.ForRequestedType<IWidget>().TheDefaultIs(aWidget); }); Assert.AreSame(aWidget, manager.GetInstance<IWidget>()); @@ -217,7 +217,7 @@ [Test] public void TheDefaultInstanceIsConcreteType() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { // Needs to blow up if the concrete type can't be used registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<ARule>(); @@ -237,7 +237,7 @@ Assert.IsTrue(pluginGraph.ContainsFamily(typeof (IGateway))); - InstanceManager manager = new InstanceManager(pluginGraph); + StructureMap.Container manager = new StructureMap.Container(pluginGraph); IGateway gateway = (IGateway) manager.GetInstance(typeof (IGateway)); Assert.IsInstanceOfType(typeof (DefaultGateway), gateway); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -12,7 +12,7 @@ private void assertThingMatches(Action<Registry> action) { - IContainer manager = new InstanceManager(action); + IContainer manager = new StructureMap.Container(action); Thing actual = manager.GetInstance<Thing>(); Assert.AreEqual(_prototype, actual); } Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -45,7 +45,7 @@ [Test] public void Add_concrete_type() { - InstanceManager manager = new InstanceManager(delegate(Registry r) + StructureMap.Container manager = new StructureMap.Container(delegate(Registry r) { r.ForRequestedType(typeof(ITarget)).AddConcreteType(typeof(Target1)); }); @@ -57,7 +57,7 @@ [Test] public void Add_concrete_type_with_name() { - InstanceManager manager = new InstanceManager(delegate(Registry r) + StructureMap.Container manager = new StructureMap.Container(delegate(Registry r) { r.ForRequestedType(typeof(ITarget)).AddConcreteType(typeof(Target1), "1"); r.ForRequestedType(typeof(ITarget)).AddConcreteType(typeof(Target2), "2"); @@ -73,7 +73,7 @@ [Test] public void Add_default_by_concrete_type() { - InstanceManager manager = new InstanceManager(delegate(Registry r) + StructureMap.Container manager = new StructureMap.Container(delegate(Registry r) { r.ForRequestedType(typeof (ITarget)).TheDefaultIsConcreteType(typeof (Target3)); }); @@ -84,7 +84,7 @@ [Test] public void Add_default_instance() { - InstanceManager manager = new InstanceManager(delegate(Registry r) + StructureMap.Container manager = new StructureMap.Container(delegate(Registry r) { r.ForRequestedType(typeof(ITarget)).TheDefaultIs(Instance<Target2>()); }); @@ -95,7 +95,7 @@ [Test] public void Add_instance_by_lambda() { - InstanceManager manager = new InstanceManager(delegate(Registry r) + StructureMap.Container manager = new StructureMap.Container(delegate(Registry r) { r.ForRequestedType(typeof(ITarget)).TheDefaultIs(delegate() { return new Target1(); }); }); @@ -106,7 +106,7 @@ [Test] public void Add_instance_directly() { - InstanceManager manager = new InstanceManager(delegate(Registry r) + StructureMap.Container manager = new StructureMap.Container(delegate(Registry r) { r.ForRequestedType(typeof (ITarget)).AddInstance(Instance<Target2>()); }); @@ -118,7 +118,7 @@ [Test] public void Enrichment() { - InstanceManager manager = new InstanceManager(delegate(Registry r) + StructureMap.Container manager = new StructureMap.Container(delegate(Registry r) { r.ForRequestedType(typeof(ITarget)) .TheDefaultIsConcreteType(typeof(Target1)) @@ -164,7 +164,7 @@ { ITarget created = null; - InstanceManager manager = new InstanceManager(delegate(Registry r) + StructureMap.Container manager = new StructureMap.Container(delegate(Registry r) { r.ForRequestedType(typeof (ITarget)) .TheDefaultIsConcreteType(typeof (Target3)) Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -82,7 +82,7 @@ [Test] public void CanStillAddOtherPropertiesAfterTheCallToChildArray() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<Processor>() .TheDefaultIs( @@ -103,7 +103,7 @@ [Test] public void InjectPropertiesByName() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<Processor2>() .TheDefaultIs( @@ -153,7 +153,7 @@ [Test] public void PlaceMemberInArrayByReference() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.AddInstanceOf<IHandler>().UsingConcreteType<Handler1>().WithName("One"); registry.AddInstanceOf<IHandler>().UsingConcreteType<Handler2>().WithName("Two"); @@ -178,7 +178,7 @@ [Test] public void ProgrammaticallyInjectArrayAllInline() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<Processor>() .TheDefaultIs( Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -38,7 +38,7 @@ { if (_manager == null) { - _manager = new InstanceManager(delegate(Registry registry) + _manager = new StructureMap.Container(delegate(Registry registry) { _defaultRegistry(registry); action(registry); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -15,7 +15,7 @@ { _lastService = null; - _manager = new InstanceManager(delegate(Registry registry) + _manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<IService>().AddInstances ( Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -56,7 +56,7 @@ Assert.AreEqual(Profile.InstanceKeyForProfile(theProfileName), defaultInstance.Name); - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); manager.SetDefaultsToProfile(theProfileName); AWidget widget = (AWidget)manager.GetInstance<IWidget>(); Assert.IsNotNull(widget); @@ -83,7 +83,7 @@ { string theProfileName = "something"; - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.CreateProfile(theProfileName) .For<IWidget>().UseConcreteType<AWidget>() @@ -101,7 +101,7 @@ { string theProfileName = "something"; - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.CreateProfile(theProfileName) .For<IWidget>().Use(delegate() { return new AWidget(); }) @@ -122,7 +122,7 @@ string theProfileName = "something"; IWidget theTemplate = new AWidget(); - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.CreateProfile(theProfileName) .For<IWidget>().UsePrototypeOf(theTemplate); Modified: trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -21,12 +21,12 @@ "; _graph = DataMother.BuildPluginGraphFromXml(xml); - _manager = new InstanceManager(_graph); + _manager = new StructureMap.Container(_graph); } #endregion - private InstanceManager _manager; + private StructureMap.Container _manager; private PluginGraph _graph; [Test] Modified: trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -85,7 +85,7 @@ public void GettingTheRightInstanceKeyWhenUsingAMAchineOverrideInCombinationWithProfile() { ProfileBuilder.OverrideMachineName("GREEN-BOX"); - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); ColorWidget widget = (ColorWidget) manager.GetInstance<IWidget>(); Assert.AreEqual("Green", widget.Color); @@ -95,7 +95,7 @@ public void GotTheInstanceForTheMachineOverride() { ProfileBuilder.OverrideMachineName("ORANGE-BOX"); - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); ColorWidget widget = (ColorWidget)manager.GetInstance<IWidget>(); Assert.AreEqual("Orange", widget.Color); @@ -104,7 +104,7 @@ [Test] public void HasADefaultInstanceKey() { - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); manager.SetDefaultsToProfile("Green"); @@ -115,7 +115,7 @@ [Test] public void HasTheOverrideForProfile() { - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); manager.SetDefaultsToProfile("Blue"); ColorRule rule = (ColorRule) manager.GetInstance<Rule>(); @@ -131,7 +131,7 @@ public void InlineMachine1() { ProfileBuilder.OverrideMachineName("ORANGE-BOX"); - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); ColorWidget widget = (ColorWidget)manager.GetInstance(typeof(IWidget)); Assert.AreEqual("Orange", widget.Color); @@ -141,7 +141,7 @@ public void InlineMachine2() { ProfileBuilder.OverrideMachineName("GREEN-BOX"); - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); ColorWidget widget = (ColorWidget)manager.GetInstance(typeof(IWidget)); Assert.AreEqual("Green", widget.Color); @@ -150,7 +150,7 @@ [Test] public void SetTheProfile() { - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); manager.SetDefaultsToProfile("Green"); ColorRule greenRule = (ColorRule)manager.GetInstance(typeof(Rule)); Modified: trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -17,12 +17,12 @@ public void SetUp() { _graph = DataMother.GetPluginGraph("ShortInstance.xml"); - _manager = new InstanceManager(_graph); + _manager = new StructureMap.Container(_graph); } #endregion - private InstanceManager _manager; + private StructureMap.Container _manager; private PluginGraph _graph; [Test] Modified: trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -39,7 +39,7 @@ PluginGraph graph = builder.Build(); - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); Decision d1 = (Decision) manager.GetInstance(typeof (Decision), "RedBlue"); Assert.IsNotNull(d1); Modified: trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -59,7 +59,7 @@ [Test] public void AddInstanceToInstanceManagerWhenTheInstanceFactoryDoesNotExist() { - InstanceManager manager = new InstanceManager(new PluginGraph()); + StructureMap.Container manager = new StructureMap.Container(new PluginGraph()); manager.AddInstance<IService>(new LiteralInstance(_red).WithName("Red")); manager.AddInstance<IService>(new LiteralInstance(_blue).WithName("Blue")); @@ -99,7 +99,7 @@ PluginFamily family = pluginGraph.FindFamily(typeof(ISomething)); family.AddPlugin(typeof (SomethingOne), "One"); - InstanceManager manager = new InstanceManager(pluginGraph); + StructureMap.Container manager = new StructureMap.Container(pluginGraph); ConfiguredInstance instance = new ConfiguredInstance().WithConcreteKey("One").WithName("One"); manager.AddInstance<ISomething>(instance); @@ -113,7 +113,7 @@ public void AddPluginForTypeWhenThePluginDoesNotAlreadyExistsDoesNothing() { PluginGraph pluginGraph = new PluginGraph(); - InstanceManager manager = new InstanceManager(pluginGraph); + StructureMap.Container manager = new StructureMap.Container(pluginGraph); manager.AddInstance<ISomething, SomethingOne>(); Modified: trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -23,7 +23,7 @@ PluginFamily family = graph.FindFamily(typeof (Cow)); family.AddPlugin(typeof (Cow), "Default"); - InstanceManager manager = new InstanceManager(graph); + StructureMap.Container manager = new StructureMap.Container(graph); ConfiguredInstance instance = new ConfiguredInstance() .WithConcreteKey("Default").WithName("Angus") Modified: trunk/Source/StructureMap.Testing/Container/ExceptionHandling/StructureMapExceptionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/ExceptionHandling/StructureMapExceptionTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Container/ExceptionHandling/StructureMapExceptionTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -107,14 +107,14 @@ } - private void assertErrorIsThrown(int errorCode, string xml, Action<InstanceManager> action) + private void assertErrorIsThrown(int errorCode, string xml, Action<StructureMap.Container> action) { XmlDocument document = new XmlDocument(); document.LoadXml(xml.Replace("\"", "'")); ConfigurationParser parser = new ConfigurationParser(document.DocumentElement); PluginGraphBuilder builder = new PluginGraphBuilder(parser); - InstanceManager manager = new InstanceManager(builder.Build()); + StructureMap.Container manager = new StructureMap.Container(builder.Build()); try { @@ -154,7 +154,7 @@ <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''> </PluginFamily> </StructureMap> ", - delegate (InstanceManager manager) + delegate (StructureMap.Container manager) { manager.GetInstance<IWidget>("NotAnActualInstanceName"); } @@ -187,7 +187,7 @@ <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''></PluginFamily> </StructureMap> ", - delegate (InstanceManager manager) + delegate (StructureMap.Container manager) { manager.GetInstance<IWidget>(); } Modified: trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -123,7 +123,7 @@ [Test] public void PassAnArgumentIntoExplicitArgumentsForARequestedInterface() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<IProvider>().TheDefaultIsConcreteType<LumpProvider>(); }); @@ -158,7 +158,7 @@ [Test] public void PassExplicitArgsIntoInstanceManager() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { registry.ForRequestedType<ExplicitTarget>().TheDefaultIs( Registry.Instance<ExplicitTarget>() @@ -211,7 +211,7 @@ [Test] public void Fill_in_argument_by_name() { - InstanceManager manager = new InstanceManager(); + StructureMap.Container manager = new StructureMap.Container(); manager.AddDefaultInstance<IView, View>(); Node theNode = new Node(); @@ -230,7 +230,7 @@ [Test] public void Pass_in_arguments_as_dictionary() { - InstanceManager manager = new InstanceManager(); + StructureMap.Container manager = new StructureMap.Container(); manager.AddDefaultInstance<IView, View>(); Node theNode = new Node(); Modified: trunk/Source/StructureMap.Testing/Container/FillDependenciesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/FillDependenciesTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Container/FillDependenciesTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -14,7 +14,7 @@ { PluginGraph pluginGraph = ObjectMother.GetPluginGraph(); - InstanceManager manager = new InstanceManager(pluginGraph); + StructureMap.Container manager = new StructureMap.Container(pluginGraph); // The dependencies must have a default setting first manager.SetDefault(typeof (IStrategy), "Red"); @@ -33,7 +33,7 @@ public void TryToFillDependenciesOnAbstractClassThrowsException() { PluginGraph pluginGraph = ObjectMother.GetPluginGraph(); - InstanceManager manager = new InstanceManager(pluginGraph); + StructureMap.Container manager = new StructureMap.Container(pluginGraph); manager.FillDependencies(typeof (AbstractClass)); } @@ -43,7 +43,7 @@ public void TryToFillDependenciesOnClassWithPrimitiveArgumentsThrowsException() { PluginGraph pluginGraph = ObjectMother.GetPluginGraph(); - InstanceManager manager = new InstanceManager(pluginGraph); + StructureMap.Container manager = new StructureMap.Container(pluginGraph); manager.FillDependencies(typeof (CannotBeFilledConcreteClass)); } Modified: trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -33,7 +33,7 @@ PluginGraph pluginGraph = DataMother.GetDiagnosticPluginGraph("SampleConfig.xml"); - InstanceManager manager = new InstanceManager(pluginGraph); + StructureMap.Container manager = new StructureMap.Container(pluginGraph); IList list = manager.GetAllInstances(typeof (IWidget)); Modified: trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -17,7 +17,7 @@ [SetUp] public void SetUp() { - _manager = new InstanceManager(delegate(Registry registry) + _manager = new StructureMap.Container(delegate(Registry registry) { registry.BuildInstancesOf<Rule>(); registry.ScanAssemblies() @@ -29,7 +29,7 @@ #endregion - private InstanceManager _manager; + private StructureMap.Container _manager; Modified: trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs 2008-05-28 03:58:49 UTC (rev 107) +++ trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs 2008-05-28 04:02:54 UTC (rev 108) @@ -20,7 +20,7 @@ [SetUp] public void SetUp() { - _manager = new InstanceManager(delegate(Registry registry) + _manager = new StructureMap.Container(delegate(Registry registry) { registry.ScanAssemblies().IncludeAssembly("StructureMap.Testing.Widget"); registry.BuildInstancesOf<Rule>(); @@ -73,14 +73,14 @@ [Test] public void CanBuildConcreteTypesThatAreNotPreviouslyRegistered() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.Container(delegate(Registry registry) { - // Create a new InstanceManager that has a default instance configured for only the - // IProvider interface. InstanceManager is the real "container" behind ObjectFactory + // Create a new Container that has a default instance configured for only the + // IProvider interface. Container is the real "container" behind ObjectFactory registry.ForRequestedType<IProvider>().TheDefaultIsConcreteType<Provider>(); }); - // Now, have that same InstanceManager create a ClassThatUsesProvider. StructureMap will + // Now, have that same Container create a ClassThatUsesProvider. StructureMap will // see that ClassThatUsesProvider is concrete, determine its constructor args, and build one // for you with the default IProvider. No other configuration necessary. ClassThatUsesProvider classThatUsesProvider = manager.GetInstance<ClassThatUsesProvider>(); @@ -90,7 +90,7 @@ [Test] public void CanBuildConcreteTypesThatAreNotPreviouslyRegisteredWithArgumentsProvided() { - IContainer manager = new InstanceManager(delegate(Registry registry) + IContainer manager = new StructureMap.... [truncated message content] |
From: <jer...@us...> - 2008-05-28 15:50:17
|
Revision: 109 http://structuremap.svn.sourceforge.net/structuremap/?rev=109&view=rev Author: jeremydmiller Date: 2008-05-28 08:50:14 -0700 (Wed, 28 May 2008) Log Message: ----------- Modified Paths: -------------- trunk/Source/StructureMap/Emitting/ClassBuilder.cs trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs trunk/Source/StructureMap/InstanceBuilder.cs trunk/Source/StructureMap/InstanceBuilderList.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs trunk/Source/StructureMap.AutoMocking/StructureMap.AutoMocking.csproj trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs trunk/Source/StructureMap.Testing/Container/EmittingTester.cs trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs trunk/Source/StructureMap.Testing.Widget/Decision.cs trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs Added Paths: ----------- trunk/Source/StructureMap.AutoMocking/AutoMockedContainer.cs trunk/Source/StructureMap.Testing/InstanceBuilderListTester.cs trunk/Source/StructureMap.Testing/MergingTester.cs Removed Paths: ------------- trunk/Source/StructureMap/InstanceManager.cs trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs Modified: trunk/Source/StructureMap/Emitting/ClassBuilder.cs =================================================================== --- trunk/Source/StructureMap/Emitting/ClassBuilder.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap/Emitting/ClassBuilder.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -83,31 +83,6 @@ ilgen.Emit(OpCodes.Ret); } - - public void AddReadonlyStringProperty(string propertyName, string propertyValue, bool @override) - { - PropertyBuilder prop = - _newTypeBuilder.DefineProperty(propertyName, PropertyAttributes.HasDefault, typeof (string), null); - - MethodAttributes atts = MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig | - MethodAttributes.Final | MethodAttributes.SpecialName; - - string getterMethodName = "get_" + propertyName; - - MethodBuilder methodGet = - _newTypeBuilder.DefineMethod(getterMethodName, atts, CallingConventions.Standard, typeof (string), null); - ILGenerator gen = methodGet.GetILGenerator(); - - LocalBuilder ilReturn = gen.DeclareLocal(typeof (string)); - - gen.Emit(OpCodes.Ldstr, propertyValue); - gen.Emit(OpCodes.Stloc_0); - gen.Emit(OpCodes.Ldloc_0); - gen.Emit(OpCodes.Ret); - - prop.SetGetMethod(methodGet); - } - public void AddPluggedTypeGetter(Type pluggedType) { PropertyBuilder prop = Modified: trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs =================================================================== --- trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -94,7 +94,6 @@ private void configureClassBuilder(ClassBuilder builderClass, Plugin plugin) { - builderClass.AddReadonlyStringProperty("ConcreteTypeKey", plugin.ConcreteKey, true); builderClass.AddPluggedTypeGetter(plugin.PluggedType); BuildInstanceMethod method = new BuildInstanceMethod(plugin); Modified: trunk/Source/StructureMap/InstanceBuilder.cs =================================================================== --- trunk/Source/StructureMap/InstanceBuilder.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap/InstanceBuilder.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -15,8 +15,6 @@ { } - public abstract string ConcreteTypeKey { get; } - public abstract Type PluggedType { get; } public abstract object BuildInstance(IConfiguredInstance instance, IBuildSession session); Modified: trunk/Source/StructureMap/InstanceBuilderList.cs =================================================================== --- trunk/Source/StructureMap/InstanceBuilderList.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap/InstanceBuilderList.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -9,6 +9,7 @@ { private readonly Dictionary<Type, InstanceBuilder> _builders = new Dictionary<Type, InstanceBuilder>(); private readonly Type _pluginType; + private readonly Dictionary<string, Type> _aliases = new Dictionary<string, Type>(); public InstanceBuilderList(Type pluginType, IEnumerable<Plugin> plugins) @@ -17,7 +18,17 @@ processPlugins(plugins); } + public InstanceBuilderList(Type pluginType) + { + _pluginType = pluginType; + } + public int BuilderCount + { + get { return _builders.Count; } + } + + public InstanceBuilder FindByType(Type pluggedType) { if (pluggedType == null) @@ -34,7 +45,7 @@ if (TypeRules.CanBeCast(_pluginType, pluggedType)) { Plugin plugin = new Plugin(pluggedType); - processPlugins(new Plugin[] {plugin}); + processPlugin(plugin); return _builders[pluggedType]; } @@ -44,24 +55,32 @@ public InstanceBuilder FindByConcreteKey(string concreteKey) { - foreach (KeyValuePair<Type, InstanceBuilder> pair in _builders) + if (_aliases.ContainsKey(concreteKey)) { - if (pair.Value.ConcreteTypeKey == concreteKey) - { - return pair.Value; - } + Type pluggedType = _aliases[concreteKey]; + return FindByType(pluggedType); } return null; } - public void Add(Type pluggedType, InstanceBuilder builder) + private void processPlugin(Plugin plugin) { - _builders.Add(pluggedType, builder); + processPlugins(new Plugin[] { plugin }); } private void processPlugins(IEnumerable<Plugin> plugins) { + foreach (Plugin plugin in plugins) + { + if (_aliases.ContainsKey(plugin.ConcreteKey)) + { + continue; + } + + _aliases.Add(plugin.ConcreteKey, plugin.PluggedType); + } + List<InstanceBuilder> list = createInstanceBuilders(plugins); foreach (InstanceBuilder builder in list) { @@ -71,8 +90,27 @@ private List<InstanceBuilder> createInstanceBuilders(IEnumerable<Plugin> plugins) { - InstanceBuilderAssembly builderAssembly = new InstanceBuilderAssembly(_pluginType, plugins); + List<Plugin> list = new List<Plugin>(); + foreach (Plugin plugin in plugins) + { + if (!_builders.ContainsKey(plugin.PluggedType)) + { + list.Add(plugin); + } + } + + InstanceBuilderAssembly builderAssembly = new InstanceBuilderAssembly(_pluginType, list); return builderAssembly.Compile(); } + + public void Add(Plugin plugin) + { + Add(new Plugin[] {plugin}); + } + + public void Add(IEnumerable<Plugin> plugins) + { + processPlugins(plugins); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -18,6 +18,11 @@ #region constructor functions + public InstanceFactory(Type pluginType) : this(new PluginFamily(pluginType)) + { + + } + /// <summary> /// Constructor to use when troubleshooting possible configuration issues. /// </summary> @@ -107,11 +112,10 @@ } - public Instance AddType<T>() + [Obsolete] public Instance AddType<T>() { InstanceBuilder builder = _instanceBuilders.FindByType(typeof (T)); - ConfiguredInstance instance = new ConfiguredInstance(); - instance.WithConcreteKey(builder.ConcreteTypeKey).WithName(builder.ConcreteTypeKey); + ConfiguredInstance instance = new ConfiguredInstance(typeof(T)).WithName(TypePath.GetAssemblyQualifiedName(typeof(T))); AddInstance(instance); @@ -147,5 +151,14 @@ } #endregion + + public void Merge(PluginFamily family) + { + _instanceBuilders.Add(family.Plugins); + foreach (Instance instance in family.GetAllInstances()) + { + AddInstance(instance); + } + } } } \ No newline at end of file Deleted: trunk/Source/StructureMap/InstanceManager.cs =================================================================== --- trunk/Source/StructureMap/InstanceManager.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap/InstanceManager.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -1,291 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics; -using System.Text; -using StructureMap.Configuration.DSL; -using StructureMap.Diagnostics; -using StructureMap.Graph; -using StructureMap.Interceptors; -using StructureMap.Pipeline; - -namespace StructureMap -{ - /// <summary> - /// A collection of IInstanceFactory's. - /// </summary> - public class InstanceManager : TypeRules, IContainer - { - private InterceptorLibrary _interceptorLibrary; - private PipelineGraph _pipelineGraph; - - public InstanceManager(Action<Registry> action) - { - Registry registry = new Registry(); - action(registry); - - construct(registry.Build()); - } - - public InstanceManager(Registry registry) : this(registry.Build()) - { - } - - public InstanceManager() : this(new PluginGraph()) - { - } - - /// <summary> - /// Constructor to create an InstanceManager - /// </summary> - /// <param name="pluginGraph">PluginGraph containing the instance and type definitions - /// for the InstanceManager</param> - /// <param name="failOnException">Flags the InstanceManager to fail or trap exceptions</param> - public InstanceManager(PluginGraph pluginGraph) - { - construct(pluginGraph); - } - - private void construct(PluginGraph pluginGraph) - { - _interceptorLibrary = pluginGraph.InterceptorLibrary; - - if (!pluginGraph.IsSealed) - { - pluginGraph.Seal(); - } - - pluginGraph.Log.AssertFailures(); - - _pipelineGraph = new PipelineGraph(pluginGraph); - } - - protected MissingFactoryFunction onMissingFactory - { - set { _pipelineGraph.OnMissingFactory = value; } - } - - #region IContainer Members - - public T GetInstance<T>(string instanceKey) - { - return (T) GetInstance(typeof (T), instanceKey); - } - - public T GetInstance<T>(Instance instance) - { - return (T) GetInstance(typeof (T), instance); - } - - public PLUGINTYPE GetInstance<PLUGINTYPE>(ExplicitArguments args) - { - Instance defaultInstance = _pipelineGraph.GetDefault(typeof (PLUGINTYPE)); - - ExplicitInstance<PLUGINTYPE> instance = new ExplicitInstance<PLUGINTYPE>(args, defaultInstance); - return GetInstance<PLUGINTYPE>(instance); - } - - public void Inject<PLUGINTYPE>(PLUGINTYPE instance) - { - _pipelineGraph.Inject(instance); - } - - public void InjectByName<PLUGINTYPE>(PLUGINTYPE instance, string instanceKey) - { - LiteralInstance literalInstance = new LiteralInstance(instance); - literalInstance.Name = instanceKey; - - AddInstance<PLUGINTYPE>(literalInstance); - } - - public void InjectByName<PLUGINTYPE, CONCRETETYPE>(string instanceKey) - { - ConfiguredInstance instance = new ConfiguredInstance(typeof(CONCRETETYPE)); - instance.Name = instanceKey; - - AddInstance<PLUGINTYPE>(instance); - } - - public T GetInstance<T>() - { - return (T) GetInstance(typeof (T)); - } - - public T FillDependencies<T>() - { - return (T) FillDependencies(typeof (T)); - } - - public void InjectStub<T>(T instance) - { - InjectStub(typeof (T), instance); - } - - public IList<T> GetAllInstances<T>() - { - List<T> list = new List<T>(); - - IBuildSession session = withNewSession(); - - foreach (T instance in forType(typeof (T)).GetAllInstances(session)) - { - list.Add(instance); - } - - return list; - } - - public void SetDefaultsToProfile(string profile) - { - _pipelineGraph.CurrentProfile = profile; - } - - /// <summary> - /// Creates the named instance of the PluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instanceKey"></param> - /// <returns></returns> - public object GetInstance(Type pluginType, string instanceKey) - { - return withNewSession().CreateInstance(pluginType, instanceKey); - } - - - /// <summary> - /// Creates a new object instance of the requested type - /// </summary> - /// <param name="pluginType"></param> - /// <returns></returns> - public object GetInstance(Type pluginType) - { - return withNewSession().CreateInstance(pluginType); - } - - - /// <summary> - /// Creates a new instance of the requested type using the InstanceMemento. Mostly used from other - /// classes to link children members - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instance"></param> - /// <returns></returns> - public object GetInstance(Type pluginType, Instance instance) - { - return withNewSession().CreateInstance(pluginType, instance); - } - - /// <summary> - /// Sets the default instance for the PluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instance"></param> - public void SetDefault(Type pluginType, Instance instance) - { - _pipelineGraph.SetDefault(pluginType, instance); - } - - /// <summary> - /// Sets the default instance for the PluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instanceKey"></param> - public void SetDefault(Type pluginType, string instanceKey) - { - ReferencedInstance reference = new ReferencedInstance(instanceKey); - _pipelineGraph.SetDefault(pluginType, reference); - } - - - /// <summary> - /// Attempts to create a new instance of the requested type. Automatically inserts the default - /// configured instance for each dependency in the StructureMap constructor function. - /// </summary> - /// <param name="type"></param> - /// <returns></returns> - public object FillDependencies(Type type) - { - if (!IsConcrete(type)) - { - throw new StructureMapException(230, type.FullName); - } - - Plugin plugin = new Plugin(type); - if (!plugin.CanBeAutoFilled) - { - throw new StructureMapException(230, type.FullName); - } - - return GetInstance(type); - } - - /// <summary> - /// Sets up the InstanceManager to return the object in the "stub" argument anytime - /// any instance of the PluginType is requested - /// </summary> - /// <param name="pluginType"></param> - /// <param name="stub"></param> - public void InjectStub(Type pluginType, object stub) - { - if (!CanBeCast(pluginType, stub.GetType())) - { - throw new StructureMapException(220, pluginType.FullName, - stub.GetType().FullName); - } - - - LiteralInstance instance = new LiteralInstance(stub); - _pipelineGraph.SetDefault(pluginType, instance); - } - - public IList GetAllInstances(Type type) - { - return forType(type).GetAllInstances(withNewSession()); - } - - public void AddInstance<T>(Instance instance) - { - _pipelineGraph.AddInstance<T>(instance); - } - - public void AddInstance<PLUGINTYPE, CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE - { - _pipelineGraph.AddInstance<PLUGINTYPE, CONCRETETYPE>(); - } - - public void AddDefaultInstance<PLUGINTYPE, CONCRETETYPE>() - { - _pipelineGraph.AddDefaultInstance<PLUGINTYPE, CONCRETETYPE>(); - } - - public string WhatDoIHave() - { - WhatDoIHaveWriter writer = new WhatDoIHaveWriter(_pipelineGraph); - return writer.GetText(); - } - - public ExplicitArgsExpression With<T>(T arg) - { - return new ExplicitArgsExpression(this).With<T>(arg); - } - - public IExplicitProperty With(string argName) - { - return new ExplicitArgsExpression(this).With(argName); - } - - #endregion - - private IBuildSession withNewSession() - { - return new BuildSession(_pipelineGraph, _interceptorLibrary); - } - - - protected IInstanceFactory forType(Type type) - { - return _pipelineGraph.ForType(type); - } - - } -} \ No newline at end of file Added: trunk/Source/StructureMap.AutoMocking/AutoMockedContainer.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/AutoMockedContainer.cs (rev 0) +++ trunk/Source/StructureMap.AutoMocking/AutoMockedContainer.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -0,0 +1,33 @@ +using System; +using StructureMap.Graph; +using StructureMap.Pipeline; + +namespace StructureMap.AutoMocking +{ + public class AutoMockedContainer : Container + { + private readonly ServiceLocator _locator; + + public AutoMockedContainer(ServiceLocator locator) + { + _locator = locator; + + onMissingFactory = delegate(Type pluginType, ProfileManager profileManager) + { + if (!pluginType.IsAbstract && pluginType.IsClass) + { + return null; + } + + object service = _locator.Service(pluginType); + InstanceFactory factory = new InstanceFactory(new PluginFamily(pluginType)); + + LiteralInstance instance = new LiteralInstance(service); + + profileManager.SetDefault(pluginType, instance); + + return factory; + }; + } + } +} \ No newline at end of file Deleted: trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -1,34 +0,0 @@ -using System; -using StructureMap.Graph; -using StructureMap.Pipeline; - -namespace StructureMap.AutoMocking -{ - public class AutoMockedInstanceManager : Container - { - private readonly ServiceLocator _locator; - - public AutoMockedInstanceManager(ServiceLocator locator) - { - _locator = locator; - - onMissingFactory = delegate(Type pluginType, ProfileManager profileManager) - { - if (!pluginType.IsAbstract && pluginType.IsClass) - { - return null; - } - - object service = _locator.Service(pluginType); - InstanceFactory factory = new InstanceFactory(new PluginFamily(pluginType)); - - LiteralInstance instance = new LiteralInstance(service); - - profileManager.SetDefault(pluginType, instance); - - return factory; - }; - } - - } -} \ No newline at end of file Modified: trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -13,13 +13,13 @@ // Note that it subclasses the RhinoMocks.MockRepository class public class RhinoAutoMocker<TARGETCLASS> : MockRepository where TARGETCLASS : class { - private readonly AutoMockedInstanceManager _manager; + private readonly AutoMockedContainer _manager; private TARGETCLASS _classUnderTest; public RhinoAutoMocker() { RhinoMocksServiceLocator locator = new RhinoMocksServiceLocator(this); - _manager = new AutoMockedInstanceManager(locator); + _manager = new AutoMockedContainer(locator); } // Replaces the inner Container in ObjectFactory with the mocked Modified: trunk/Source/StructureMap.AutoMocking/StructureMap.AutoMocking.csproj =================================================================== --- trunk/Source/StructureMap.AutoMocking/StructureMap.AutoMocking.csproj 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.AutoMocking/StructureMap.AutoMocking.csproj 2008-05-28 15:50:14 UTC (rev 109) @@ -42,7 +42,7 @@ <Compile Include="..\CommonAssemblyInfo.cs"> <Link>CommonAssemblyInfo.cs</Link> </Compile> - <Compile Include="AutoMockedInstanceManager.cs" /> + <Compile Include="AutoMockedContainer.cs" /> <Compile Include="IntegrationSpecification.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="RhinoAutoMocker.cs" /> Modified: trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -16,14 +16,14 @@ { _mocks = new MockRepository(); _locator = new RhinoMocksServiceLocator(_mocks); - _instanceManager = new AutoMockedInstanceManager(_locator); + _container = new AutoMockedContainer(_locator); } #endregion private MockRepository _mocks; private RhinoMocksServiceLocator _locator; - private AutoMockedInstanceManager _instanceManager; + private AutoMockedContainer _container; public class ConcreteThing @@ -132,11 +132,11 @@ [Test] public void AutoFillAConcreteClassWithMocks() { - IMockedService service = _instanceManager.GetInstance<IMockedService>(); - IMockedService2 service2 = _instanceManager.GetInstance<IMockedService2>(); - IMockedService3 service3 = _instanceManager.GetInstance<IMockedService3>(); + IMockedService service = _container.GetInstance<IMockedService>(); + IMockedService2 service2 = _container.GetInstance<IMockedService2>(); + IMockedService3 service3 = _container.GetInstance<IMockedService3>(); - ConcreteClass concreteClass = _instanceManager.FillDependencies<ConcreteClass>(); + ConcreteClass concreteClass = _container.FillDependencies<ConcreteClass>(); Assert.AreSame(service, concreteClass.Service); Assert.AreSame(service2, concreteClass.Service2); @@ -146,7 +146,7 @@ [Test] public void GetAFullMockForAServiceThatHasNotPreviouslyBeenRequested() { - IMockedService service = _instanceManager.GetInstance<IMockedService>(); + IMockedService service = _container.GetInstance<IMockedService>(); Assert.IsNotNull(service); @@ -169,21 +169,21 @@ public void InjectAStubAndGetTheStubBack() { StubService stub = new StubService(); - _instanceManager.InjectStub<IMockedService>(stub); + _container.InjectStub<IMockedService>(stub); - Assert.AreSame(stub, _instanceManager.GetInstance<IMockedService>()); - Assert.AreSame(stub, _instanceManager.GetInstance<IMockedService>()); - Assert.AreSame(stub, _instanceManager.GetInstance<IMockedService>()); + Assert.AreSame(stub, _container.GetInstance<IMockedService>()); + Assert.AreSame(stub, _container.GetInstance<IMockedService>()); + Assert.AreSame(stub, _container.GetInstance<IMockedService>()); } [Test] public void RequestTheServiceTwiceAndGetTheExactSameMockObject() { - IMockedService service = _instanceManager.GetInstance<IMockedService>(); - Assert.AreSame(service, _instanceManager.GetInstance<IMockedService>()); - Assert.AreSame(service, _instanceManager.GetInstance<IMockedService>()); - Assert.AreSame(service, _instanceManager.GetInstance<IMockedService>()); - Assert.AreSame(service, _instanceManager.GetInstance<IMockedService>()); + IMockedService service = _container.GetInstance<IMockedService>(); + Assert.AreSame(service, _container.GetInstance<IMockedService>()); + Assert.AreSame(service, _container.GetInstance<IMockedService>()); + Assert.AreSame(service, _container.GetInstance<IMockedService>()); + Assert.AreSame(service, _container.GetInstance<IMockedService>()); } [Test] Modified: trunk/Source/StructureMap.Testing/Container/EmittingTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/EmittingTester.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.Testing/Container/EmittingTester.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -73,12 +73,6 @@ } [Test] - public void ConcreteTypeKey() - { - Assert.AreEqual("Complex", builder.ConcreteTypeKey); - } - - [Test] public void DoubleProperty() { Assert.AreEqual(4, rule.Double); Modified: trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -61,9 +61,38 @@ Assert.IsNotNull(gateway); } + [Test] + public void Import_from_family_picks_up_new_InstanceBuilders() + { + InstanceFactory factory = new InstanceFactory(typeof(IWidget)); + + PluginFamily family = new PluginFamily(typeof(IWidget)); + family.AddPlugin(typeof (AWidget)); + family.AddPlugin(typeof (ColorWidget)); + factory.Merge(family); + InstanceBuilder builder = factory.FindBuilderByType(typeof (AWidget)); + Assert.IsNotNull(builder); + builder = factory.FindBuilderByType(typeof(ColorWidget)); + Assert.IsNotNull(builder); + } + [Test] + public void Import_from_family_picks_up_new_instances() + { + InstanceFactory factory = new InstanceFactory(typeof(IWidget)); + PluginFamily family = new PluginFamily(typeof(IWidget)); + family.AddInstance(new LiteralInstance(new AWidget()).WithName("New")); + family.AddInstance(new LiteralInstance(new AWidget()).WithName("New2")); + family.AddInstance(new LiteralInstance(new AWidget()).WithName("New3")); + + factory.Merge(family); + + Assert.IsNotNull(factory.FindInstance("New")); + Assert.IsNotNull(factory.FindInstance("New2")); + Assert.IsNotNull(factory.FindInstance("New3")); + } } } \ No newline at end of file Added: trunk/Source/StructureMap.Testing/InstanceBuilderListTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/InstanceBuilderListTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/InstanceBuilderListTester.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Text; +using NUnit.Framework; +using StructureMap.Graph; +using StructureMap.Testing.Widget; + +namespace StructureMap.Testing +{ + [TestFixture] + public class InstanceBuilderListTester + { + [Test] + public void InstanceBuilderList_add_a_new_InstanceBuilder_if_the_new_Plugin_is_not_recognized() + { + InstanceBuilderList list = new InstanceBuilderList(typeof(IWidget)); + Assert.AreEqual(0, list.BuilderCount); + + Plugin plugin = new Plugin(typeof(AWidget)); + list.Add(plugin); + + Assert.AreEqual(1, list.BuilderCount); + InstanceBuilder builder = list.FindByType(typeof(AWidget)); + + Assert.IsNotNull(builder); + } + + [Test] + public void InstanceBuilderList_should_not_add_a_new_InstanceBuilder_if_the_same_one_exists() + { + InstanceBuilderList list = new InstanceBuilderList(typeof(IWidget)); + Plugin plugin = new Plugin(typeof(AWidget)); + list.Add(plugin); + list.Add(plugin); + + Assert.AreEqual(1, list.BuilderCount); + } + + [Test] + public void Do_not_add_a_new_InstanceBuilder_for_the_same_plugged_type_but_different_concrete_key() + { + InstanceBuilderList list = new InstanceBuilderList(typeof(IWidget)); + Plugin plugin = new Plugin(typeof(AWidget)); + list.Add(plugin); + + Plugin plugin2 = new Plugin(typeof(AWidget), "DifferentKey"); + list.Add(plugin2); + + Assert.AreEqual(1, list.BuilderCount); + } + + [Test] + public void Find_the_InstanceBuilder_by_concrete_key_with_different_aliased_concrete_keys() + { + InstanceBuilderList list = new InstanceBuilderList(typeof(IWidget)); + Plugin plugin = new Plugin(typeof(AWidget)); + list.Add(plugin); + + Plugin plugin2 = new Plugin(typeof(AWidget), "DifferentKey"); + list.Add(plugin2); + + InstanceBuilder builder1 = list.FindByConcreteKey(plugin.ConcreteKey); + InstanceBuilder builder2 = list.FindByConcreteKey(plugin2.ConcreteKey); + + Assert.AreSame(builder1, builder2); + } + } +} Added: trunk/Source/StructureMap.Testing/MergingTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/MergingTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/MergingTester.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; +using NUnit.Framework; +using StructureMap.Graph; +using StructureMap.Testing.Widget; + +namespace StructureMap.Testing +{ + [TestFixture] + public class MergingTester + { + + + + } +} Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-28 15:50:14 UTC (rev 109) @@ -315,8 +315,10 @@ </Compile> <Compile Include="Graph\TypePathTester.cs" /> <Compile Include="ImplicitPluginFromPluggedTypeAttributeTester.cs" /> + <Compile Include="InstanceBuilderListTester.cs" /> <Compile Include="InstanceMementoInstanceCreationTester.cs" /> <Compile Include="MementoTester.cs" /> + <Compile Include="MergingTester.cs" /> <Compile Include="ObjectFactoryTester.cs"> <SubType>Code</SubType> </Compile> Modified: trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -51,14 +51,6 @@ public class StringListBuilder : InstanceBuilder { - - public override string ConcreteTypeKey - { - get { return null; } - } - - - public override object BuildInstance(IConfiguredInstance instance, StructureMap.Pipeline.IBuildSession session) { return null; Modified: trunk/Source/StructureMap.Testing.Widget/Decision.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/Decision.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.Testing.Widget/Decision.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -16,11 +16,6 @@ public class DecisionBuilder : InstanceBuilder { - public override string ConcreteTypeKey - { - get { return null; } - } - public override object BuildInstance(IConfiguredInstance instance, StructureMap.Pipeline.IBuildSession session) { return new Decision( Modified: trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -92,11 +92,6 @@ public class ChildLoaderTemplate : InstanceBuilder { - public override string ConcreteTypeKey - { - get { return null; } - } - public override Type PluggedType { get { throw new NotImplementedException(); } Modified: trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -28,11 +28,6 @@ public class CowBuilder : InstanceBuilder { - public override string ConcreteTypeKey - { - get { return "Default"; } - } - public Type ThePluginType { get Modified: trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs 2008-05-28 04:02:54 UTC (rev 108) +++ trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs 2008-05-28 15:50:14 UTC (rev 109) @@ -13,12 +13,6 @@ { } - - public override string ConcreteTypeKey - { - get { throw new NotImplementedException(); } - } - public override Type PluggedType { get { throw new NotImplementedException(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-05-29 03:12:01
|
Revision: 110 http://structuremap.svn.sourceforge.net/structuremap/?rev=110&view=rev Author: jeremydmiller Date: 2008-05-28 20:11:55 -0700 (Wed, 28 May 2008) Log Message: ----------- Starting the InstanceFactory.Merge functionality Modified Paths: -------------- trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap.Testing/Container/ContainerTester.cs Removed Paths: ------------- trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-05-28 15:50:14 UTC (rev 109) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-05-29 03:11:55 UTC (rev 110) @@ -157,6 +157,11 @@ _instanceBuilders.Add(family.Plugins); foreach (Instance instance in family.GetAllInstances()) { + if (_instances.ContainsKey(instance.Name)) + { + continue; + } + AddInstance(instance); } } Added: trunk/Source/StructureMap.Testing/Container/ContainerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/ContainerTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Container/ContainerTester.cs 2008-05-29 03:11:55 UTC (rev 110) @@ -0,0 +1,233 @@ +using System; +using NUnit.Framework; +using StructureMap.Configuration.DSL; +using StructureMap.Exceptions; +using StructureMap.Graph; +using StructureMap.Interceptors; +using StructureMap.Pipeline; +using StructureMap.Source; +using StructureMap.Testing.GenericWidgets; +using StructureMap.Testing.Widget; +using StructureMap.Testing.Widget3; + +namespace StructureMap.Testing.Container +{ + [TestFixture] + public class ContainerTester : Registry + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + _manager = new StructureMap.Container(delegate(Registry registry) + { + registry.ScanAssemblies().IncludeAssembly("StructureMap.Testing.Widget"); + registry.BuildInstancesOf<Rule>(); + registry.BuildInstancesOf<IWidget>(); + registry.BuildInstancesOf<WidgetMaker>(); + }); + } + + #endregion + + private IContainer _manager; + + private void addColorMemento(string Color) + { + ConfiguredInstance instance = new ConfiguredInstance(Color).WithConcreteKey("Color").SetProperty("Color", Color); + + _manager.AddInstance<Rule>(instance); + _manager.AddInstance<IWidget>(instance); + _manager.AddInstance<WidgetMaker>(instance); + } + + public interface IProvider + { + } + + public class Provider : IProvider + { + } + + public class ClassThatUsesProvider + { + private readonly IProvider _provider; + + public ClassThatUsesProvider(IProvider provider) + { + _provider = provider; + } + + + public IProvider Provider + { + get { return _provider; } + } + } + + public class DifferentProvider : IProvider + { + } + + [Test] + public void CanBuildConcreteTypesThatAreNotPreviouslyRegistered() + { + IContainer manager = new StructureMap.Container(delegate(Registry registry) + { + // Create a new Container that has a default instance configured for only the + // IProvider interface. Container is the real "container" behind ObjectFactory + registry.ForRequestedType<IProvider>().TheDefaultIsConcreteType<Provider>(); + }); + + // Now, have that same Container create a ClassThatUsesProvider. StructureMap will + // see that ClassThatUsesProvider is concrete, determine its constructor args, and build one + // for you with the default IProvider. No other configuration necessary. + ClassThatUsesProvider classThatUsesProvider = manager.GetInstance<ClassThatUsesProvider>(); + Assert.IsInstanceOfType(typeof (Provider), classThatUsesProvider.Provider); + } + + [Test] + public void CanBuildConcreteTypesThatAreNotPreviouslyRegisteredWithArgumentsProvided() + { + IContainer manager = new StructureMap.Container(delegate(Registry registry) + { + registry.ForRequestedType<IProvider>().TheDefaultIsConcreteType<Provider>(); + }); + + DifferentProvider differentProvider = new DifferentProvider(); + ExplicitArguments args = new ExplicitArguments(); + args.Set<IProvider>(differentProvider); + + ClassThatUsesProvider classThatUsesProvider = manager.GetInstance<ClassThatUsesProvider>(args); + Assert.AreSame(differentProvider, classThatUsesProvider.Provider); + } + + + + + [Test] + public void FindAPluginFamilyForAGenericTypeFromPluginTypeName() + { + Type serviceType = typeof (IService<string>); + PluginGraph pluginGraph = PluginGraph.BuildGraphFromAssembly(serviceType.Assembly); + PipelineGraph pipelineGraph = new PipelineGraph(pluginGraph); + + Type stringService = typeof (IService<string>); + + IInstanceFactory factory = pipelineGraph.ForType(stringService); + Assert.AreEqual(stringService, factory.PluginType); + } + + [Test] + public void GetDefaultInstance() + { + addColorMemento("Red"); + addColorMemento("Orange"); + addColorMemento("Blue"); + + _manager.SetDefault(typeof (Rule), "Blue"); + ColorRule rule = _manager.GetInstance(typeof (Rule)) as ColorRule; + + Assert.IsNotNull(rule); + Assert.AreEqual("Blue", rule.Color); + } + + [Test] + public void GetInstanceOf3Types() + { + addColorMemento("Red"); + addColorMemento("Orange"); + addColorMemento("Blue"); + + ColorRule rule = _manager.GetInstance(typeof (Rule), "Blue") as ColorRule; + Assert.IsNotNull(rule); + Assert.AreEqual("Blue", rule.Color); + + ColorWidget widget = _manager.GetInstance(typeof (IWidget), "Red") as ColorWidget; + Assert.IsNotNull(widget); + Assert.AreEqual("Red", widget.Color); + + ColorWidgetMaker maker = _manager.GetInstance(typeof (WidgetMaker), "Orange") as ColorWidgetMaker; + Assert.IsNotNull(maker); + Assert.AreEqual("Orange", maker.Color); + } + + [Test, ExpectedException(typeof (StructureMapException))] + public void GetMissingType() + { + object o = _manager.GetInstance(typeof (string)); + } + + + private void assertColorIs(IContainer manager, string color) + { + ColorService rule = (ColorService) manager.GetInstance<IService>(); + Assert.AreEqual(color, rule.Color); + } + + [Test] + public void SetDefaultInstanceByString() + { + IContainer manager = new StructureMap.Container(delegate(Registry registry) + { + registry.ForRequestedType<IService>() + .AddInstance(Instance<ColorService>().WithName("Red").WithProperty("color").EqualTo("Red")) + .AddInstance(Instance<ColorService>().WithName("Blue").WithProperty("color").EqualTo("Blue")) + .AddInstance(Instance<ColorService>().WithName("Green").WithProperty("color").EqualTo("Green")); + }); + + manager.SetDefault(typeof(IService), "Red"); + assertColorIs(manager, "Red"); + + manager.SetDefault(typeof(IService), "Green"); + assertColorIs(manager, "Green"); + + manager.SetDefault(typeof(IService), "Blue"); + assertColorIs(manager, "Blue"); + } + + [Test] + public void Can_set_profile_name_and_reset_defaults() + { + IContainer manager = new StructureMap.Container(delegate(Registry registry) + { + registry.ForRequestedType<IService>() + .TheDefaultIs(Instance<ColorService>().WithName("Orange").WithProperty("color").EqualTo("Orange")) + .AddInstance(Instance<ColorService>().WithName("Red").WithProperty("color").EqualTo("Red")) + .AddInstance(Instance<ColorService>().WithName("Blue").WithProperty("color").EqualTo("Blue")) + .AddInstance(Instance<ColorService>().WithName("Green").WithProperty("color").EqualTo("Green")); + + registry.CreateProfile("Red").For<IService>().UseNamedInstance("Red"); + registry.CreateProfile("Blue").For<IService>().UseNamedInstance("Blue"); + }); + + assertColorIs(manager, "Orange"); + + manager.SetDefaultsToProfile("Red"); + assertColorIs(manager, "Red"); + + manager.SetDefaultsToProfile("Blue"); + assertColorIs(manager, "Blue"); + + manager.SetDefaultsToProfile(string.Empty); + assertColorIs(manager, "Orange"); + } + + [Test, ExpectedException(typeof(StructureMapException))] + public void TryToGetDefaultInstanceWithNoInstance() + { + StructureMap.Container manager = new StructureMap.Container(new PluginGraph()); + manager.GetInstance<IService>(); + } + + [Test, ExpectedException(typeof(StructureMapConfigurationException))] + public void CTOR_throws_StructureMapConfigurationException_if_there_is_an_error() + { + PluginGraph graph = new PluginGraph(); + graph.Log.RegisterError(400, new ApplicationException("Bad!")); + + new StructureMap.Container(graph); + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs 2008-05-28 15:50:14 UTC (rev 109) +++ trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs 2008-05-29 03:11:55 UTC (rev 110) @@ -94,5 +94,21 @@ Assert.IsNotNull(factory.FindInstance("New2")); Assert.IsNotNull(factory.FindInstance("New3")); } + + [Test] + public void Merge_from_PluginFamily_will_not_replace_an_existing_instance() + { + InstanceFactory factory = new InstanceFactory(typeof(IWidget)); + LiteralInstance instance1 = new LiteralInstance(new AWidget()).WithName("New"); + factory.AddInstance(instance1); + + PluginFamily family = new PluginFamily(typeof(IWidget)); + family.AddInstance(new LiteralInstance(new AWidget()).WithName("New")); + + factory.Merge(family); + + Assert.AreSame(instance1, factory.FindInstance("New")); + + } } } \ No newline at end of file Deleted: trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs 2008-05-28 15:50:14 UTC (rev 109) +++ trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs 2008-05-29 03:11:55 UTC (rev 110) @@ -1,233 +0,0 @@ -using System; -using NUnit.Framework; -using StructureMap.Configuration.DSL; -using StructureMap.Exceptions; -using StructureMap.Graph; -using StructureMap.Interceptors; -using StructureMap.Pipeline; -using StructureMap.Source; -using StructureMap.Testing.GenericWidgets; -using StructureMap.Testing.Widget; -using StructureMap.Testing.Widget3; - -namespace StructureMap.Testing.Container -{ - [TestFixture] - public class InstanceManagerTester : Registry - { - #region Setup/Teardown - - [SetUp] - public void SetUp() - { - _manager = new StructureMap.Container(delegate(Registry registry) - { - registry.ScanAssemblies().IncludeAssembly("StructureMap.Testing.Widget"); - registry.BuildInstancesOf<Rule>(); - registry.BuildInstancesOf<IWidget>(); - registry.BuildInstancesOf<WidgetMaker>(); - }); - } - - #endregion - - private IContainer _manager; - - private void addColorMemento(string Color) - { - ConfiguredInstance instance = new ConfiguredInstance(Color).WithConcreteKey("Color").SetProperty("Color", Color); - - _manager.AddInstance<Rule>(instance); - _manager.AddInstance<IWidget>(instance); - _manager.AddInstance<WidgetMaker>(instance); - } - - public interface IProvider - { - } - - public class Provider : IProvider - { - } - - public class ClassThatUsesProvider - { - private readonly IProvider _provider; - - public ClassThatUsesProvider(IProvider provider) - { - _provider = provider; - } - - - public IProvider Provider - { - get { return _provider; } - } - } - - public class DifferentProvider : IProvider - { - } - - [Test] - public void CanBuildConcreteTypesThatAreNotPreviouslyRegistered() - { - IContainer manager = new StructureMap.Container(delegate(Registry registry) - { - // Create a new Container that has a default instance configured for only the - // IProvider interface. Container is the real "container" behind ObjectFactory - registry.ForRequestedType<IProvider>().TheDefaultIsConcreteType<Provider>(); - }); - - // Now, have that same Container create a ClassThatUsesProvider. StructureMap will - // see that ClassThatUsesProvider is concrete, determine its constructor args, and build one - // for you with the default IProvider. No other configuration necessary. - ClassThatUsesProvider classThatUsesProvider = manager.GetInstance<ClassThatUsesProvider>(); - Assert.IsInstanceOfType(typeof (Provider), classThatUsesProvider.Provider); - } - - [Test] - public void CanBuildConcreteTypesThatAreNotPreviouslyRegisteredWithArgumentsProvided() - { - IContainer manager = new StructureMap.Container(delegate(Registry registry) - { - registry.ForRequestedType<IProvider>().TheDefaultIsConcreteType<Provider>(); - }); - - DifferentProvider differentProvider = new DifferentProvider(); - ExplicitArguments args = new ExplicitArguments(); - args.Set<IProvider>(differentProvider); - - ClassThatUsesProvider classThatUsesProvider = manager.GetInstance<ClassThatUsesProvider>(args); - Assert.AreSame(differentProvider, classThatUsesProvider.Provider); - } - - - - - [Test] - public void FindAPluginFamilyForAGenericTypeFromPluginTypeName() - { - Type serviceType = typeof (IService<string>); - PluginGraph pluginGraph = PluginGraph.BuildGraphFromAssembly(serviceType.Assembly); - PipelineGraph pipelineGraph = new PipelineGraph(pluginGraph); - - Type stringService = typeof (IService<string>); - - IInstanceFactory factory = pipelineGraph.ForType(stringService); - Assert.AreEqual(stringService, factory.PluginType); - } - - [Test] - public void GetDefaultInstance() - { - addColorMemento("Red"); - addColorMemento("Orange"); - addColorMemento("Blue"); - - _manager.SetDefault(typeof (Rule), "Blue"); - ColorRule rule = _manager.GetInstance(typeof (Rule)) as ColorRule; - - Assert.IsNotNull(rule); - Assert.AreEqual("Blue", rule.Color); - } - - [Test] - public void GetInstanceOf3Types() - { - addColorMemento("Red"); - addColorMemento("Orange"); - addColorMemento("Blue"); - - ColorRule rule = _manager.GetInstance(typeof (Rule), "Blue") as ColorRule; - Assert.IsNotNull(rule); - Assert.AreEqual("Blue", rule.Color); - - ColorWidget widget = _manager.GetInstance(typeof (IWidget), "Red") as ColorWidget; - Assert.IsNotNull(widget); - Assert.AreEqual("Red", widget.Color); - - ColorWidgetMaker maker = _manager.GetInstance(typeof (WidgetMaker), "Orange") as ColorWidgetMaker; - Assert.IsNotNull(maker); - Assert.AreEqual("Orange", maker.Color); - } - - [Test, ExpectedException(typeof (StructureMapException))] - public void GetMissingType() - { - object o = _manager.GetInstance(typeof (string)); - } - - - private void assertColorIs(IContainer manager, string color) - { - ColorService rule = (ColorService) manager.GetInstance<IService>(); - Assert.AreEqual(color, rule.Color); - } - - [Test] - public void SetDefaultInstanceByString() - { - IContainer manager = new StructureMap.Container(delegate(Registry registry) - { - registry.ForRequestedType<IService>() - .AddInstance(Instance<ColorService>().WithName("Red").WithProperty("color").EqualTo("Red")) - .AddInstance(Instance<ColorService>().WithName("Blue").WithProperty("color").EqualTo("Blue")) - .AddInstance(Instance<ColorService>().WithName("Green").WithProperty("color").EqualTo("Green")); - }); - - manager.SetDefault(typeof(IService), "Red"); - assertColorIs(manager, "Red"); - - manager.SetDefault(typeof(IService), "Green"); - assertColorIs(manager, "Green"); - - manager.SetDefault(typeof(IService), "Blue"); - assertColorIs(manager, "Blue"); - } - - [Test] - public void Can_set_profile_name_and_reset_defaults() - { - IContainer manager = new StructureMap.Container(delegate(Registry registry) - { - registry.ForRequestedType<IService>() - .TheDefaultIs(Instance<ColorService>().WithName("Orange").WithProperty("color").EqualTo("Orange")) - .AddInstance(Instance<ColorService>().WithName("Red").WithProperty("color").EqualTo("Red")) - .AddInstance(Instance<ColorService>().WithName("Blue").WithProperty("color").EqualTo("Blue")) - .AddInstance(Instance<ColorService>().WithName("Green").WithProperty("color").EqualTo("Green")); - - registry.CreateProfile("Red").For<IService>().UseNamedInstance("Red"); - registry.CreateProfile("Blue").For<IService>().UseNamedInstance("Blue"); - }); - - assertColorIs(manager, "Orange"); - - manager.SetDefaultsToProfile("Red"); - assertColorIs(manager, "Red"); - - manager.SetDefaultsToProfile("Blue"); - assertColorIs(manager, "Blue"); - - manager.SetDefaultsToProfile(string.Empty); - assertColorIs(manager, "Orange"); - } - - [Test, ExpectedException(typeof(StructureMapException))] - public void TryToGetDefaultInstanceWithNoInstance() - { - StructureMap.Container manager = new StructureMap.Container(new PluginGraph()); - manager.GetInstance<IService>(); - } - - [Test, ExpectedException(typeof(StructureMapConfigurationException))] - public void CTOR_throws_StructureMapConfigurationException_if_there_is_an_error() - { - PluginGraph graph = new PluginGraph(); - graph.Log.RegisterError(400, new ApplicationException("Bad!")); - - new StructureMap.Container(graph); - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-28 15:50:14 UTC (rev 109) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-29 03:11:55 UTC (rev 110) @@ -214,7 +214,7 @@ <Compile Include="Container\InstanceFactoryTester.cs"> <SubType>Code</SubType> </Compile> - <Compile Include="Container\InstanceManagerTester.cs"> + <Compile Include="Container\ContainerTester.cs"> <SubType>Code</SubType> </Compile> <Compile Include="Container\IntegratedTester.cs"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-05-30 16:36:27
|
Revision: 111 http://structuremap.svn.sourceforge.net/structuremap/?rev=111&view=rev Author: jeremydmiller Date: 2008-05-30 09:36:24 -0700 (Fri, 30 May 2008) Log Message: ----------- ProfileManager.ImportFrom() behavior Modified Paths: -------------- trunk/Source/StructureMap/Pipeline/ProfileManager.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerMergeTester.cs Modified: trunk/Source/StructureMap/Pipeline/ProfileManager.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2008-05-29 03:11:55 UTC (rev 110) +++ trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2008-05-30 16:36:24 UTC (rev 111) @@ -182,5 +182,20 @@ pair.Value.CopyDefault(basicType, templatedType); } } + + public void ImportFrom(ProfileManager source) + { + foreach (KeyValuePair<string, Profile> pair in source._profiles) + { + Profile fromProfile = pair.Value; + Profile toProfile = getProfile(pair.Key); + + fromProfile.FillAllTypesInto(toProfile); + } + + source._default.FillAllTypesInto(_default); + + setProfileDefaults(new GraphLog()); + } } } \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerMergeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerMergeTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerMergeTester.cs 2008-05-30 16:36:24 UTC (rev 111) @@ -0,0 +1,116 @@ +using NUnit.Framework; +using StructureMap.Pipeline; +using StructureMap.Testing.Widget; + +namespace StructureMap.Testing.Pipeline +{ + [TestFixture] + public class ProfileManagerMergeTester + { + private const string PROFILE = "profile"; + + [Test] + public void Import_the_default_for_a_profile_that_is_not_in_the_destination() + { + ProfileManager source = new ProfileManager(); + ConfiguredInstance profileInstance = new ConfiguredInstance(typeof(AWidget)); + source.SetDefault(PROFILE, typeof(IWidget), profileInstance); + + ProfileManager destination = new ProfileManager(); + + destination.ImportFrom(source); + + Assert.AreSame(profileInstance, destination.GetDefault(typeof(IWidget), PROFILE)); + } + + [Test] + public void Import_the_default_for_a_profile_make_sure_overriding_the_destination_does_not_impact_the_source() + { + ProfileManager source = new ProfileManager(); + ConfiguredInstance profileInstance = new ConfiguredInstance(typeof(AWidget)); + source.SetDefault(PROFILE, typeof(IWidget), profileInstance); + + ProfileManager destination = new ProfileManager(); + + destination.ImportFrom(source); + + // Source should be unchanged when destination IS changed + destination.SetDefault(PROFILE, typeof(IWidget), new LiteralInstance(new AWidget())); + Assert.AreSame(profileInstance, source.GetDefault(typeof(IWidget), PROFILE)); + } + + [Test] + public void Import_a_default_for_a_profile_in_destination_does_not_override_existing_default_in_that_profile() + { + ProfileManager source = new ProfileManager(); + ConfiguredInstance sourceInstance = new ConfiguredInstance(typeof(AWidget)); + source.SetDefault(PROFILE, typeof(IWidget), sourceInstance); + + // Fill in value before the ImportFrom + ProfileManager destination = new ProfileManager(); + LiteralInstance destinationInstance = new LiteralInstance(new AWidget()); + destination.SetDefault(PROFILE, typeof(IWidget), destinationInstance); + + destination.ImportFrom(source); + + + Assert.AreSame(destinationInstance, destination.GetDefault(typeof(IWidget), PROFILE)); + } + + [Test] + public void Import_the_default_if_it_is_completely_missing() + { + ProfileManager source = new ProfileManager(); + ConfiguredInstance sourceInstance = new ConfiguredInstance(typeof(AWidget)); + source.SetDefault(typeof(IWidget), sourceInstance); + + ProfileManager destination = new ProfileManager(); + destination.ImportFrom(source); + + Assert.AreSame(sourceInstance, destination.GetDefault(typeof(IWidget))); + } + + [Test] + public void Import_the_default_does_not_impact_the_source() + { + ProfileManager source = new ProfileManager(); + ConfiguredInstance sourceInstance = new ConfiguredInstance(typeof(AWidget)); + source.SetDefault(typeof(IWidget), sourceInstance); + + ProfileManager destination = new ProfileManager(); + destination.ImportFrom(source); + destination.SetDefault(typeof(IWidget), new LiteralInstance(new AWidget())); + + Assert.AreSame(sourceInstance, source.GetDefault(typeof(IWidget))); + } + + [Test] + public void Import_an_instance_from_the_default_profile() + { + ProfileManager source = new ProfileManager(); + ConfiguredInstance sourceInstance = new ConfiguredInstance(typeof(AWidget)); + source.SetDefault(PROFILE, typeof(IWidget), sourceInstance); + + ProfileManager destination = new ProfileManager(); + destination.DefaultProfileName = PROFILE; + destination.ImportFrom(source); + + Assert.AreSame(sourceInstance, destination.GetDefault(typeof(IWidget))); + } + + [Test] + public void Import_a_default_when_the_destination_already_has_an_active_profile() + { + ProfileManager source = new ProfileManager(); + ConfiguredInstance sourceInstance = new ConfiguredInstance(typeof(AWidget)); + source.SetDefault(PROFILE, typeof(IWidget), sourceInstance); + + ProfileManager destination = new ProfileManager(); + destination.SetDefault(PROFILE, typeof(Rule), new ConfiguredInstance(typeof(ColorRule))); + destination.CurrentProfile = PROFILE; + destination.ImportFrom(source); + + Assert.AreSame(sourceInstance, destination.GetDefault(typeof(IWidget))); + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-29 03:11:55 UTC (rev 110) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-30 16:36:24 UTC (rev 111) @@ -332,6 +332,7 @@ <Compile Include="Pipeline\DefaultInstanceTester.cs" /> <Compile Include="Pipeline\InstanceTester.cs" /> <Compile Include="Pipeline\LiteralInstanceTester.cs" /> + <Compile Include="Pipeline\ProfileManagerMergeTester.cs" /> <Compile Include="Pipeline\ProfileManagerTester.cs" /> <Compile Include="Pipeline\ProfileTester.cs" /> <Compile Include="Pipeline\PrototypeInstanceTester.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-06-01 14:33:19
|
Revision: 113 http://structuremap.svn.sourceforge.net/structuremap/?rev=113&view=rev Author: jeremydmiller Date: 2008-06-01 07:33:12 -0700 (Sun, 01 Jun 2008) Log Message: ----------- dynamic container expansion, InjectStub_by_name Modified Paths: -------------- trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap.Testing/BuildSessionTester.cs trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs trunk/Source/StructureMap.Testing/Graph/EnumerationTester.cs Modified: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs 2008-05-31 19:47:30 UTC (rev 112) +++ trunk/Source/StructureMap/Container.cs 2008-06-01 14:33:12 UTC (rev 113) @@ -105,9 +105,10 @@ Inject<T>(instance); } - public void InjectStub<T>(string name, T instance) + public void InjectStub<T>(string name, T stub) { - throw new NotImplementedException(); + LiteralInstance instance = new LiteralInstance(stub).WithName(name); + _pipelineGraph.AddInstance<T>(instance); } public IList<T> GetAllInstances<T>() Modified: trunk/Source/StructureMap.Testing/BuildSessionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-05-31 19:47:30 UTC (rev 112) +++ trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-06-01 14:33:12 UTC (rev 113) @@ -148,7 +148,7 @@ assertActionThrowsErrorCode(200, delegate { BuildSession session = new BuildSession(graph, null); - session.CreateInstance(typeof (IGateway), "A Name"); + session.CreateInstance(typeof (IGateway), "Gateway that is not configured"); }); } Modified: trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs 2008-05-31 19:47:30 UTC (rev 112) +++ trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs 2008-06-01 14:33:12 UTC (rev 113) @@ -33,14 +33,11 @@ private void addColorMemento(string Color) { - ConfiguredInstance instance = new ConfiguredInstance(Color).WithConcreteKey("Color").SetProperty("Color", - Color); - _manager.Configure(delegate(Registry registry) { - registry.AddInstanceOf<Rule>(instance); - registry.AddInstanceOf<IWidget>(instance); - registry.AddInstanceOf<WidgetMaker>(instance); + registry.AddInstanceOf<Rule>().UsingConcreteType<ColorRule>().SetProperty("Color", Color).WithName(Color); + registry.AddInstanceOf<IWidget>().UsingConcreteType<ColorWidget>().SetProperty("Color", Color).WithName(Color); + registry.AddInstanceOf<WidgetMaker>().UsingConcreteType<ColorWidgetMaker>().SetProperty("Color", Color).WithName(Color); }); } @@ -203,8 +200,16 @@ [Test] public void InjectStub_by_name() { - Assert.Fail("Do."); IContainer container = new Container(); + + ColorRule red = new ColorRule("Red"); + ColorRule blue = new ColorRule("Blue"); + + container.InjectStub<Rule>("Red", red); + container.InjectStub<Rule>("Blue", blue); + + Assert.AreSame(red, container.GetInstance<Rule>("Red")); + Assert.AreSame(blue, container.GetInstance<Rule>("Blue")); } Modified: trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs 2008-05-31 19:47:30 UTC (rev 112) +++ trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs 2008-06-01 14:33:12 UTC (rev 113) @@ -113,8 +113,13 @@ family.AddPlugin(typeof (SomethingOne), "One"); IContainer manager = new Container(pluginGraph); + manager.Configure( - delegate(Registry registry) { registry.AddInstanceOf<ISomething>().WithConcreteKey("One").WithName("One"); }); + delegate(Registry registry) + { + registry.ForRequestedType<ISomething>().AliasConcreteType<SomethingOne>("One"); + registry.AddInstanceOf<ISomething>().WithConcreteKey("One").WithName("One"); + }); IList<ISomething> list = manager.GetAllInstances<ISomething>(); Assert.AreEqual(1, list.Count); Modified: trunk/Source/StructureMap.Testing/Graph/EnumerationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/EnumerationTester.cs 2008-05-31 19:47:30 UTC (rev 112) +++ trunk/Source/StructureMap.Testing/Graph/EnumerationTester.cs 2008-06-01 14:33:12 UTC (rev 113) @@ -21,7 +21,7 @@ manager.Configure(delegate(Registry registry) { - registry.AddInstanceOf<Cow>().UsingConcreteTypeNamed("Default") + registry.AddInstanceOf<Cow>().UsingConcreteType<Cow>() .WithName("Angus") .WithProperty("Name").EqualTo("Bessie") .WithProperty("Breed").EqualTo("Angus") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-06-01 23:59:12
|
Revision: 114 http://structuremap.svn.sourceforge.net/structuremap/?rev=114&view=rev Author: jeremydmiller Date: 2008-06-01 16:59:11 -0700 (Sun, 01 Jun 2008) Log Message: ----------- Default convention scanning Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs trunk/Source/StructureMap/Graph/AssemblyScanner.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap/Graph/ITypeScanner.cs trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-06-01 14:33:12 UTC (rev 113) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-06-01 23:59:11 UTC (rev 114) @@ -85,5 +85,16 @@ return this; } + + public ScanAssembliesExpression With(ITypeScanner scanner) + { + _registry.addExpression(delegate(PluginGraph graph) + { + graph.Assemblies.AddScanner(scanner); + }); + + + return this; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/AssemblyScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2008-06-01 14:33:12 UTC (rev 113) +++ trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2008-06-01 23:59:11 UTC (rev 114) @@ -6,12 +6,12 @@ namespace StructureMap.Graph { - // TODO: redo in 3.5 w/ Lambdas public class AssemblyScanner { private readonly List<Assembly> _assemblies = new List<Assembly>(); private readonly GraphLog _log; + private readonly List<ITypeScanner> _scanners = new List<ITypeScanner>(); public AssemblyScanner(GraphLog log) { @@ -27,35 +27,49 @@ { // Don't do this for SystemScan scanTypes(delegate(Type type) - { - if (Registry.IsPublicRegistry(type)) - { - Registry registry = (Registry) Activator.CreateInstance(type); - registry.ConfigurePluginGraph(pluginGraph); - } - }); + { + if (!Registry.IsPublicRegistry(type)) return; + Registry registry = (Registry) Activator.CreateInstance(type); + registry.ConfigurePluginGraph(pluginGraph); + }); + findFamiliesAndPlugins(pluginGraph); + runScanners(pluginGraph); } + private void runScanners(PluginGraph graph) + { + Registry registry = new Registry(); + scanTypes(delegate(Type type) + { + foreach (ITypeScanner scanner in _scanners) + { + scanner.Process(type, registry); + } + }); + + registry.ConfigurePluginGraph(graph); + } + private void findFamiliesAndPlugins(PluginGraph pluginGraph) { scanTypes(delegate(Type type) - { - if (PluginFamilyAttribute.MarkedAsPluginFamily(type)) - { - pluginGraph.CreateFamily(type); - } - }); + { + if (PluginFamilyAttribute.MarkedAsPluginFamily(type)) + { + pluginGraph.CreateFamily(type); + } + }); scanTypes(delegate(Type type) - { - foreach (PluginFamily family in pluginGraph.PluginFamilies) - { - family.AnalyzeTypeForPlugin(type); - } - }); + { + foreach (PluginFamily family in pluginGraph.PluginFamilies) + { + family.AnalyzeTypeForPlugin(type); + } + }); } @@ -121,5 +135,10 @@ return false; } + + public void AddScanner(ITypeScanner scanner) + { + _scanners.Add(scanner); + } } } \ No newline at end of file Added: trunk/Source/StructureMap/Graph/ITypeScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/ITypeScanner.cs (rev 0) +++ trunk/Source/StructureMap/Graph/ITypeScanner.cs 2008-06-01 23:59:11 UTC (rev 114) @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Text; +using StructureMap.Configuration.DSL; + +namespace StructureMap.Graph +{ + public interface ITypeScanner + { + void Process(Type type, Registry registry); + } + + public class DefaultConventionScanner : TypeRules, ITypeScanner + { + public void Process(Type type, Registry registry) + { + if (!IsConcrete(type)) return; + + Type pluginType = FindPluginType(type); + if (pluginType != null) + { + registry.ForRequestedType(pluginType).TheDefaultIsConcreteType(type); + } + } + + public static Type FindPluginType(Type concreteType) + { + string interfaceName = "I" + concreteType.Name; + Type[] interfaces = concreteType.GetInterfaces(); + return Array.Find(interfaces, delegate(Type t) + { + return t.Name == interfaceName; + }); + } + } +} Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-06-01 14:33:12 UTC (rev 113) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-06-01 23:59:11 UTC (rev 114) @@ -374,6 +374,7 @@ <Link>Properties\structuremap.snk</Link> </None> <Compile Include="ErrorMessages.cs" /> + <Compile Include="Graph\ITypeScanner.cs" /> <Compile Include="Pipeline\ConfiguredInstance.Building.cs" /> <Compile Include="Pipeline\IStructuredInstance.cs" /> <Compile Include="Util\Cache.cs" /> Added: trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs 2008-06-01 23:59:11 UTC (rev 114) @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Text; +using NUnit.Framework; +using StructureMap.Configuration.DSL; +using StructureMap.Graph; +using StructureMap.Pipeline; + +namespace StructureMap.Testing.Graph +{ + [TestFixture] + public class DefaultConventionScanningTester + { + [Test] + public void FindPluginType() + { + Assert.AreEqual(typeof(IConvention), DefaultConventionScanner.FindPluginType(typeof(Convention))); + Assert.IsNull(DefaultConventionScanner.FindPluginType(this.GetType())); + } + + + [Test] + public void Process_to_PluginGraph() + { + Registry registry = new Registry(); + DefaultConventionScanner scanner = new DefaultConventionScanner(); + scanner.Process(typeof(Convention), registry); + + PluginGraph graph = registry.Build(); + + Assert.IsFalse(graph.PluginFamilies.Contains(typeof(IServer))); + Assert.IsTrue(graph.PluginFamilies.Contains(typeof(IConvention))); + + PluginFamily family = graph.FindFamily(typeof (IConvention)); + Assert.AreEqual(1, family.InstanceCount); + } + + [Test] + public void Process_to_Container() + { + Container container = new Container(delegate(Registry registry) + { + registry.ScanAssemblies().IncludeTheCallingAssembly() + .With(new DefaultConventionScanner()); + }); + + Assert.IsInstanceOfType(typeof(Convention), container.GetInstance<IConvention>()); + } + } + + public interface IConvention{} + public interface IServer{} + public class Convention : IConvention, IServer + { + public void Go() + { + throw new NotImplementedException(); + } + } + + public class Something : IConvention{} +} Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-06-01 14:33:12 UTC (rev 113) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-06-01 23:59:11 UTC (rev 114) @@ -191,6 +191,7 @@ <Compile Include="Graph\ContainerConstructorAttributeTester.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Graph\DefaultConventionScanningTester.cs" /> <Compile Include="Graph\DynamicInjectionTester.cs" /> <Compile Include="Graph\EmittingTester.cs"> <SubType>Code</SubType> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-06-02 03:02:31
|
Revision: 115 http://structuremap.svn.sourceforge.net/structuremap/?rev=115&view=rev Author: jeremydmiller Date: 2008-06-01 20:02:16 -0700 (Sun, 01 Jun 2008) Log Message: ----------- mild refactoring of DefaultConventionScanner Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs trunk/Source/StructureMap/Graph/ITypeScanner.cs trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-06-01 23:59:11 UTC (rev 114) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-06-02 03:02:16 UTC (rev 115) @@ -96,5 +96,10 @@ return this; } + + public ScanAssembliesExpression With<T>() where T : ITypeScanner, new() + { + return With(new T()); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/ITypeScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/ITypeScanner.cs 2008-06-01 23:59:11 UTC (rev 114) +++ trunk/Source/StructureMap/Graph/ITypeScanner.cs 2008-06-02 03:02:16 UTC (rev 115) @@ -23,7 +23,7 @@ } } - public static Type FindPluginType(Type concreteType) + public virtual Type FindPluginType(Type concreteType) { string interfaceName = "I" + concreteType.Name; Type[] interfaces = concreteType.GetInterfaces(); Modified: trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs 2008-06-01 23:59:11 UTC (rev 114) +++ trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs 2008-06-02 03:02:16 UTC (rev 115) @@ -14,8 +14,8 @@ [Test] public void FindPluginType() { - Assert.AreEqual(typeof(IConvention), DefaultConventionScanner.FindPluginType(typeof(Convention))); - Assert.IsNull(DefaultConventionScanner.FindPluginType(this.GetType())); + Assert.AreEqual(typeof(IConvention), new DefaultConventionScanner().FindPluginType(typeof(Convention))); + Assert.IsNull(new DefaultConventionScanner().FindPluginType(this.GetType())); } @@ -46,6 +46,19 @@ Assert.IsInstanceOfType(typeof(Convention), container.GetInstance<IConvention>()); } + + + [Test] + public void Process_to_Container_2() + { + Container container = new Container(delegate(Registry registry) + { + registry.ScanAssemblies().IncludeTheCallingAssembly() + .With<DefaultConventionScanner>(); + }); + + Assert.IsInstanceOfType(typeof(Convention), container.GetInstance<IConvention>()); + } } public interface IConvention{} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-06-05 13:32:35
|
Revision: 118 http://structuremap.svn.sourceforge.net/structuremap/?rev=118&view=rev Author: jeremydmiller Date: 2008-06-05 06:32:32 -0700 (Thu, 05 Jun 2008) Log Message: ----------- missed checkin stuff Modified Paths: -------------- trunk/Source/StructureMap/ObjectFactory.cs Added Paths: ----------- trunk/Source/StructureMap.Testing/Graph/ExceptionHandling/ trunk/Source/StructureMap.Testing/Graph/ExceptionHandling/StructureMapExceptionTester.cs trunk/Source/StructureMap.Testing/Graph/Interceptors/ trunk/Source/StructureMap.Testing/Graph/Interceptors/CompoundInterceptorTester.cs trunk/Source/StructureMap.Testing/Graph/Interceptors/InterceptorLibraryTester.cs trunk/Source/StructureMap.Testing/Graph/Interceptors/MockTypeInterceptor.cs trunk/Source/StructureMap.Testing/Graph/Interceptors/TypeInterceptionTester.cs Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-06-02 16:28:50 UTC (rev 117) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-06-05 13:32:32 UTC (rev 118) @@ -33,6 +33,19 @@ } /// <summary> + /// Restarts ObjectFactory and blows away all Singleton's and cached instances. Use with caution. + /// </summary> + public static void Reset() + { + _manager = buildManager(); + + if (_notify != null) + { + _notify(); + } + } + + /// <summary> /// Attempts to create a new instance of the requested type. Automatically inserts the default /// configured instance for each dependency in the StructureMap constructor function. /// </summary> @@ -70,7 +83,12 @@ manager.InjectStub(typeof (PLUGINTYPE), stub); } + public static void InjectStub<PLUGINTYPE>(string name, PLUGINTYPE stub) + { + manager.InjectStub<PLUGINTYPE>(name, stub); + } + public static string WhatDoIHave() { return manager.WhatDoIHave(); @@ -124,18 +142,7 @@ get { return _profile; } } - /// <summary> - /// Restarts ObjectFactory. Use with caution. - /// </summary> - public static void Reset() - { - _manager = buildManager(); - if (_notify != null) - { - _notify(); - } - } /// <summary> /// Strictly used for testing scenarios @@ -178,7 +185,8 @@ /// <summary> - /// Restores all default instance settings according to the StructureMap.config files + /// Restores all default instance settings and removes any Profile settings applied + /// at runtime /// </summary> public static void ResetDefaults() { Added: trunk/Source/StructureMap.Testing/Graph/ExceptionHandling/StructureMapExceptionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/ExceptionHandling/StructureMapExceptionTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/ExceptionHandling/StructureMapExceptionTester.cs 2008-06-05 13:32:32 UTC (rev 118) @@ -0,0 +1,237 @@ +using System; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; +using System.Xml; +using NUnit.Framework; +using StructureMap.Configuration; +using StructureMap.Graph; +using StructureMap.Testing.TestData; +using StructureMap.Testing.Widget; + +namespace StructureMap.Testing.Graph.ExceptionHandling +{ + [TestFixture] + public class StructureMapExceptionTester + { + private void assertErrorIsLogged(int errorCode, string xml) + { + PluginGraph graph = DataMother.BuildPluginGraphFromXml(xml); + graph.Log.AssertHasError(errorCode); + } + + + private void assertErrorIsThrown(int errorCode, string xml, Action<Container> action) + { + XmlDocument document = new XmlDocument(); + document.LoadXml(xml.Replace("\"", "'")); + + ConfigurationParser parser = new ConfigurationParser(document.DocumentElement); + PluginGraphBuilder builder = new PluginGraphBuilder(parser); + Container manager = new Container(builder.Build()); + + try + { + action(manager); + Assert.Fail("Should have thrown exception"); + } + catch (StructureMapException ex) + { + Assert.AreEqual(errorCode, ex.ErrorCode, "Expected error code"); + } + } + + [Test] + public void CanSerialize() + { + ApplicationException ex = new ApplicationException("Oh no!"); + StructureMapException smapEx = new StructureMapException(200, ex, "a", "b"); + + BinaryFormatter formatter = new BinaryFormatter(); + MemoryStream stream = new MemoryStream(); + formatter.Serialize(stream, smapEx); + + stream.Position = 0; + + StructureMapException smapEx2 = (StructureMapException) formatter.Deserialize(stream); + Assert.AreNotSame(smapEx, smapEx2); + + Assert.AreEqual(smapEx.Message, smapEx2.Message); + } + + [Test] + public void CouldNotFindConcreteKey() + { + assertErrorIsLogged(201, + @" + <StructureMap> + <Assembly Name='StructureMap.Testing.Widget'/> + + <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''> + <Instance Key='BadConcreteKey' Type='NotARealConcreteKey'></Instance> + </PluginFamily> + </StructureMap> + "); + } + + [Test] + public void CouldNotFindInstanceKey() + { + assertErrorIsThrown(200, + @" + <StructureMap> + <Assembly Name='StructureMap.Testing.Widget'/> + + <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''> </PluginFamily> + </StructureMap> + ", + delegate(Container manager) { manager.GetInstance<IWidget>("NotAnActualInstanceName"); } + ); + } + + [Test] + public void CouldNotUpcastDesignatedPluggedTypeIntoPluginType() + { + assertErrorIsLogged(104, + @" + <StructureMap> + <Assembly Name='StructureMap.Testing.Widget'/> + + <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''> + <Plugin Assembly='StructureMap.Testing.Widget' Type='StructureMap.Testing.Widget.ComplexRule' ConcreteKey='Rule'/> + </PluginFamily> + </StructureMap> + "); + } + + [Test] + public void ExceptionMessage() + { + StructureMapException exception = new StructureMapException(100, "StructureMap.config"); + string expected = + "StructureMap Exception Code: 100\nExpected file \"StructureMap.config\" cannot be opened at StructureMap.config"; + + string actual = exception.Message; + + Assert.AreEqual(expected, actual); + } + + [Test] + public void Log_101_if_CannotLoadAssemblyInAssemblyNode() + { + assertErrorIsLogged(101, + @" + <StructureMap> + <Assembly Name='StructureMap.NonExistent'/> + </StructureMap> + "); + } + + + [Test] + public void Log_103_CannotLoadTypeFromPluginFamilyNode() + { + assertErrorIsLogged(103, + @" + <StructureMap> + <PluginFamily Assembly='StructureMap.Testing.Widget' Type='StructureMap.Testing.Widget.NotARealType'/> + </StructureMap> + "); + } + + [Test] + public void Log_112_if_MissingConcreteKeyOnPluginNode() + { + assertErrorIsLogged(112, + @" + <StructureMap> + <Assembly Name='StructureMap.Testing.Widget'/> + + <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''> + <Plugin Assembly='StructureMap.Testing.Widget' Type='StructureMap.Testing.Widget.NotPluggableWidget' ConcreteKey=''/> + </PluginFamily> + </StructureMap> +"); + } + + [Test] + public void Log_113_if_a_duplicate_Plugin_ConcreteKey_is_detected() + { + assertErrorIsLogged(113, + @" + + <StructureMap> + <Assembly Name='StructureMap.Testing.Widget'/> + + <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''> + <Plugin Assembly='StructureMap.Testing.Widget' Type='StructureMap.Testing.Widget.NotPluggableWidget' ConcreteKey='Dup'/> + <Plugin Assembly='StructureMap.Testing.Widget' Type='StructureMap.Testing.Widget.NotPluggableWidget' ConcreteKey='Dup'/> + </PluginFamily> + </StructureMap> + +"); + } + + [Test] + public void Log_130_if_an_error_occurs_when_trying_to_create_an_interceptor_configured_in_xml() + { + assertErrorIsLogged(130, + @" + <StructureMap> + <Assembly Name='StructureMap.Testing.Widget'/> + + <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''> + <Interceptors> + <Interceptor Type='NotARealType'></Interceptor> + </Interceptors> + </PluginFamily> + </StructureMap> +"); + } + + [Test] + public void Log_130_if_there_is_an_error_while_creating_TheDesignatedMementoSourceForAPluginFamily() + { + assertErrorIsLogged(130, + @" + <StructureMap> + <Assembly Name='StructureMap.Testing.Widget'/> + + <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''> + <Plugin Assembly='StructureMap.Testing.Widget' Type='StructureMap.Testing.Widget.NotPluggableWidget' ConcreteKey='Dup'/> + <Source Type='Nonexistent'/> + </PluginFamily> + </StructureMap> +"); + } + + [Test] + public void Log_131_if_Plugin_type_could_not_be_loaded_from_Xml_configuration() + { + assertErrorIsLogged(131, + @" + <StructureMap> + <Assembly Name='StructureMap.Testing.Widget'/> + + <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''> + <Plugin Assembly='StructureMap.Testing' Type='StructureMap.Testing.Widget.NotARealClass' ConcreteKey='NotReal'/> + </PluginFamily> + </StructureMap> + "); + } + + [Test] + public void Throw_202_when_DefaultKeyDoesNotExist() + { + assertErrorIsThrown(202, + @" + <StructureMap> + <Assembly Name='StructureMap.Testing.Widget'/> + + <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''></PluginFamily> + </StructureMap> + ", + delegate(Container manager) { manager.GetInstance<IWidget>(); } + ); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Interceptors/CompoundInterceptorTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Interceptors/CompoundInterceptorTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Interceptors/CompoundInterceptorTester.cs 2008-06-05 13:32:32 UTC (rev 118) @@ -0,0 +1,46 @@ +using NUnit.Framework; +using Rhino.Mocks; +using StructureMap.Interceptors; + +namespace StructureMap.Testing.Graph.Interceptors +{ + [TestFixture] + public class CompoundInterceptorTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + } + + #endregion + + [Test] + public void CallAllTheInterceptors() + { + MockRepository mocks = new MockRepository(); + InstanceInterceptor interceptor1 = mocks.CreateMock<InstanceInterceptor>(); + InstanceInterceptor interceptor2 = mocks.CreateMock<InstanceInterceptor>(); + InstanceInterceptor interceptor3 = mocks.CreateMock<InstanceInterceptor>(); + InstanceInterceptor interceptor4 = mocks.CreateMock<InstanceInterceptor>(); + + Expect.Call(interceptor1.Process("0")).Return("1"); + Expect.Call(interceptor2.Process("1")).Return("2"); + Expect.Call(interceptor3.Process("2")).Return("3"); + Expect.Call(interceptor4.Process("3")).Return("4"); + + mocks.ReplayAll(); + CompoundInterceptor compoundInterceptor = new CompoundInterceptor(new InstanceInterceptor[] + { + interceptor1, + interceptor2, + interceptor3, + interceptor4 + }); + + Assert.AreEqual("4", compoundInterceptor.Process("0")); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Interceptors/InterceptorLibraryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Interceptors/InterceptorLibraryTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Interceptors/InterceptorLibraryTester.cs 2008-06-05 13:32:32 UTC (rev 118) @@ -0,0 +1,156 @@ +using System; +using NUnit.Framework; +using Rhino.Mocks; +using StructureMap.Interceptors; + +namespace StructureMap.Testing.Graph.Interceptors +{ + [TestFixture] + public class InterceptorLibraryTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + _interceptor1 = new MockTypeInterceptor(typeof (string)); + _interceptor2 = new MockTypeInterceptor(typeof (int), typeof (double)); + _interceptor3 = new MockTypeInterceptor(typeof (string), typeof (bool)); + _interceptor4 = new MockTypeInterceptor(typeof (string), typeof (double)); + + _library = new InterceptorLibrary(); + _library.AddInterceptor(_interceptor1); + _library.AddInterceptor(_interceptor2); + _library.AddInterceptor(_interceptor3); + _library.AddInterceptor(_interceptor4); + } + + #endregion + + private MockTypeInterceptor _interceptor1; + private MockTypeInterceptor _interceptor2; + private MockTypeInterceptor _interceptor3; + private MockTypeInterceptor _interceptor4; + private InterceptorLibrary _library; + + [Test] + public void Find_All_Of_The_Interceptors_For_A_Type_On_Multiple_Passes() + { + Assert.AreEqual(new TypeInterceptor[] {_interceptor1, _interceptor3, _interceptor4}, + _library.FindInterceptors(typeof (string))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2, _interceptor4}, + _library.FindInterceptors(typeof (double))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2}, _library.FindInterceptors(typeof (int))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor3}, _library.FindInterceptors(typeof (bool))); + + Assert.AreEqual(new TypeInterceptor[] {_interceptor1, _interceptor3, _interceptor4}, + _library.FindInterceptors(typeof (string))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2, _interceptor4}, + _library.FindInterceptors(typeof (double))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2}, _library.FindInterceptors(typeof (int))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor3}, _library.FindInterceptors(typeof (bool))); + + Assert.AreEqual(new TypeInterceptor[] {_interceptor1, _interceptor3, _interceptor4}, + _library.FindInterceptors(typeof (string))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2, _interceptor4}, + _library.FindInterceptors(typeof (double))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2}, _library.FindInterceptors(typeof (int))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor3}, _library.FindInterceptors(typeof (bool))); + + Assert.AreEqual(new TypeInterceptor[] {_interceptor1, _interceptor3, _interceptor4}, + _library.FindInterceptors(typeof (string))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2, _interceptor4}, + _library.FindInterceptors(typeof (double))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2}, _library.FindInterceptors(typeof (int))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor3}, _library.FindInterceptors(typeof (bool))); + } + + [Test] + public void Find_All_Of_The_Interceptors_For_A_Type_On_The_First_Pass() + { + Assert.AreEqual(new TypeInterceptor[] {_interceptor1, _interceptor3, _interceptor4}, + _library.FindInterceptors(typeof (string))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2, _interceptor4}, + _library.FindInterceptors(typeof (double))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2}, _library.FindInterceptors(typeof (int))); + Assert.AreEqual(new TypeInterceptor[] {_interceptor3}, _library.FindInterceptors(typeof (bool))); + } + + [Test] + public void Find_CompoundInterceptor_For_A_Type_On_The_First_Pass() + { + Assert.AreEqual(new TypeInterceptor[] {_interceptor1, _interceptor3, _interceptor4}, + _library.FindInterceptor(typeof (string)).Interceptors); + Assert.AreEqual(new TypeInterceptor[] {_interceptor2, _interceptor4}, + _library.FindInterceptor(typeof (double)).Interceptors); + } + + [Test] + public void Import_from_gets_all_interceptors_and_resets_the_type_filter() + { + InterceptorLibrary sourceLibrary = new InterceptorLibrary(); + sourceLibrary.AddInterceptor(new MockTypeInterceptor(typeof (string))); + sourceLibrary.FindInterceptor(typeof (string)); + + InterceptorLibrary destinationLibrary = new InterceptorLibrary(); + destinationLibrary.AddInterceptor(new MockTypeInterceptor(typeof (string))); + + destinationLibrary.ImportFrom(sourceLibrary); + + InstanceInterceptor[] interceptors = destinationLibrary.FindInterceptors(typeof (string)); + Assert.AreEqual(2, interceptors.Length); + } + + + [Test] + public void + When_Interceptors_Are_Requested_For_A_Type_For_The_First_Time_The_Library_Will_Scan_All_The_TypeInterceptors + () + { + MockRepository mocks = new MockRepository(); + TypeInterceptor interceptor1 = mocks.CreateMock<TypeInterceptor>(); + TypeInterceptor interceptor2 = mocks.CreateMock<TypeInterceptor>(); + TypeInterceptor interceptor3 = mocks.CreateMock<TypeInterceptor>(); + + _library.AddInterceptor(interceptor1); + _library.AddInterceptor(interceptor2); + _library.AddInterceptor(interceptor3); + + Type type = typeof (string); + Expect.Call(interceptor1.MatchesType(type)).Return(true); + Expect.Call(interceptor2.MatchesType(type)).Return(true); + Expect.Call(interceptor3.MatchesType(type)).Return(true); + + mocks.ReplayAll(); + _library.FindInterceptors(type); + mocks.VerifyAll(); + } + + [Test] + public void When_Interceptors_Are_Requested_For_The_Second_Time_The_Library_Will_NOT_Scan_The_Interceptors_Again + () + { + MockRepository mocks = new MockRepository(); + TypeInterceptor interceptor1 = mocks.CreateMock<TypeInterceptor>(); + TypeInterceptor interceptor2 = mocks.CreateMock<TypeInterceptor>(); + TypeInterceptor interceptor3 = mocks.CreateMock<TypeInterceptor>(); + + _library.AddInterceptor(interceptor1); + _library.AddInterceptor(interceptor2); + _library.AddInterceptor(interceptor3); + + Type type = typeof (string); + Expect.Call(interceptor1.MatchesType(type)).Return(true); + Expect.Call(interceptor2.MatchesType(type)).Return(true); + Expect.Call(interceptor3.MatchesType(type)).Return(true); + + mocks.ReplayAll(); + _library.FindInterceptors(type); + _library.FindInterceptors(type); + _library.FindInterceptors(type); + _library.FindInterceptors(type); + _library.FindInterceptors(type); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Interceptors/MockTypeInterceptor.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Interceptors/MockTypeInterceptor.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Interceptors/MockTypeInterceptor.cs 2008-06-05 13:32:32 UTC (rev 118) @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using StructureMap.Interceptors; + +namespace StructureMap.Testing.Graph.Interceptors +{ + public class MockTypeInterceptor : TypeInterceptor + { + #region Delegates + + public delegate object InterceptionDelegate<T>(T target); + + #endregion + + private readonly Dictionary<Type, InstanceInterceptor> _innerInterceptors + = new Dictionary<Type, InstanceInterceptor>(); + + private readonly List<Type> _types = new List<Type>(); + + public MockTypeInterceptor(params Type[] types) + { + _types.AddRange(types); + } + + #region TypeInterceptor Members + + public bool MatchesType(Type type) + { + return _types.Contains(type); + } + + public object Process(object target) + { + return _innerInterceptors[target.GetType()].Process(target); + } + + #endregion + + public void SetToMatch<T>() + { + _types.Add(typeof (T)); + } + + public void AddHandler<T>(InterceptionDelegate<T> handler) + { + _types.Add(typeof (T)); + _innerInterceptors.Add(typeof (T), new CommonInterceptor<T>(handler)); + } + + #region Nested type: CommonInterceptor + + public class CommonInterceptor<T> : InstanceInterceptor + { + private readonly InterceptionDelegate<T> _handler; + + public CommonInterceptor(InterceptionDelegate<T> handler) + { + _handler = handler; + } + + #region InstanceInterceptor Members + + public object Process(object target) + { + return _handler((T) target); + } + + #endregion + } + + #endregion + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Interceptors/TypeInterceptionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Interceptors/TypeInterceptionTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Interceptors/TypeInterceptionTester.cs 2008-06-05 13:32:32 UTC (rev 118) @@ -0,0 +1,119 @@ +using System; +using NUnit.Framework; +using StructureMap.Configuration.DSL; + +namespace StructureMap.Testing.Graph.Interceptors +{ + [TestFixture] + public class TypeInterceptionTester : Registry + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + manager = null; + + registry = new Registry(); + registry.ForRequestedType<IAnInterfaceOfSomeSort>() + .AddInstance(Instance<RedSomething>().WithName("Red")) + .AddInstance(Instance<GreenSomething>().WithName("Green")) + .AddInstance(Instance<BlueSomething>().WithName("Blue")); + } + + #endregion + + private Registry registry; + private IContainer manager; + + private void assertThisIsType<T>(string name) + { + if (manager == null) + { + manager = new Container(registry); + } + + Assert.IsInstanceOfType(typeof (T), manager.GetInstance<IAnInterfaceOfSomeSort>(name)); + } + + private void assertThatThisIsWrappedSomething<OUTERTYPE, INNERTYPE>(string name) + where OUTERTYPE : WrappedSomething + { + if (manager == null) + { + manager = new Container(registry); + } + + OUTERTYPE something = (OUTERTYPE) manager.GetInstance<IAnInterfaceOfSomeSort>(name); + Assert.IsInstanceOfType(typeof (INNERTYPE), something.Inner); + } + + public interface IAnInterfaceOfSomeSort + { + } + + public class RedSomething : IAnInterfaceOfSomeSort + { + } + + public class GreenSomething : IAnInterfaceOfSomeSort + { + } + + public class BlueSomething : IAnInterfaceOfSomeSort + { + } + + public class WrappedSomething : IAnInterfaceOfSomeSort + { + private readonly IAnInterfaceOfSomeSort _inner; + + public WrappedSomething(IAnInterfaceOfSomeSort inner) + { + _inner = inner; + } + + + public IAnInterfaceOfSomeSort Inner + { + get { return _inner; } + } + } + + public class WrappedSomething2 : WrappedSomething + { + public WrappedSomething2(IAnInterfaceOfSomeSort inner) : base(inner) + { + } + } + + [Test] + public void If_An_Interceptor_Is_Registered_At_The_PluginGraph_It_Will_Be_Used_To_Construct_An_Instance() + { + MockTypeInterceptor interceptor = new MockTypeInterceptor(); + interceptor.AddHandler<RedSomething>( + delegate(RedSomething something) { return new WrappedSomething(something); }); + + interceptor.AddHandler<GreenSomething>( + delegate(GreenSomething something) { return new WrappedSomething2(something); }); + + registry.RegisterInterceptor(interceptor); + + assertThisIsType<BlueSomething>("Blue"); + assertThatThisIsWrappedSomething<WrappedSomething, RedSomething>("Red"); + assertThatThisIsWrappedSomething<WrappedSomething2, GreenSomething>("Green"); + } + + [Test] + public void Register_A_Type_Interceptor_By_The_Fluent_Interface() + { + registry.IfTypeMatches(delegate(Type type) { return type.Equals(typeof (BlueSomething)); }) + .InterceptWith( + delegate(object rawInstance) { return new WrappedSomething((IAnInterfaceOfSomeSort) rawInstance); }); + + assertThisIsType<RedSomething>("Red"); + assertThisIsType<GreenSomething>("Green"); + assertThatThisIsWrappedSomething<WrappedSomething, BlueSomething>("Blue"); + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-06-07 22:28:54
|
Revision: 119 http://structuremap.svn.sourceforge.net/structuremap/?rev=119&view=rev Author: jeremydmiller Date: 2008-06-07 15:28:52 -0700 (Sat, 07 Jun 2008) Log Message: ----------- diagnostics - wip Modified Paths: -------------- trunk/Source/StructureMap/Diagnostics/GraphLog.cs trunk/Source/StructureMap/StructureMap.csproj Modified: trunk/Source/StructureMap/Diagnostics/GraphLog.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/GraphLog.cs 2008-06-05 13:32:32 UTC (rev 118) +++ trunk/Source/StructureMap/Diagnostics/GraphLog.cs 2008-06-07 22:28:52 UTC (rev 119) @@ -63,12 +63,12 @@ return; } - string message = WriteFailures(); + string message = BuildFailureMessage(); throw new StructureMapConfigurationException(message); } - private string WriteFailures() + public string BuildFailureMessage() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-06-05 13:32:32 UTC (rev 118) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-06-07 22:28:52 UTC (rev 119) @@ -373,8 +373,10 @@ <None Include="..\structuremap.snk"> <Link>Properties\structuremap.snk</Link> </None> + <Compile Include="Diagnostics\Doctor.cs" /> <Compile Include="ErrorMessages.cs" /> <Compile Include="Graph\ITypeScanner.cs" /> + <Compile Include="IBootstrapper.cs" /> <Compile Include="Pipeline\ConfiguredInstance.Building.cs" /> <Compile Include="Pipeline\IStructuredInstance.cs" /> <Compile Include="Util\Cache.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-06-07 22:48:48
|
Revision: 120 http://structuremap.svn.sourceforge.net/structuremap/?rev=120&view=rev Author: jeremydmiller Date: 2008-06-07 15:48:46 -0700 (Sat, 07 Jun 2008) Log Message: ----------- missed a file or two Added Paths: ----------- trunk/Source/StructureMap/Diagnostics/Doctor.cs trunk/Source/StructureMap/IBootstrapper.cs Added: trunk/Source/StructureMap/Diagnostics/Doctor.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/Doctor.cs (rev 0) +++ trunk/Source/StructureMap/Diagnostics/Doctor.cs 2008-06-07 22:48:46 UTC (rev 120) @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Text; +using StructureMap.Graph; + +namespace StructureMap.Diagnostics +{ + + + public class DoctorReport + { + public string Message; + public bool Failure; + } + + public class DoctorRunner : MarshalByRefObject + { + public override object InitializeLifetimeService() + { + return null; + } + + public DoctorReport RunReport(string bootstrapperTypeName) + { + // TODO: bootstrapperType cannot be found + // TODO: bootstrapperType blows up + TypePath path = new TypePath(bootstrapperTypeName); + Type bootstrapperType = path.FindType(); + + IBootstrapper bootstrapper = (IBootstrapper) Activator.CreateInstance(bootstrapperType); + + // TODO - random error + PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); + + // TODO -- Fails on constructor + if (graph.Log.ErrorCount > 0) + { + + } + + + } + } + + public class Doctor + { + } +} Added: trunk/Source/StructureMap/IBootstrapper.cs =================================================================== --- trunk/Source/StructureMap/IBootstrapper.cs (rev 0) +++ trunk/Source/StructureMap/IBootstrapper.cs 2008-06-07 22:48:46 UTC (rev 120) @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace StructureMap +{ + public interface IBootstrapper + { + void BootstrapStructureMap(); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-06-15 14:28:16
|
Revision: 122 http://structuremap.svn.sourceforge.net/structuremap/?rev=122&view=rev Author: jeremydmiller Date: 2008-06-15 07:28:14 -0700 (Sun, 15 Jun 2008) Log Message: ----------- cleaning up the xml parsing Modified Paths: -------------- trunk/Source/StructureMap/Configuration/FamilyParser.cs trunk/Source/StructureMap/Diagnostics/Error.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-06-15 01:49:31 UTC (rev 121) +++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-06-15 14:28:14 UTC (rev 122) @@ -30,12 +30,17 @@ family.SetScopeTo(scope); attachMementoSource(family, familyElement); - familyElement.ForEachChild(PLUGIN_NODE).Do(element => attachPlugin(element, family)); + attachPlugins(family, familyElement); attachInterceptors(family, familyElement); attachInstances(family, familyElement, _builder); }); } + private void attachPlugins(PluginFamily family, XmlElement familyElement) + { + familyElement.ForEachChild(PLUGIN_NODE).Do(element => attachPlugin(element, family)); + } + private void attachInstances(PluginFamily family, XmlElement familyElement, IGraphBuilder builder) { familyElement.ForEachChild(INSTANCE_NODE).Do(element => @@ -108,7 +113,6 @@ family.AddPlugin(plugin); pluginElement.ForTextInChild("Setter/@Name").Do(prop => plugin.Setters.Add(prop)); - }); } @@ -119,8 +123,10 @@ { var interceptorMemento = new XmlAttributeInstanceMemento(element); string context = contextBase + element.OuterXml; - _builder.WithSystemObject<IBuildInterceptor>(interceptorMemento, context, - interceptor => family.AddInterceptor(interceptor)); + _builder.WithSystemObject<IBuildInterceptor>( + interceptorMemento, + context, + interceptor => family.AddInterceptor(interceptor)); }); } } Modified: trunk/Source/StructureMap/Diagnostics/Error.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/Error.cs 2008-06-15 01:49:31 UTC (rev 121) +++ trunk/Source/StructureMap/Diagnostics/Error.cs 2008-06-15 14:28:14 UTC (rev 122) @@ -88,7 +88,6 @@ public void Write(StringWriter writer) { - // TODO: hit with an extension method for 3.5 writer.WriteLine("Error: " + Code); if (Instance != null) writer.WriteLine(Instance.ToString()); writer.WriteLine("Source: " + Source); Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-06-15 01:49:31 UTC (rev 121) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-06-15 14:28:14 UTC (rev 122) @@ -148,7 +148,6 @@ private void discoverImplicitInstances() { - // TODO: Apply some 3.5 lambda magic. Maybe move to PluginCollection List<Plugin> list = _plugins.FindAutoFillablePlugins(); list.RemoveAll( plugin => _instances.Exists(instance => instance.Matches(plugin))); Modified: trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs 2008-06-15 01:49:31 UTC (rev 121) +++ trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs 2008-06-15 14:28:14 UTC (rev 122) @@ -131,14 +131,6 @@ }); } - // TODO: Decide if this is important or not - //[Test] - //public void Log_error_156_if_Include_node_does_not_have_a_File() - //{ - // DataMother.WriteDocument("MissingInclude.xml", "<StructureMap><Include></Include></StructureMap>"); - // assertErrorIsLogged(156, () => builder.IncludeFile("MissingInclude.xml")); - //} - [Test, Explicit] public void Log_exception_100_if_StructureMap_config_is_required_and_missing() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-06-16 02:12:57
|
Revision: 123 http://structuremap.svn.sourceforge.net/structuremap/?rev=123&view=rev Author: jeremydmiller Date: 2008-06-15 19:12:53 -0700 (Sun, 15 Jun 2008) Log Message: ----------- adding the ability to define IDictionary<T, U>, NameValueCollection, and primitive array arguments in the xml configuration Modified Paths: -------------- trunk/Source/StructureMap/Configuration/XmlExtensions.cs trunk/Source/StructureMap/Diagnostics/Error.cs trunk/Source/StructureMap/Graph/TypeRules.cs trunk/Source/StructureMap/InstanceMemento.cs trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs trunk/Source/StructureMap/Source/XmlAttributeInstanceMemento.cs trunk/Source/StructureMap/Source/XmlNodeInstanceMemento.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing/TestData/DataMother.cs Added Paths: ----------- trunk/Source/StructureMap/Configuration/DictionaryReader.cs trunk/Source/StructureMap/Configuration/ITypeReader.cs trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs trunk/Source/StructureMap/Configuration/TypeReaderFactory.cs trunk/Source/StructureMap.Testing/Configuration/DictionaryAndArrayArgumentTester.cs trunk/Source/StructureMap.Testing/Configuration/DictionaryReaderTester.cs trunk/Source/StructureMap.Testing/Configuration/PrimitiveArrayReaderTester.cs Added: trunk/Source/StructureMap/Configuration/DictionaryReader.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DictionaryReader.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DictionaryReader.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Xml; +using StructureMap.Pipeline; + +namespace StructureMap.Configuration +{ + public class DictionaryReader : ITypeReader + { + public bool CanProcess(Type pluginType) + { + if (pluginType.Equals(typeof(NameValueCollection))) return true; + if (!pluginType.IsGenericType) return false; + + var definition = pluginType.GetGenericTypeDefinition(); + if (definition == null) return false; + + return definition.Equals(typeof (IDictionary<,>)) || definition.Equals(typeof (Dictionary<,>)); + } + + private static IBuilder findBuilder(Type pluginType) + { + if (pluginType.Equals(typeof(NameValueCollection))) return new NameValueCollectionBuilder(); + + var definition = pluginType.GetGenericTypeDefinition(); + if (definition.Equals(typeof(IDictionary<,>)) || definition.Equals(typeof(Dictionary<,>))) + { + var arguments = pluginType.GetGenericArguments(); + var builderType = typeof (DictionaryBuilder<,>).MakeGenericType(arguments); + return (IBuilder) Activator.CreateInstance(builderType); + } + + return null; + } + + public Instance Read(XmlNode node, Type pluginType) + { + var builder = findBuilder(pluginType); + node.ForEachChild("Pair").Do(element => builder.Read(element.GetAttribute("Key"), element.GetAttribute("Value"))); + + return new SerializedInstance(builder.Object); + } + + + + + + + + + internal interface IBuilder + { + void Read(string name, string value); + object Object { get; } + } + + internal class NameValueCollectionBuilder : IBuilder + { + private readonly NameValueCollection _collection = new NameValueCollection(); + + public void Read(string name, string value) + { + _collection.Add(name, value); + } + + public object Object + { + get { return _collection; } + } + } + + internal class DictionaryBuilder<KEY, VALUE> : IBuilder + { + private Dictionary<KEY, VALUE> _dictionary = new Dictionary<KEY, VALUE>(); + + public void Read(string name, string value) + { + KEY key = (KEY) Convert.ChangeType(name, typeof (KEY)); + VALUE theValue = (VALUE) Convert.ChangeType(value, typeof (VALUE)); + + _dictionary.Add(key, theValue); + } + + public object Object + { + get { return _dictionary; } + } + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Configuration/ITypeReader.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ITypeReader.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/ITypeReader.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -0,0 +1,14 @@ +using System; +using System.Linq; +using System.Text; +using System.Xml; +using StructureMap.Pipeline; + +namespace StructureMap.Configuration +{ + public interface ITypeReader + { + bool CanProcess(Type pluginType); + Instance Read(XmlNode node, Type pluginType); + } +} Added: trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs =================================================================== --- trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -0,0 +1,38 @@ +using System; +using System.Xml; +using StructureMap.Graph; +using StructureMap.Pipeline; + +namespace StructureMap.Configuration +{ + public class PrimitiveArrayReader : TypeRules, ITypeReader + { + #region ITypeReader Members + + public bool CanProcess(Type pluginType) + { + return IsPrimitiveArray(pluginType); + } + + public Instance Read(XmlNode node, Type pluginType) + { + Type elementType = pluginType.GetElementType(); + char concatenator = node.GetAttribute("Concatenator", ",").ToCharArray()[0]; + + var valueString = node.GetAttribute("Values", string.Empty); + string[] rawValues = valueString.Split(new[]{concatenator}, StringSplitOptions.RemoveEmptyEntries); + + + var array = Array.CreateInstance(elementType, rawValues.Length); + for (int i = 0; i < rawValues.Length; i++) + { + object convertedType = Convert.ChangeType(rawValues[i].Trim(), elementType); + array.SetValue(convertedType, i); + } + + return new SerializedInstance(array); + } + + #endregion + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Configuration/TypeReaderFactory.cs =================================================================== --- trunk/Source/StructureMap/Configuration/TypeReaderFactory.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/TypeReaderFactory.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; + +namespace StructureMap.Configuration +{ + public static class TypeReaderFactory + { + private static List<ITypeReader> _readers = new List<ITypeReader>(); + + static TypeReaderFactory() + { + _readers.Add(new DictionaryReader()); + _readers.Add(new PrimitiveArrayReader()); + } + + public static ITypeReader GetReader(Type pluginType) + { + foreach (var reader in _readers) + { + if (reader.CanProcess(pluginType)) + { + return reader; + } + } + + return null; + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/XmlExtensions.cs =================================================================== --- trunk/Source/StructureMap/Configuration/XmlExtensions.cs 2008-06-15 14:28:14 UTC (rev 122) +++ trunk/Source/StructureMap/Configuration/XmlExtensions.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -5,6 +5,12 @@ { public static class XmlExtensions { + public static string GetAttribute(this XmlNode node, string attributeName, string defaultValue) + { + var attribute = node.Attributes.GetNamedItem(attributeName); + return attribute == null ? defaultValue : attribute.InnerText; + } + public static XmlTextExpression ForTextInChild(this XmlNode node, string xpath) { return new XmlTextExpression(node, xpath); Modified: trunk/Source/StructureMap/Diagnostics/Error.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/Error.cs 2008-06-15 14:28:14 UTC (rev 122) +++ trunk/Source/StructureMap/Diagnostics/Error.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -8,7 +8,7 @@ { private readonly int _code; private readonly string _message; - private readonly string _stackTrace = string.Empty; + private string _stackTrace = string.Empty; public InstanceToken Instance; public string Source; @@ -27,8 +27,9 @@ public Error(int errorCode, Exception ex, params object[] args) : this(errorCode, args) { - _message += "\n\n" + ex.ToString(); - _stackTrace = ex.StackTrace; + _message += "\n\n" + ex.Message; + + writeStackTrace(ex); } @@ -36,10 +37,23 @@ { _code = exception.ErrorCode; _message = exception.Message; - _stackTrace = exception.StackTrace; + + writeStackTrace(exception); } + private void writeStackTrace(Exception exception) + { + _stackTrace = string.Empty; + Exception ex = exception; + while (ex != null) + { + _stackTrace += exception.ToString(); + _stackTrace += "\n\n"; + ex = ex.InnerException; + } + } + public int Code { get { return _code; } Modified: trunk/Source/StructureMap/Graph/TypeRules.cs =================================================================== --- trunk/Source/StructureMap/Graph/TypeRules.cs 2008-06-15 14:28:14 UTC (rev 122) +++ trunk/Source/StructureMap/Graph/TypeRules.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -77,7 +77,7 @@ protected bool IsChild(Type type) { - return !type.IsArray && !IsSimple(type); + return IsPrimitiveArray(type) || (!type.IsArray && !IsSimple(type)); } protected bool IsChildArray(Type type) @@ -85,6 +85,11 @@ return type.IsArray && !IsSimple(type.GetElementType()); } + protected bool IsPrimitiveArray(Type type) + { + return type.IsArray && IsSimple(type.GetElementType()); + } + protected bool IsConcrete(Type type) { return !type.IsInterface && !type.IsAbstract; Modified: trunk/Source/StructureMap/InstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/InstanceMemento.cs 2008-06-15 14:28:14 UTC (rev 122) +++ trunk/Source/StructureMap/InstanceMemento.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -147,6 +147,8 @@ /// <returns></returns> protected abstract string getPropertyValue(string Key); + + /// <summary> /// Returns the named child InstanceMemento /// </summary> @@ -160,6 +162,12 @@ return returnValue; } + public virtual Instance ReadChildInstance(string name, PluginGraph graph, Type childType) + { + InstanceMemento child = GetChildMemento(name); + return child == null ? null : child.ReadInstance(graph, childType); + } + /// <summary> /// Template method for implementation specific retrieval of the named property /// </summary> @@ -207,7 +215,7 @@ } catch (Exception e) { - throw new StructureMapException(260, InstanceKey, pluginType.FullName); + throw new StructureMapException(260, e, InstanceKey, pluginType.FullName); } } @@ -225,5 +233,7 @@ return new ConfiguredInstance(this, pluginGraph, pluginType); } + + } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs 2008-06-15 14:28:14 UTC (rev 122) +++ trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -81,9 +81,11 @@ private void copyChild(string name, Type childType) { - InstanceMemento child = _memento.GetChildMemento(name); + //InstanceMemento child = _memento.GetChildMemento(name); + //Instance childInstance = child == null ? new DefaultInstance() : child.ReadInstance(_pluginGraph, childType); - Instance childInstance = child == null ? new DefaultInstance() : child.ReadInstance(_pluginGraph, childType); + Instance childInstance = _memento.ReadChildInstance(name, _pluginGraph, childType) ?? new DefaultInstance(); + _instance.Child(name).Is(childInstance); } Modified: trunk/Source/StructureMap/Source/XmlAttributeInstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/Source/XmlAttributeInstanceMemento.cs 2008-06-15 14:28:14 UTC (rev 122) +++ trunk/Source/StructureMap/Source/XmlAttributeInstanceMemento.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -1,6 +1,9 @@ +using System; using System.Collections; using System.Xml; using StructureMap.Configuration; +using StructureMap.Graph; +using StructureMap.Pipeline; namespace StructureMap.Source { @@ -110,5 +113,17 @@ { return _element.OuterXml; } + + public override Instance ReadChildInstance(string name, PluginGraph graph, Type childType) + { + var reader = TypeReaderFactory.GetReader(childType); + if (reader == null) + { + return base.ReadChildInstance(name, graph, childType); + } + + XmlElement element = _element[name]; + return reader.Read(element, childType); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Source/XmlNodeInstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/Source/XmlNodeInstanceMemento.cs 2008-06-15 14:28:14 UTC (rev 122) +++ trunk/Source/StructureMap/Source/XmlNodeInstanceMemento.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Xml; using StructureMap.Configuration; +using StructureMap.Graph; +using StructureMap.Pipeline; namespace StructureMap.Source { @@ -41,6 +43,11 @@ { get { + if (!string.IsNullOrEmpty(getPluggedType())) + { + return false; + } + bool returnValue = false; string typeName = getAttribute("Type"); @@ -66,10 +73,10 @@ return getAttribute(XmlConstants.PLUGGED_TYPE); } - private XmlNode getChildNode(string Key) + private XmlElement getChildNode(string Key) { string xpath = string.Format("Property[@Name='{0}']", Key); - XmlNode nodeProperty = _innerNode.SelectSingleNode(xpath); + XmlElement nodeProperty = (XmlElement) _innerNode.SelectSingleNode(xpath); return nodeProperty; } @@ -94,6 +101,18 @@ } + public override Instance ReadChildInstance(string name, PluginGraph graph, Type childType) + { + var reader = TypeReaderFactory.GetReader(childType); + if (reader == null) + { + return base.ReadChildInstance(name, graph, childType); + } + + XmlElement element = getChildNode(name); + return reader.Read(element, childType); + } + protected override InstanceMemento getChild(string Key) { InstanceMemento returnValue = null; Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-06-15 14:28:14 UTC (rev 122) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-06-16 02:12:53 UTC (rev 123) @@ -392,6 +392,10 @@ <None Include="..\structuremap.snk"> <Link>Properties\structuremap.snk</Link> </None> + <Compile Include="Configuration\DictionaryReader.cs" /> + <Compile Include="Configuration\ITypeReader.cs" /> + <Compile Include="Configuration\PrimitiveArrayReader.cs" /> + <Compile Include="Configuration\TypeReaderFactory.cs" /> <Compile Include="Configuration\XmlExtensions.cs" /> <Compile Include="Diagnostics\Doctor.cs" /> <Compile Include="Diagnostics\DoctorReport.cs" /> Added: trunk/Source/StructureMap.Testing/Configuration/DictionaryAndArrayArgumentTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DictionaryAndArrayArgumentTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Configuration/DictionaryAndArrayArgumentTester.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -0,0 +1,138 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NUnit.Framework; +using StructureMap.Graph; +using StructureMap.Pipeline; +using StructureMap.Source; +using StructureMap.Testing.Pipeline; +using StructureMap.Testing.TestData; + +namespace StructureMap.Testing.Configuration +{ + [TestFixture] + public class DictionaryAndArrayArgumentTester + { + [Test] + public void Read_in_a_dictionary_type_from_an_attribute_normalized_memento() + { + string xml = @" +<root> + <dictionary> + <Pair Key='color' Value='red'/> + <Pair Key='state' Value='texas'/> + <Pair Key='direction' Value='north'/> + </dictionary> +</root> +"; + + var element = DataMother.BuildDocument(xml).DocumentElement; + element.SetAttribute("PluggedType", TypePath.GetAssemblyQualifiedName(typeof (ClassWithDictionary))); + + XmlAttributeInstanceMemento memento = new XmlAttributeInstanceMemento(element); + + Instance instance = memento.ReadInstance(new PluginGraph(), typeof (ClassWithDictionary)); + + + ClassWithDictionary theObject = + (ClassWithDictionary) instance.Build(typeof(ClassWithDictionary), new BuildSession(new PluginGraph())); + + + theObject.Dictionary["color"].ShouldEqual("red"); + theObject.Dictionary["state"].ShouldEqual("texas"); + theObject.Dictionary["direction"].ShouldEqual("north"); + } + + [Test] + public void Read_in_a_dictionary_type_from_a_node_normalized_memento() + { + string xml = @" +<root> + <Property Name='dictionary'> + <Pair Key='color' Value='red'/> + <Pair Key='state' Value='texas'/> + <Pair Key='direction' Value='north'/> + </Property> +</root> +"; + + var element = DataMother.BuildDocument(xml).DocumentElement; + element.SetAttribute("PluggedType", TypePath.GetAssemblyQualifiedName(typeof(ClassWithDictionary))); + + XmlNodeInstanceMemento memento = new XmlNodeInstanceMemento(element, "Type", "Key"); + + Instance instance = memento.ReadInstance(new PluginGraph(), typeof(ClassWithDictionary)); + + + ClassWithDictionary theObject = + (ClassWithDictionary)instance.Build(typeof(ClassWithDictionary), new BuildSession(new PluginGraph())); + + + theObject.Dictionary["color"].ShouldEqual("red"); + theObject.Dictionary["state"].ShouldEqual("texas"); + theObject.Dictionary["direction"].ShouldEqual("north"); + } + + [Test] + public void Read_in_a_class_with_primitive_arrays() + { + string xml = @" +<root> + <numbers Values='1,2,3'/> + <strings Values='1,2,3'/> +</root> +"; + + var element = DataMother.BuildDocument(xml).DocumentElement; + element.SetAttribute("PluggedType", TypePath.GetAssemblyQualifiedName(typeof(ClassWithStringAndIntArray))); + + XmlAttributeInstanceMemento memento = new XmlAttributeInstanceMemento(element); + PluginGraph graph = new PluginGraph(); + Instance instance = memento.ReadInstance(graph, typeof(ClassWithStringAndIntArray)); + + ClassWithStringAndIntArray theObject = (ClassWithStringAndIntArray) instance.Build(typeof (ClassWithStringAndIntArray), + new BuildSession(graph)); + + theObject.Numbers.ShouldEqual(new int[] {1, 2, 3}); + theObject.Strings.ShouldEqual(new string[] {"1", "2", "3"}); + } + } + + public class ClassWithStringAndIntArray + { + private int[] _numbers; + private string[] _strings; + + public ClassWithStringAndIntArray(int[] numbers, string[] strings) + { + _numbers = numbers; + _strings = strings; + } + + public int[] Numbers + { + get { return _numbers; } + } + + public string[] Strings + { + get { return _strings; } + } + } + + public class ClassWithDictionary + { + private readonly IDictionary<string, string> _dictionary; + + public ClassWithDictionary(IDictionary<string, string> dictionary) + { + _dictionary = dictionary; + } + + public IDictionary<string, string> Dictionary + { + get { return _dictionary; } + } + } +} Added: trunk/Source/StructureMap.Testing/Configuration/DictionaryReaderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DictionaryReaderTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Configuration/DictionaryReaderTester.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -0,0 +1,154 @@ +using System.Collections.Generic; +using System.Collections.Specialized; +using NUnit.Framework; +using StructureMap.Configuration; +using StructureMap.Pipeline; +using StructureMap.Testing.Pipeline; +using StructureMap.Testing.TestData; + +namespace StructureMap.Testing.Configuration +{ + [TestFixture] + public class DictionaryReaderTester + { + [Test] + public void Can_process_a_dictionary() + { + var reader = new DictionaryReader(); + reader.CanProcess(typeof (IDictionary<string, string>)).ShouldBeTrue(); + reader.CanProcess(typeof (IDictionary<int, string>)).ShouldBeTrue(); + reader.CanProcess(typeof (IDictionary<string, int>)).ShouldBeTrue(); + reader.CanProcess(typeof (Dictionary<string, string>)).ShouldBeTrue(); + reader.CanProcess(typeof (Dictionary<int, string>)).ShouldBeTrue(); + reader.CanProcess(typeof (Dictionary<string, int>)).ShouldBeTrue(); + } + + [Test] + public void Can_process_NameValueCollection() + { + new DictionaryReader().CanProcess(typeof (NameValueCollection)).ShouldBeTrue(); + } + + [Test] + public void Read_a_string_int_dictionary2() + { + string xml = + @" +<node> + <Pair Key='color' Value='1'/> + <Pair Key='state' Value='2'/> + <Pair Key='direction' Value='3'/> +</node> +"; + + Instance instance = new DictionaryReader().Read(DataMother.BuildDocument(xml).DocumentElement, + typeof (Dictionary<string, int>)); + instance.ShouldBeOfType(typeof (SerializedInstance)); + + var collection = + (Dictionary<string, int>) instance.Build(typeof (Dictionary<string, int>), new StubBuildSession()); + + collection["color"].ShouldEqual(1); + collection["state"].ShouldEqual(2); + collection["direction"].ShouldEqual(3); + } + + [Test] + public void Read_a_string_string_dictionary() + { + string xml = + @" +<node> + <Pair Key='color' Value='red'/> + <Pair Key='state' Value='texas'/> + <Pair Key='direction' Value='north'/> +</node> +"; + + Instance instance = new DictionaryReader().Read(DataMother.BuildDocument(xml).DocumentElement, + typeof (IDictionary<string, string>)); + instance.ShouldBeOfType(typeof (SerializedInstance)); + + var collection = + (IDictionary<string, string>) + instance.Build(typeof (IDictionary<string, string>), new StubBuildSession()); + + collection["color"].ShouldEqual("red"); + collection["state"].ShouldEqual("texas"); + collection["direction"].ShouldEqual("north"); + } + + + [Test] + public void Read_a_string_string_dictionary2() + { + string xml = + @" +<node> + <Pair Key='color' Value='red'/> + <Pair Key='state' Value='texas'/> + <Pair Key='direction' Value='north'/> +</node> +"; + + Instance instance = new DictionaryReader().Read(DataMother.BuildDocument(xml).DocumentElement, + typeof (Dictionary<string, string>)); + instance.ShouldBeOfType(typeof (SerializedInstance)); + + var collection = + (Dictionary<string, string>) instance.Build(typeof (Dictionary<string, string>), new StubBuildSession()); + + collection["color"].ShouldEqual("red"); + collection["state"].ShouldEqual("texas"); + collection["direction"].ShouldEqual("north"); + } + + [Test] + public void Read_an_instance_for_NameValueCollection() + { + string xml = + @" +<node> + <Pair Key='color' Value='red'/> + <Pair Key='state' Value='texas'/> + <Pair Key='direction' Value='north'/> +</node> +"; + + Instance instance = new DictionaryReader().Read(DataMother.BuildDocument(xml).DocumentElement, + typeof (NameValueCollection)); + instance.ShouldBeOfType(typeof (SerializedInstance)); + + var collection = (NameValueCollection) instance.Build(typeof (NameValueCollection), new StubBuildSession()); + + collection["color"].ShouldEqual("red"); + collection["state"].ShouldEqual("texas"); + collection["direction"].ShouldEqual("north"); + } + + + [Test] + public void Read_an_int_string_dictionary() + { + string xml = + @" +<node> + <Pair Key='1' Value='red'/> + <Pair Key='2' Value='texas'/> + <Pair Key='3' Value='north'/> +</node> +"; + + Instance instance = new DictionaryReader().Read(DataMother.BuildDocument(xml).DocumentElement, + typeof (IDictionary<int, string>)); + instance.ShouldBeOfType(typeof (SerializedInstance)); + + var collection = + (IDictionary<int, string>) instance.Build(typeof (IDictionary<int, string>), new StubBuildSession()); + + collection[1].ShouldEqual("red"); + collection[2].ShouldEqual("texas"); + collection[3].ShouldEqual("north"); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Configuration/PrimitiveArrayReaderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/PrimitiveArrayReaderTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Configuration/PrimitiveArrayReaderTester.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Xml; +using NUnit.Framework; +using StructureMap.Configuration; +using StructureMap.Pipeline; +using StructureMap.Testing.Pipeline; +using StructureMap.Testing.TestData; +using StructureMap.Testing.Widget; + +namespace StructureMap.Testing.Configuration +{ + [TestFixture] + public class PrimitiveeArrayReaderTester + { + [Test] + public void CanProcess_an_array_of_primitive_types() + { + PrimitiveArrayReader reader = new PrimitiveArrayReader(); + + reader.CanProcess(typeof(string)).ShouldBeFalse(); + reader.CanProcess(typeof(IWidget[])).ShouldBeFalse(); + + reader.CanProcess(typeof(string[])).ShouldBeTrue(); + reader.CanProcess(typeof(int[])).ShouldBeTrue(); + reader.CanProcess(typeof(double[])).ShouldBeTrue(); + } + + private object parseNode(string xml, Type pluginType) + { + XmlElement element = DataMother.BuildDocument(xml).DocumentElement; + PrimitiveArrayReader reader = new PrimitiveArrayReader(); + Instance instance = reader.Read(element, pluginType); + + return instance.Build(pluginType, new StubBuildSession()); + } + + [Test] + public void Parse_a_string_array_with_the_default_concatenator() + { + parseNode("<node Values='a,b,c,d'></node>", typeof (string[])).ShouldEqual(new string[] {"a", "b", "c", "d"}); + } + + + [Test] + public void Parse_a_string_array_with_overridden_concatenator() + { + parseNode("<node Values='a,b,c,d' Concatenator=';'></node>", typeof(string[])).ShouldEqual(new string[] { "a,b,c,d" }); + parseNode("<node Values='a;b;c;d' Concatenator=';'></node>", typeof(string[])).ShouldEqual(new string[] { "a", "b", "c", "d" }); + } + + + [Test] + public void Parse_a_string_array_with_the_default_concatenator_and_deal_with_leading_or_trailing_spaces() + { + parseNode("<node Values='a , b,c,d'></node>", typeof(string[])).ShouldEqual(new string[] { "a", "b", "c", "d" }); + } + + + [Test] + public void Parse_an_int_array_with_the_default_concatenator() + { + parseNode("<node Values='1,2,3,4'></node>", typeof(int[])).ShouldEqual(new int[] { 1, 2, 3, 4 }); + } + } +} Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-06-15 14:28:14 UTC (rev 122) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-06-16 02:12:53 UTC (rev 123) @@ -180,6 +180,8 @@ <Compile Include="Configuration\ConfigurationParserBuilderTester.cs" /> <Compile Include="Configuration\ConfigurationParserTester.cs" /> <Compile Include="Configuration\DefaultInstanceNodeTester.cs" /> + <Compile Include="Configuration\DictionaryAndArrayArgumentTester.cs" /> + <Compile Include="Configuration\DictionaryReaderTester.cs" /> <Compile Include="Configuration\DSL\AddInstanceTester.cs" /> <Compile Include="Configuration\DSL\AddTypesTester.cs" /> <Compile Include="Configuration\DSL\ConstructorExpressionTester.cs" /> @@ -203,6 +205,7 @@ </Compile> <Compile Include="Configuration\InlineInstanceDefinitionInProfileAndMachineNodesTester.cs" /> <Compile Include="Configuration\NormalGraphBuilderTester.cs" /> + <Compile Include="Configuration\PrimitiveArrayReaderTester.cs" /> <Compile Include="Configuration\ProfileBuilderTester.cs" /> <Compile Include="Configuration\ShortcuttedInstanceNodeTester.cs" /> <Compile Include="Diagnostics\DoctorTester.cs" /> Modified: trunk/Source/StructureMap.Testing/TestData/DataMother.cs =================================================================== --- trunk/Source/StructureMap.Testing/TestData/DataMother.cs 2008-06-15 14:28:14 UTC (rev 122) +++ trunk/Source/StructureMap.Testing/TestData/DataMother.cs 2008-06-16 02:12:53 UTC (rev 123) @@ -19,16 +19,22 @@ public static PluginGraph BuildPluginGraphFromXml(string xml) { - xml = xml.Replace("'", "\""); - XmlDocument document = new XmlDocument(); - document.LoadXml(xml); + XmlDocument document = BuildDocument(xml); ConfigurationParser parser = new ConfigurationParser(document.DocumentElement); PluginGraphBuilder builder = new PluginGraphBuilder(parser); return builder.Build(); } + public static XmlDocument BuildDocument(string xml) + { + xml = xml.Replace("'", "\""); + XmlDocument document = new XmlDocument(); + document.LoadXml(xml); + return document; + } + public static void BackupStructureMapConfig() { if (File.Exists("StructureMap.config.bak")) File.Delete("StructureMap.config.bak"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |