From: <jer...@us...> - 2008-04-06 23:53:50
|
Revision: 75 http://structuremap.svn.sourceforge.net/structuremap/?rev=75&view=rev Author: jeremydmiller Date: 2008-04-06 16:53:49 -0700 (Sun, 06 Apr 2008) Log Message: ----------- refactoring the new Instance's to use a Type instead of a generic. Alas, it is not a perfect world Modified Paths: -------------- 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/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 Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -11,19 +11,9 @@ public class ConfiguredInstance : Instance { - protected override T build<T>(IInstanceCreator creator) + protected override object build(Type type, 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(); - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/DefaultInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/DefaultInstance.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap/Pipeline/DefaultInstance.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -6,19 +6,9 @@ { public class DefaultInstance : Instance { - protected override T build<T>(IInstanceCreator creator) + protected override object build(Type type, IInstanceCreator creator) { - return creator.CreateInstance<T>(); + return creator.CreateInstance(type); } - - public override void Diagnose<T>(IInstanceCreator creator, IInstanceDiagnostics diagnostics) - { - throw new NotImplementedException(); - } - - public override void Describe<T>(IInstanceDiagnostics diagnostics) - { - throw new NotImplementedException(); - } } } Modified: trunk/Source/StructureMap/Pipeline/Instance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Instance.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap/Pipeline/Instance.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -7,11 +7,11 @@ { public interface IInstanceCreator { - T CreateInstance<T>(string referenceKey); - T CreateInstance<T>(); + object CreateInstance(Type type, string referenceKey); Array CreateInstanceArray(string pluginType, InstanceMemento[] instanceMementoes); object CreateInstance(string typeName, InstanceMemento memento); object CreateInstance(string typeName); + object CreateInstance(Type type); } public interface IInstanceDiagnostics @@ -35,15 +35,15 @@ set { _interceptor = value; } } - public T Build<T>(IInstanceCreator creator) where T : class + public object Build(Type type, IInstanceCreator creator) { - T rawValue = build<T>(creator); - return (T) _interceptor.Process(rawValue); + object rawValue = build(type, creator); + return _interceptor.Process(rawValue); } - protected abstract T build<T>(IInstanceCreator creator) where T : class; + protected abstract object build(Type type, IInstanceCreator creator); - public abstract void Diagnose<T>(IInstanceCreator creator, IInstanceDiagnostics diagnostics) where T : class; - public abstract void Describe<T>(IInstanceDiagnostics diagnostics) 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 Modified: trunk/Source/StructureMap/Pipeline/LiteralInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/LiteralInstance.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap/Pipeline/LiteralInstance.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -4,7 +4,7 @@ { public class LiteralInstance<PLUGINTYPE> : Instance { - private PLUGINTYPE _object; + private readonly PLUGINTYPE _object; public LiteralInstance(PLUGINTYPE anObject) { @@ -13,22 +13,12 @@ // TODO: VALIDATE NOT NULL } - protected override T build<T>(IInstanceCreator creator) + + protected override object build(Type type, IInstanceCreator creator) { - T returnValue = _object as T; // TODO: VALIDATE THE CAST AND NULL - return returnValue; + return _object; } - - 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/Pipeline/PrototypeInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -13,20 +13,10 @@ } - protected override T build<T>(IInstanceCreator creator) + protected override object build(Type type, IInstanceCreator creator) { // TODO: VALIDATION IF IT CAN'T BE CAST - return (T) _prototype.Clone(); + return _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 Modified: trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -13,19 +13,10 @@ _referenceKey = referenceKey; } - protected override T build<T>(IInstanceCreator creator) - { - return creator.CreateInstance<T>(_referenceKey); - } - public override void Diagnose<T>(IInstanceCreator creator, IInstanceDiagnostics diagnostics) + protected override object build(Type type, IInstanceCreator creator) { - throw new NotImplementedException(); + return creator.CreateInstance(type, _referenceKey); } - - public override void Describe<T>(IInstanceDiagnostics diagnostics) - { - throw new NotImplementedException(); - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/UserControlInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/UserControlInstance.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap/Pipeline/UserControlInstance.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -12,20 +12,11 @@ _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) + protected override object build(Type type, IInstanceCreator creator) { - throw new NotImplementedException(); + // TODO: VALIDATE that the type works + return new Page().LoadControl(_url); } - - public override void Describe<T>(IInstanceDiagnostics diagnostics) - { - throw new NotImplementedException(); - } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Pipeline/DefaultInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/DefaultInstanceTester.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap.Testing/Pipeline/DefaultInstanceTester.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -28,13 +28,13 @@ using (mocks.Record()) { - Expect.Call(instanceCreator.CreateInstance<IDefault>()).Return(theDefault); + Expect.Call(instanceCreator.CreateInstance(typeof(IDefault))).Return(theDefault); } using (mocks.Playback()) { DefaultInstance instance = new DefaultInstance(); - Assert.AreSame(theDefault, instance.Build<IDefault>(instanceCreator)); + Assert.AreSame(theDefault, instance.Build(typeof(IDefault), instanceCreator)); } } Modified: trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -1,3 +1,4 @@ +using System; using NUnit.Framework; using Rhino.Mocks; using StructureMap.Interceptors; @@ -33,7 +34,7 @@ using (mocks.Playback()) { - Assert.AreEqual(objectReturnedByInterceptor, instanceUnderTest.Build<object>(null)); + Assert.AreEqual(objectReturnedByInterceptor, instanceUnderTest.Build(typeof(object), null)); } } @@ -44,19 +45,10 @@ { 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) + protected override object build(Type type, StructureMap.Pipeline.IInstanceCreator creator) { - throw new System.NotImplementedException(); + return TheInstanceThatWasBuilt; } - - protected override T build<T>(StructureMap.Pipeline.IInstanceCreator creator) - { - return (T) TheInstanceThatWasBuilt; - } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Pipeline/LiteralInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/LiteralInstanceTester.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap.Testing/Pipeline/LiteralInstanceTester.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -17,7 +17,7 @@ { ATarget target = new ATarget(); LiteralInstance<ITarget> instance = new LiteralInstance<ITarget>(target); - Assert.AreSame(target, instance.Build<ITarget>(null)); + Assert.AreSame(target, instance.Build(typeof(ITarget), null)); } public interface ITarget Modified: trunk/Source/StructureMap.Testing/Pipeline/PrototypeInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/PrototypeInstanceTester.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap.Testing/Pipeline/PrototypeInstanceTester.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -19,7 +19,7 @@ PrototypeTarget target = new PrototypeTarget("Jeremy"); PrototypeInstance instance = new PrototypeInstance(target); - object returnedValue = instance.Build<PrototypeTarget>(null); + object returnedValue = instance.Build(typeof(PrototypeTarget), null); Assert.AreEqual(target, returnedValue); Assert.AreNotSame(target, returnedValue); Modified: trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -24,12 +24,12 @@ using (mocks.Record()) { - Expect.Call(instanceCreator.CreateInstance<IReferenced>(theReferenceKey)).Return(returnedValue); + Expect.Call(instanceCreator.CreateInstance(typeof(IReferenced), theReferenceKey)).Return(returnedValue); } using (mocks.Playback()) { - Assert.AreSame(returnedValue, instance.Build<IReferenced>(instanceCreator)); + Assert.AreSame(returnedValue, instance.Build(typeof(IReferenced), instanceCreator)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |