From: <jer...@us...> - 2010-02-04 02:35:32
|
Revision: 330 http://structuremap.svn.sourceforge.net/structuremap/?rev=330&view=rev Author: jeremydmiller Date: 2010-02-04 00:51:33 +0000 (Thu, 04 Feb 2010) Log Message: ----------- committed a patch from Frank Quednau related to open generics types Modified Paths: -------------- trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs trunk/Source/StructureMap/TypeExtensions.cs trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2010-02-04 00:33:40 UTC (rev 329) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2010-02-04 00:51:33 UTC (rev 330) @@ -288,9 +288,15 @@ return clone; }).Where(x => x != null).Each(templatedFamily.AddInstance); + //Are there instances that close the templatedtype straight away? + _instances.GetAll() + .Where(x => x.ConcreteType.CanBeCastTo(templatedType)) + .Each(templatedFamily.AddInstance); + // Need to attach the new PluginFamily to the old PluginGraph Parent.PluginFamilies.Add(templatedFamily); + return templatedFamily; } @@ -363,4 +369,4 @@ #endregion } -} \ No newline at end of file +} Modified: trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs 2010-02-04 00:33:40 UTC (rev 329) +++ trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs 2010-02-04 00:51:33 UTC (rev 330) @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Globalization; using System.Linq; using StructureMap.Construction; using StructureMap.Graph; @@ -198,7 +199,7 @@ if (value.GetType() == dependencyType) return new ObjectInstance(value); TypeConverter converter = TypeDescriptor.GetConverter(dependencyType); - object convertedValue = converter.ConvertFrom(value); + object convertedValue = converter.ConvertFrom(null, CultureInfo.InvariantCulture, value); return new ObjectInstance(convertedValue); } catch (Exception e) @@ -276,4 +277,4 @@ return "'{0}' -> {1}".ToFormat(Name, _plugin.PluggedType.FullName); } } -} \ No newline at end of file +} Modified: trunk/Source/StructureMap/TypeExtensions.cs =================================================================== --- trunk/Source/StructureMap/TypeExtensions.cs 2010-02-04 00:33:40 UTC (rev 329) +++ trunk/Source/StructureMap/TypeExtensions.cs 2010-02-04 00:51:33 UTC (rev 330) @@ -181,7 +181,7 @@ return false; } - if (pluginType.IsOpenGeneric() && pluggedType.IsGenericType) + if (pluginType.IsOpenGeneric()) { return GenericsPluginGraph.CanBeCast(pluginType, pluggedType); } @@ -257,4 +257,4 @@ } } } -} \ No newline at end of file +} Modified: trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2010-02-04 00:33:40 UTC (rev 329) +++ trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2010-02-04 00:51:33 UTC (rev 330) @@ -157,6 +157,13 @@ } [Test] + public void CanPlugConcreteNonGenericClassIntoGenericInterface() + { + typeof(NotSoGenericService).CanBeCastTo(typeof(IGenericService<>)) + .ShouldBeTrue(); + } + + [Test] public void Define_profile_with_generics_and_concrete_type() { var container = new Container(registry => @@ -306,4 +313,9 @@ return typeof (T); } } -} \ No newline at end of file + + public class NotSoGenericService : IGenericService<string> + { + public void DoSomething(string thing) { } + } +} Modified: trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs 2010-02-04 00:33:40 UTC (rev 329) +++ trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs 2010-02-04 00:51:33 UTC (rev 330) @@ -37,7 +37,15 @@ public class Service3<T> : IService<T> { } + + public interface IOtherService<T> + { + } + public class Service4 : IOtherService<string> + { + } + [PluginFamily("Default")] public interface IThingy { @@ -134,6 +142,22 @@ } [Test] + public void Add_an_assembly_on_the_fly_and_pick_up_plugins4() + { + var container = new Container(); + container.Configure( + registry => registry.Scan( + x => + { + x.AssemblyContainingType(typeof (IOtherService<>)); + x.AddAllTypesOf(typeof (IOtherService<>)); + })); + + var instances = container.GetAllInstances<IOtherService<string>>(); + instances.Any(s=> s is Service4).ShouldBeTrue(); + } + + [Test] public void Add_generic_stuff_in_configure() { var container = new Container(); @@ -331,4 +355,4 @@ throw new NotImplementedException(); } } -} \ No newline at end of file +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |