From: <fli...@us...> - 2009-09-28 02:01:49
|
Revision: 263 http://structuremap.svn.sourceforge.net/structuremap/?rev=263&view=rev Author: flimflan Date: 2009-09-28 02:01:41 +0000 (Mon, 28 Sep 2009) Log Message: ----------- Fixed bug with TryGetInstance not returning instances for registered open generic types. Modified Paths: -------------- trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs Modified: trunk/Source/StructureMap/PipelineGraph.cs =================================================================== --- trunk/Source/StructureMap/PipelineGraph.cs 2009-09-16 00:06:24 UTC (rev 262) +++ trunk/Source/StructureMap/PipelineGraph.cs 2009-09-28 02:01:41 UTC (rev 263) @@ -227,7 +227,9 @@ public bool HasDefaultForPluginType(Type pluginType) { - PluginTypeConfiguration configuration = PluginTypes.FirstOrDefault(p => p.PluginType == pluginType); + var typeToFind = pluginType.IsGenericType ? pluginType.GetGenericTypeDefinition() : pluginType; + var configuration = PluginTypes.FirstOrDefault(p => p.PluginType == typeToFind); + return configuration == null ? false : configuration.Default != null; } Modified: trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs 2009-09-16 00:06:24 UTC (rev 262) +++ trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs 2009-09-28 02:01:41 UTC (rev 263) @@ -272,8 +272,21 @@ instance.ShouldBeOfType(typeof(ColorRule)); } + [Test] + public void TryGetInstance_returns_instance_for_an_open_generic_that_it_can_close() + { + var container = new Container(x => x.ForRequestedType(typeof (IOpenGeneric<>)).TheDefaultIsConcreteType(typeof (ConcreteOpenGeneric<>))); + container.TryGetInstance<IOpenGeneric<object>>().ShouldNotBeNull(); + } + [Test] + public void TryGetInstance_returns_null_for_an_open_generic_that_it_cannot_close() + { + var container = new Container(x => x.ForRequestedType(typeof(IOpenGeneric<>)).TheDefaultIsConcreteType(typeof(ConcreteOpenGeneric<>))); + container.TryGetInstance<IAnotherOpenGeneric<object>>().ShouldBeNull(); + } + [Test, ExpectedException(typeof (StructureMapException))] public void GetMissingType() { @@ -303,4 +316,8 @@ manager.GetInstance<IService>(); } } + + public interface IOpenGeneric<T>{} + public interface IAnotherOpenGeneric<T>{} + public class ConcreteOpenGeneric<T> : IOpenGeneric<T>{} } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |