From: <jer...@us...> - 2008-04-06 18:45:52
|
Revision: 71 http://structuremap.svn.sourceforge.net/structuremap/?rev=71&view=rev Author: jeremydmiller Date: 2008-04-06 11:45:47 -0700 (Sun, 06 Apr 2008) Log Message: ----------- start of the new Pipeline Modified Paths: -------------- trunk/Source/StructureMap/StructureMap.csproj 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/Pipeline/ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs trunk/Source/StructureMap/Pipeline/DefaultInstance.cs trunk/Source/StructureMap/Pipeline/Instance.cs trunk/Source/StructureMap/Pipeline/LiteralInstance.cs trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs trunk/Source/StructureMap/Pipeline/UserControlInstance.cs trunk/Source/StructureMap.Testing/Pipeline/ trunk/Source/StructureMap.Testing/Pipeline/DefaultInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/LiteralInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/PrototypeInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs Property Changed: ---------------- trunk/Source/ Property changes on: trunk/Source ___________________________________________________________________ Name: svn:ignore - *.suo _ReSharper.StructureMap PrecompiledWeb *.resharper *.user + *.suo _ReSharper.StructureMap PrecompiledWeb *.resharper *.user Ankh.Load _UpgradeReport_Files UpgradeLog.XML UpgradeLog2.XML UpgradeLog3.XML UpgradeLog4.XML Added: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-04-06 18:45:47 UTC (rev 71) @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace StructureMap.Pipeline +{ + public interface IConfiguredInstance + { + + } + + public class ConfiguredInstance : Instance + { + + + protected override T build<T>(IInstanceCreator creator) + { + throw new NotImplementedException(); + } + + public override void Diagnose<T>(IInstanceCreator creator, IInstanceDiagnostics diagnostics) + { + throw new NotImplementedException(); + } + + public override void Describe<T>(IInstanceDiagnostics diagnostics) + { + throw new NotImplementedException(); + } + } +} Added: trunk/Source/StructureMap/Pipeline/DefaultInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/DefaultInstance.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/DefaultInstance.cs 2008-04-06 18:45:47 UTC (rev 71) @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace StructureMap.Pipeline +{ + public class DefaultInstance : Instance + { + protected override T build<T>(IInstanceCreator creator) + { + return creator.CreateInstance<T>(); + } + + public override void Diagnose<T>(IInstanceCreator creator, IInstanceDiagnostics diagnostics) + { + throw new NotImplementedException(); + } + + public override void Describe<T>(IInstanceDiagnostics diagnostics) + { + throw new NotImplementedException(); + } + } +} Added: trunk/Source/StructureMap/Pipeline/Instance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Instance.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/Instance.cs 2008-04-06 18:45:47 UTC (rev 71) @@ -0,0 +1,45 @@ +using System; +using System.Web.UI; +using StructureMap.Interceptors; + +namespace StructureMap.Pipeline +{ + public interface IInstanceCreator + { + T CreateInstance<T>(string referenceKey); + T CreateInstance<T>(); + } + + public interface IInstanceDiagnostics + { + } + + public abstract class Instance + { + private string _name; + private InstanceInterceptor _interceptor = new NulloInterceptor(); + + public string Name + { + get { return _name; } + set { _name = value; } + } + + public InstanceInterceptor Interceptor + { + get { return _interceptor; } + set { _interceptor = value; } + } + + public T Build<T>(IInstanceCreator creator) where T : class + { + T rawValue = build<T>(creator); + return (T) _interceptor.Process(rawValue); + } + + protected abstract T build<T>(IInstanceCreator creator) where T : class; + + public abstract void Diagnose<T>(IInstanceCreator creator, IInstanceDiagnostics diagnostics) where T : class; + public abstract void Describe<T>(IInstanceDiagnostics diagnostics) where T : class; + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Pipeline/LiteralInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/LiteralInstance.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/LiteralInstance.cs 2008-04-06 18:45:47 UTC (rev 71) @@ -0,0 +1,34 @@ +using System; + +namespace StructureMap.Pipeline +{ + public class LiteralInstance<PLUGINTYPE> : Instance + { + private PLUGINTYPE _object; + + public LiteralInstance(PLUGINTYPE anObject) + { + _object = anObject; + + // TODO: VALIDATE NOT NULL + } + + protected override T build<T>(IInstanceCreator creator) + { + T returnValue = _object as T; + // TODO: VALIDATE THE CAST AND NULL + + return returnValue; + } + + public override void Diagnose<T>(IInstanceCreator creator, IInstanceDiagnostics diagnostics) + { + throw new NotImplementedException(); + } + + public override void Describe<T>(IInstanceDiagnostics diagnostics) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs 2008-04-06 18:45:47 UTC (rev 71) @@ -0,0 +1,32 @@ +using System; + +namespace StructureMap.Pipeline +{ + public class PrototypeInstance : Instance + { + private ICloneable _prototype; + + + public PrototypeInstance(ICloneable prototype) + { + _prototype = prototype; + } + + + protected override T build<T>(IInstanceCreator creator) + { + // TODO: VALIDATION IF IT CAN'T BE CAST + return (T) _prototype.Clone(); + } + + public override void Diagnose<T>(IInstanceCreator creator, IInstanceDiagnostics diagnostics) + { + throw new NotImplementedException(); + } + + public override void Describe<T>(IInstanceDiagnostics diagnostics) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs 2008-04-06 18:45:47 UTC (rev 71) @@ -0,0 +1,31 @@ +using System; + +namespace StructureMap.Pipeline +{ + public class ReferencedInstance : Instance + { + private readonly string _referenceKey; + + + public ReferencedInstance(string referenceKey) + { + // TODO: VALIDATION if referenceKey is null or empty + _referenceKey = referenceKey; + } + + protected override T build<T>(IInstanceCreator creator) + { + return creator.CreateInstance<T>(_referenceKey); + } + + public override void Diagnose<T>(IInstanceCreator creator, IInstanceDiagnostics diagnostics) + { + throw new NotImplementedException(); + } + + public override void Describe<T>(IInstanceDiagnostics diagnostics) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Pipeline/UserControlInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/UserControlInstance.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/UserControlInstance.cs 2008-04-06 18:45:47 UTC (rev 71) @@ -0,0 +1,31 @@ +using System; +using System.Web.UI; + +namespace StructureMap.Pipeline +{ + public class UserControlInstance : Instance + { + private readonly string _url; + + public UserControlInstance(string url) + { + _url = url; + } + + protected override T build<T>(IInstanceCreator creator) + { + // TODO: VALIDATION if it doesn't cast or can't be built + return new Page().LoadControl(_url) as T; + } + + public override void Diagnose<T>(IInstanceCreator creator, IInstanceDiagnostics diagnostics) + { + throw new NotImplementedException(); + } + + public override void Describe<T>(IInstanceDiagnostics diagnostics) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-04-06 16:26:03 UTC (rev 70) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-04-06 18:45:47 UTC (rev 71) @@ -115,6 +115,13 @@ <Link>CommonAssemblyInfo.cs</Link> <SubType>Code</SubType> </Compile> + <Compile Include="Pipeline\ConfiguredInstance.cs" /> + <Compile Include="Pipeline\DefaultInstance.cs" /> + <Compile Include="Pipeline\Instance.cs" /> + <Compile Include="Pipeline\LiteralInstance.cs" /> + <Compile Include="Pipeline\PrototypeInstance.cs" /> + <Compile Include="Pipeline\ReferencedInstance.cs" /> + <Compile Include="Pipeline\UserControlInstance.cs" /> <Compile Include="Properties\AssemblyInfo.cs"> <SubType>Code</SubType> </Compile> Added: trunk/Source/StructureMap.Testing/Pipeline/DefaultInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/DefaultInstanceTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Pipeline/DefaultInstanceTester.cs 2008-04-06 18:45:47 UTC (rev 71) @@ -0,0 +1,44 @@ +using NUnit.Framework; +using Rhino.Mocks; +using StructureMap.Pipeline; + +namespace StructureMap.Testing.Pipeline +{ + [TestFixture] + public class DefaultInstanceTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + } + + #endregion + + [Test] + public void Build_happy_path() + { + MockRepository mocks = new MockRepository(); + StructureMap.Pipeline.IInstanceCreator instanceCreator = + mocks.CreateMock<StructureMap.Pipeline.IInstanceCreator>(); + + DefaultClass theDefault = new DefaultClass(); + + + using (mocks.Record()) + { + Expect.Call(instanceCreator.CreateInstance<IDefault>()).Return(theDefault); + } + + using (mocks.Playback()) + { + DefaultInstance instance = new DefaultInstance(); + Assert.AreSame(theDefault, instance.Build<IDefault>(instanceCreator)); + } + } + + public interface IDefault {} + public class DefaultClass : IDefault {} + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs 2008-04-06 18:45:47 UTC (rev 71) @@ -0,0 +1,62 @@ +using NUnit.Framework; +using Rhino.Mocks; +using StructureMap.Interceptors; +using StructureMap.Pipeline; +using StructureMap.Testing.Container.Interceptors; + +namespace StructureMap.Testing.Pipeline +{ + [TestFixture] + public class InstanceTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + } + + [Test] + public void Instance_Build_Calls_into_its_Interceptor() + { + MockRepository mocks = new MockRepository(); + InstanceInterceptor interceptor = mocks.CreateMock<InstanceInterceptor>(); + + InstanceUnderTest instanceUnderTest = new InstanceUnderTest(); + instanceUnderTest.Interceptor = interceptor; + + object objectReturnedByInterceptor = new object(); + using (mocks.Record()) + { + Expect.Call(interceptor.Process(instanceUnderTest.TheInstanceThatWasBuilt)).Return(objectReturnedByInterceptor); + } + + using (mocks.Playback()) + { + Assert.AreEqual(objectReturnedByInterceptor, instanceUnderTest.Build<object>(null)); + } + } + + #endregion + } + + public class InstanceUnderTest : Instance + { + public object TheInstanceThatWasBuilt = new object(); + + public override void Diagnose<T>(StructureMap.Pipeline.IInstanceCreator creator, IInstanceDiagnostics diagnostics) + { + throw new System.NotImplementedException(); + } + + public override void Describe<T>(IInstanceDiagnostics diagnostics) + { + throw new System.NotImplementedException(); + } + + protected override T build<T>(StructureMap.Pipeline.IInstanceCreator creator) + { + return (T) TheInstanceThatWasBuilt; + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Pipeline/LiteralInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/LiteralInstanceTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Pipeline/LiteralInstanceTester.cs 2008-04-06 18:45:47 UTC (rev 71) @@ -0,0 +1,36 @@ +using NUnit.Framework; +using Rhino.Mocks; +using StructureMap.Pipeline; + +namespace StructureMap.Testing.Pipeline +{ + [TestFixture] + public class LiteralInstanceTester + { + [SetUp] + public void SetUp() + { + } + + [Test] + public void Build_happy_path() + { + ATarget target = new ATarget(); + LiteralInstance<ITarget> instance = new LiteralInstance<ITarget>(target); + Assert.AreSame(target, instance.Build<ITarget>(null)); + } + + public interface ITarget + { + + } + + public class ATarget : ITarget + { + public override string ToString() + { + return "the description of ATarget"; + } + } + } +} Added: trunk/Source/StructureMap.Testing/Pipeline/PrototypeInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/PrototypeInstanceTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Pipeline/PrototypeInstanceTester.cs 2008-04-06 18:45:47 UTC (rev 71) @@ -0,0 +1,68 @@ +using System; +using NUnit.Framework; +using Rhino.Mocks; +using StructureMap.Pipeline; + +namespace StructureMap.Testing.Pipeline +{ + [TestFixture] + public class PrototypeInstanceTester + { + [SetUp] + public void SetUp() + { + } + + [Test] + public void Build_a_clone() + { + PrototypeTarget target = new PrototypeTarget("Jeremy"); + PrototypeInstance instance = new PrototypeInstance(target); + + object returnedValue = instance.Build<PrototypeTarget>(null); + + Assert.AreEqual(target, returnedValue); + Assert.AreNotSame(target, returnedValue); + } + + public class PrototypeTarget : ICloneable, IEquatable<PrototypeTarget> + { + private string _name; + + + public PrototypeTarget(string name) + { + _name = name; + } + + public string Name + { + get { return _name; } + set { _name = value; } + } + + + public bool Equals(PrototypeTarget prototypeTarget) + { + if (prototypeTarget == null) return false; + return Equals(_name, prototypeTarget._name); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(this, obj)) return true; + return Equals(obj as PrototypeTarget); + } + + public override int GetHashCode() + { + return _name != null ? _name.GetHashCode() : 0; + } + + public object Clone() + { + return this.MemberwiseClone(); + } + } + } +} Added: trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs 2008-04-06 18:45:47 UTC (rev 71) @@ -0,0 +1,43 @@ +using NUnit.Framework; +using Rhino.Mocks; +using StructureMap.Pipeline; + +namespace StructureMap.Testing.Pipeline +{ + [TestFixture] + public class ReferencedInstanceTester + { + [SetUp] + public void SetUp() + { + } + + [Test] + public void Create_referenced_instance_happy_path() + { + MockRepository mocks = new MockRepository(); + StructureMap.Pipeline.IInstanceCreator instanceCreator = mocks.CreateMock<StructureMap.Pipeline.IInstanceCreator>(); + + ConcreteReferenced returnedValue = new ConcreteReferenced(); + string theReferenceKey = "theReferenceKey"; + ReferencedInstance instance = new ReferencedInstance(theReferenceKey); + + using (mocks.Record()) + { + Expect.Call(instanceCreator.CreateInstance<IReferenced>(theReferenceKey)).Return(returnedValue); + } + + using (mocks.Playback()) + { + Assert.AreSame(returnedValue, instance.Build<IReferenced>(instanceCreator)); + } + } + + public interface IReferenced + { + + } + + public class ConcreteReferenced : IReferenced{} + } +} Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-04-06 16:26:03 UTC (rev 70) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-04-06 18:45:47 UTC (rev 71) @@ -365,6 +365,11 @@ <Compile Include="ObjectMother.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Pipeline\DefaultInstanceTester.cs" /> + <Compile Include="Pipeline\InstanceTester.cs" /> + <Compile Include="Pipeline\LiteralInstanceTester.cs" /> + <Compile Include="Pipeline\PrototypeInstanceTester.cs" /> + <Compile Include="Pipeline\ReferencedInstanceTester.cs" /> <Compile Include="StructureMapConfigCreator.cs" /> <Compile Include="StructureMapConfigurationTester.cs" /> <Compile Include="TestData\DataMother.cs"> Modified: trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs 2008-04-06 16:26:03 UTC (rev 70) +++ trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs 2008-04-06 18:45:47 UTC (rev 71) @@ -1,3 +1,5 @@ +using StructureMap.Pipeline; + namespace StructureMap.Testing.Widget { public interface IList Modified: trunk/Source/StructureMap.Testing.Widget/Decision.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/Decision.cs 2008-04-06 16:26:03 UTC (rev 70) +++ trunk/Source/StructureMap.Testing.Widget/Decision.cs 2008-04-06 18:45:47 UTC (rev 71) @@ -1,3 +1,5 @@ +using StructureMap.Pipeline; + namespace StructureMap.Testing.Widget { public class Decision Modified: trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs 2008-04-06 16:26:03 UTC (rev 70) +++ trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs 2008-04-06 18:45:47 UTC (rev 71) @@ -1,3 +1,5 @@ +using StructureMap.Pipeline; + namespace StructureMap.Testing.Widget { [PluginFamily, Pluggable("Default", "")] @@ -106,11 +108,11 @@ } - public override object BuildInstance(InstanceMemento memento) + public override object BuildInstance(InstanceMemento instance) { return new Child( - memento.GetProperty("Name"), - (GrandChild) memento.GetChild("MyGrandChild", "StructureMap.Testing.Widget.GrandChild", Manager)); + instance.GetProperty("Name"), + (GrandChild) instance.GetChild("MyGrandChild", "StructureMap.Testing.Widget.GrandChild", Manager)); } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs 2008-04-06 16:26:03 UTC (rev 70) +++ trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs 2008-04-06 18:45:47 UTC (rev 71) @@ -1,4 +1,5 @@ using System; +using StructureMap.Pipeline; namespace StructureMap.Testing.Widget2 { @@ -44,12 +45,12 @@ } - public override object BuildInstance(InstanceMemento memento) + public override object BuildInstance(InstanceMemento instance) { return new Cow( - long.Parse(memento.GetProperty("Weight")), - (BreedEnum) Enum.Parse(typeof (BreedEnum), memento.GetProperty("Breed"), true), - memento.GetProperty("Name")); + long.Parse(instance.GetProperty("Weight")), + (BreedEnum) Enum.Parse(typeof (BreedEnum), instance.GetProperty("Breed"), true), + instance.GetProperty("Name")); } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs 2008-04-06 16:26:03 UTC (rev 70) +++ trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs 2008-04-06 18:45:47 UTC (rev 71) @@ -1,4 +1,5 @@ using System; +using StructureMap.Pipeline; using StructureMap.Testing.Widget; namespace StructureMap.Testing.Widget5 @@ -28,9 +29,9 @@ get { throw new NotImplementedException(); } } - public override object BuildInstance(InstanceMemento memento) + public override object BuildInstance(InstanceMemento instance) { - BasicGridColumn column = new BasicGridColumn(memento.GetProperty("headerText")); + BasicGridColumn column = new BasicGridColumn(instance.GetProperty("headerText")); // column.Widget = // (IWidget) Memento.GetChild("Widget", "StructureMap.Testing.Widget.IWidget", this.Manager); @@ -42,7 +43,7 @@ column.Rules = (Rule[]) - Manager.CreateInstanceArray("StructureMap.Testing.Widget.Rule", memento.GetChildrenArray("Rules")); + Manager.CreateInstanceArray("StructureMap.Testing.Widget.Rule", instance.GetChildrenArray("Rules")); // // column.WrapLines = bool.Parse(Memento.GetProperty("WrapLines")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |