From: <jer...@us...> - 2009-08-12 15:29:40
|
Revision: 256 http://structuremap.svn.sourceforge.net/structuremap/?rev=256&view=rev Author: jeremydmiller Date: 2009-08-12 15:29:30 +0000 (Wed, 12 Aug 2009) Log Message: ----------- added the Forward to functionality Modified Paths: -------------- trunk/Source/StructureMap/Attributes/PluggableAttribute.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Graph/Plugin.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/Model.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap.Testing/Debugging.cs trunk/Source/StructureMap.Testing/Pipeline/RedirectingTester.cs Modified: trunk/Source/StructureMap/Attributes/PluggableAttribute.cs =================================================================== --- trunk/Source/StructureMap/Attributes/PluggableAttribute.cs 2009-07-14 15:03:08 UTC (rev 255) +++ trunk/Source/StructureMap/Attributes/PluggableAttribute.cs 2009-08-12 15:29:30 UTC (rev 256) @@ -20,23 +20,13 @@ public string ConcreteKey { get; set; } /// <summary> - /// Gets an instance of PluggableAttribute from a Type object - /// </summary> - /// <param name="objectType"></param> - /// <returns></returns> - public static PluggableAttribute InstanceOf(Type objectType) - { - return GetCustomAttribute(objectType, typeof (PluggableAttribute), false) as PluggableAttribute; - } - - /// <summary> /// Determines whether a Type object is marked as Pluggable /// </summary> /// <param name="objectType"></param> /// <returns></returns> public static bool MarkedAsPluggable(Type objectType) { - PluggableAttribute att = InstanceOf(objectType); + PluggableAttribute att = GetCustomAttribute(objectType, typeof (PluggableAttribute), false) as PluggableAttribute; return (att != null); } } Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2009-07-14 15:03:08 UTC (rev 255) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2009-08-12 15:29:30 UTC (rev 256) @@ -180,7 +180,7 @@ ConditionalInstance<T> Conditional(Action<ConditionalInstance<T>.ConditionalInstanceExpression> configuration); } - public class InstanceExpression<T> : IInstanceExpression<T>, ThenItExpression<T> + public class InstanceExpression<T> : IInstanceExpression<T>, ThenItExpression<T> { private readonly Action<Instance> _action; @@ -274,6 +274,7 @@ return returnInstance(new ConditionalInstance<T>(configuration)); } + IsExpression<T> ThenItExpression<T>.ThenIt { get { return this; } Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-07-14 15:03:08 UTC (rev 255) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-08-12 15:29:30 UTC (rev 256) @@ -45,6 +45,15 @@ /// <typeparam name="T"></typeparam> /// <param name="expression"></param> void SelectConstructor<T>(Expression<Func<T>> expression); + + /// <summary> + /// Use to "forward" the request for FROM to the default of TO + /// Useful for singleton services that implement multiple + /// interface roles + /// </summary> + /// <typeparam name="FROM"></typeparam> + /// <typeparam name="TO"></typeparam> + void Forward<FROM, TO>() where FROM : class where TO : class; } @@ -370,7 +379,12 @@ PluginCache.GetPlugin(typeof(T)).UseConstructor(expression); } + public void Forward<FROM, TO>() where FROM : class where TO : class + { + For<FROM>().Use(c => c.GetInstance<TO>() as FROM); + } + /// <summary> /// Syntactic Sugar for saying ForRequestedType().TheDefault.IsThis( @object ) /// </summary> Modified: trunk/Source/StructureMap/Graph/Plugin.cs =================================================================== --- trunk/Source/StructureMap/Graph/Plugin.cs 2009-07-14 15:03:08 UTC (rev 255) +++ trunk/Source/StructureMap/Graph/Plugin.cs 2009-08-12 15:29:30 UTC (rev 256) @@ -29,7 +29,8 @@ public Plugin(Type pluggedType) { - PluggableAttribute att = PluggableAttribute.InstanceOf(pluggedType); + PluggableAttribute att = + Attribute.GetCustomAttribute(pluggedType, typeof (PluggableAttribute), false) as PluggableAttribute; _concreteKey = att == null ? pluggedType.AssemblyQualifiedName : att.ConcreteKey; _pluggedType = pluggedType; Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2009-07-14 15:03:08 UTC (rev 255) +++ trunk/Source/StructureMap/InstanceFactory.cs 2009-08-12 15:29:30 UTC (rev 256) @@ -108,7 +108,7 @@ { _lifecycle = family.Lifecycle; } - else if (!_lifecycle.GetType().Equals(family.Lifecycle.GetType())) + else if (_lifecycle != null && family.Lifecycle != null && !_lifecycle.GetType().Equals(family.Lifecycle.GetType())) { // TODO: Might need to clear out the existing policy when it's ejected _lifecycle = family.Lifecycle; Modified: trunk/Source/StructureMap/Model.cs =================================================================== --- trunk/Source/StructureMap/Model.cs 2009-07-14 15:03:08 UTC (rev 255) +++ trunk/Source/StructureMap/Model.cs 2009-08-12 15:29:30 UTC (rev 256) @@ -17,6 +17,8 @@ /// </summary> IEnumerable<PluginTypeConfiguration> PluginTypes { get; } + IEnumerable<IInstance> AllInstances { get; } + /// <summary> /// Can StructureMap fulfill a request to ObjectFactory.GetInstance(pluginType) from the /// current configuration. This does not include concrete classes that could be auto-configured @@ -109,6 +111,20 @@ return HasImplementationsFor(typeof (T)); } + public IEnumerable<IInstance> AllInstances + { + get + { + foreach (var pluginType in PluginTypes) + { + foreach (IInstance instance in pluginType.Instances) + { + yield return instance; + } + } + } + } + #endregion } } \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Debugging.cs =================================================================== --- trunk/Source/StructureMap.Testing/Debugging.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Debugging.cs 2009-08-12 15:29:30 UTC (rev 256) @@ -0,0 +1,18 @@ +using NUnit.Framework; +using StructureMap.Testing.Widget; + +namespace StructureMap.Testing +{ + [TestFixture, Explicit] + public class Debugging + { + [SetUp] + public void SetUp() + { + } + + + } + + +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Pipeline/RedirectingTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/RedirectingTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Pipeline/RedirectingTester.cs 2009-08-12 15:29:30 UTC (rev 256) @@ -0,0 +1,36 @@ +using NUnit.Framework; + +namespace StructureMap.Testing.Pipeline +{ + [TestFixture] + public class RedirectingTester + { + [Test] + public void can_successfully_redirect() + { + var container = new Container(x => + { + x.For<IOne>().Use<OneAndTwo>(); + x.Forward<ITwo, IOne>(); + }); + + container.GetInstance<IOne>().ShouldBeOfType<OneAndTwo>(); + + } + } + + public interface IOne + { + + } + + public interface ITwo + { + + } + + public class OneAndTwo : IOne, ITwo + { + + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-07-14 15:03:08 UTC (rev 255) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-08-12 15:29:30 UTC (rev 256) @@ -220,6 +220,7 @@ <Compile Include="Configuration\PrimitiveArrayReaderTester.cs" /> <Compile Include="Configuration\ProfileBuilderTester.cs" /> <Compile Include="Configuration\ShortcuttedInstanceNodeTester.cs" /> + <Compile Include="Debugging.cs" /> <Compile Include="Diagnostics\DoctorTester.cs" /> <Compile Include="Diagnostics\WriterExtensions.cs" /> <Compile Include="Examples.cs"> @@ -362,6 +363,7 @@ <Compile Include="Pipeline\ProfileManagerTester.cs" /> <Compile Include="Pipeline\ProfileTester.cs" /> <Compile Include="Pipeline\PrototypeInstanceTester.cs" /> + <Compile Include="Pipeline\RedirectingTester.cs" /> <Compile Include="Pipeline\RedirectTester.cs" /> <Compile Include="Pipeline\ReferencedInstanceTester.cs" /> <Compile Include="Pipeline\SerializedInstanceTester.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |