From: <jer...@us...> - 2009-12-19 03:05:47
|
Revision: 279 http://structuremap.svn.sourceforge.net/structuremap/?rev=279&view=rev Author: jeremydmiller Date: 2009-12-19 03:05:37 +0000 (Sat, 19 Dec 2009) Log Message: ----------- Fixing an old, old bug with defensive programming being too tight around checking CanCastTo() Modified Paths: -------------- trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs trunk/Source/StructureMap/InstanceBuilderList.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs trunk/Source/StructureMap/TypeExtensions.cs trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap.Testing/Bugs/InjectByFuncWithNoPublicConstructors.cs Modified: trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs =================================================================== --- trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs 2009-12-19 02:29:03 UTC (rev 278) +++ trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs 2009-12-19 03:05:37 UTC (rev 279) @@ -22,10 +22,11 @@ public void Process(Type type, PluginGraph graph) { - if (!type.CanBeCastTo(_pluginType)) return; - - var name = _getName(type); - graph.AddType(_pluginType, type, name); + if (type.CanBeCastTo(_pluginType) && Constructor.HasConstructors(type)) + { + var name = _getName(type); + graph.AddType(_pluginType, type, name); + } } #endregion Modified: trunk/Source/StructureMap/InstanceBuilderList.cs =================================================================== --- trunk/Source/StructureMap/InstanceBuilderList.cs 2009-12-19 02:29:03 UTC (rev 278) +++ trunk/Source/StructureMap/InstanceBuilderList.cs 2009-12-19 03:05:37 UTC (rev 279) @@ -43,7 +43,7 @@ } // Add a missing PluggedType if we can - if (pluggedType.CanBeCastTo(_pluginType)) + if (pluggedType.CanBeCastTo(_pluginType) && Constructor.HasConstructors(pluggedType)) { var plugin = new Plugin(pluggedType); processPlugin(plugin); Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs 2009-12-19 02:29:03 UTC (rev 278) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs 2009-12-19 03:05:37 UTC (rev 279) @@ -179,7 +179,7 @@ protected override bool canBePartOfPluginFamily(PluginFamily family) { - return _pluggedType.CanBeCastTo(family.PluginType); + return _pluggedType.CanBeCastTo(family.PluginType) && Constructor.HasConstructors(_pluggedType); } internal override bool Matches(Plugin plugin) Modified: trunk/Source/StructureMap/TypeExtensions.cs =================================================================== --- trunk/Source/StructureMap/TypeExtensions.cs 2009-12-19 02:29:03 UTC (rev 278) +++ trunk/Source/StructureMap/TypeExtensions.cs 2009-12-19 03:05:37 UTC (rev 279) @@ -124,11 +124,6 @@ return false; } - if (noPublicConstructors(pluggedType)) - { - return false; - } - if (IsGeneric(pluginType)) { return GenericsPluginGraph.CanBeCast(pluginType, pluggedType); @@ -164,11 +159,6 @@ return returnValue; } - private static bool noPublicConstructors(Type pluggedType) - { - return pluggedType.GetConstructors().Length == 0; - } - public static bool IsString(this Type type) { return type.Equals(typeof(string)); Added: trunk/Source/StructureMap.Testing/Bugs/InjectByFuncWithNoPublicConstructors.cs =================================================================== --- trunk/Source/StructureMap.Testing/Bugs/InjectByFuncWithNoPublicConstructors.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Bugs/InjectByFuncWithNoPublicConstructors.cs 2009-12-19 03:05:37 UTC (rev 279) @@ -0,0 +1,34 @@ +using NUnit.Framework; + +namespace StructureMap.Testing.Bugs +{ + [TestFixture] + public class InjectByFuncWithNoPublicConstructors + { + [SetUp] + public void SetUp() + { + } + + [Test] + public void register_with_generic() + { + var container = new Container(x => + { + x.For<ClassThatIsBuiltByStatic>().Use(c => ClassThatIsBuiltByStatic.Build()); + }); + + container.GetInstance<ClassThatIsBuiltByStatic>().ShouldNotBeNull(); + } + } + + public class ClassThatIsBuiltByStatic + { + public static ClassThatIsBuiltByStatic Build() + { + return new ClassThatIsBuiltByStatic(); + } + + private ClassThatIsBuiltByStatic(){} + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs 2009-12-19 02:29:03 UTC (rev 278) +++ trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs 2009-12-19 03:05:37 UTC (rev 279) @@ -29,13 +29,7 @@ private IContainer container; - [Test] - public void DoNotFindPluginWithNoPublicCTOR() - { - Assert.IsFalse(typeof (GreenType).CanBeCastTo(typeof (TypeIWantToFind))); - } - [Test] public void FoundTheRightNumberOfInstancesForATypeWithNoPlugins() { Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-12-19 02:29:03 UTC (rev 278) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-12-19 03:05:37 UTC (rev 279) @@ -182,6 +182,7 @@ <Compile Include="Bugs\FillAllPropertiesShouldWorkForAlreadyConfiguredPluginsBug.cs" /> <Compile Include="Bugs\HttpSessionNullRefBug.cs" /> <Compile Include="Bugs\IDictionaryAndXmlBugTester.cs" /> + <Compile Include="Bugs\InjectByFuncWithNoPublicConstructors.cs" /> <Compile Include="Bugs\LambdaCreatesNullBugTester.cs" /> <Compile Include="Bugs\MixedConfigureAndInitializeMissingInstanceProblem.cs" /> <Compile Include="Bugs\ScanIndexerBugTester.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |