From: <jer...@us...> - 2009-04-19 19:17:21
|
Revision: 236 http://structuremap.svn.sourceforge.net/structuremap/?rev=236&view=rev Author: jeremydmiller Date: 2009-04-19 19:17:16 +0000 (Sun, 19 Apr 2009) Log Message: ----------- Trying to fix a 400 bug related to a lambda returning null Modified Paths: -------------- trunk/Source/StructureMap/Graph/PluginCache.cs trunk/Source/StructureMap/InstanceCache.cs trunk/Source/StructureMap/StructureMapException.resx trunk/Source/StructureMap/Util/Cache.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap.Testing/Bugs/LambdaCreatesNullBugTester.cs Modified: trunk/Source/StructureMap/Graph/PluginCache.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginCache.cs 2009-04-19 18:40:49 UTC (rev 235) +++ trunk/Source/StructureMap/Graph/PluginCache.cs 2009-04-19 19:17:16 UTC (rev 236) @@ -30,8 +30,15 @@ _builders = new Cache<Type, InstanceBuilder>(t => { - Plugin plugin = _plugins[t]; - return new InstanceBuilderAssembly(new[] {plugin}).Compile()[0]; + try + { + Plugin plugin = _plugins[t]; + return new InstanceBuilderAssembly(new[] {plugin}).Compile()[0]; + } + catch (Exception e) + { + throw new StructureMapException(245, t.AssemblyQualifiedName, e); + } }); } Modified: trunk/Source/StructureMap/InstanceCache.cs =================================================================== --- trunk/Source/StructureMap/InstanceCache.cs 2009-04-19 18:40:49 UTC (rev 235) +++ trunk/Source/StructureMap/InstanceCache.cs 2009-04-19 19:17:16 UTC (rev 236) @@ -38,6 +38,8 @@ public void Set(Type pluginType, Instance Instance, object result) { + if (result == null) return; + Dictionary<Instance, object> cache = getCache(pluginType); if (cache.ContainsKey(Instance)) Modified: trunk/Source/StructureMap/StructureMapException.resx =================================================================== --- trunk/Source/StructureMap/StructureMapException.resx 2009-04-19 18:40:49 UTC (rev 235) +++ trunk/Source/StructureMap/StructureMapException.resx 2009-04-19 19:17:16 UTC (rev 236) @@ -274,4 +274,7 @@ <data name="295" xml:space="preserve"> <value>Bidirectional Dependency Problem detected with {0}. The BuildStack is: {1}</value> </data> + <data name="245" xml:space="preserve"> + <value>Error while trying to create an InstanceBuilder for {0}</value> + </data> </root> \ No newline at end of file Modified: trunk/Source/StructureMap/Util/Cache.cs =================================================================== --- trunk/Source/StructureMap/Util/Cache.cs 2009-04-19 18:40:49 UTC (rev 235) +++ trunk/Source/StructureMap/Util/Cache.cs 2009-04-19 19:17:16 UTC (rev 236) @@ -81,7 +81,9 @@ VALUE value = _onMissing(key); //Check to make sure that the onMissing didn't cache this already if(!_values.ContainsKey(key)) + { _values.Add(key, value); + } } } } @@ -90,14 +92,17 @@ } set { - if (_values.ContainsKey(key)) + lock (_locker) { - _values[key] = value; + if (_values.ContainsKey(key)) + { + _values[key] = value; + } + else + { + _values.Add(key, value); + } } - else - { - _values.Add(key, value); - } } } Added: trunk/Source/StructureMap.Testing/Bugs/LambdaCreatesNullBugTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Bugs/LambdaCreatesNullBugTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Bugs/LambdaCreatesNullBugTester.cs 2009-04-19 19:17:16 UTC (rev 236) @@ -0,0 +1,43 @@ +using System.Security.Principal; +using NUnit.Framework; + +namespace StructureMap.Testing.Bugs +{ + + [TestFixture] public class LambdaCreatesNullBugTester + { + [SetUp] public void SetUp() + { + + } + + [Test] + public void Returning_null_values_in_contructed_by_generates_a_duplicate_cache_entry() + { + var container = new Container(x => + { + x.ForRequestedType<IPrincipal>().TheDefault.Is.ConstructedBy(() => null); + + x.ForRequestedType<TestClass>().TheDefaultIsConcreteType<TestClass>(); + }); + + container.GetInstance<TestClass>().ShouldNotBeNull(); + + + //this throws a duplicate cache entry exception + container.AssertConfigurationIsValid(); + } + } + + + public class TestClass + { + private IPrincipal principal; + + public TestClass(IPrincipal principal) + { + this.principal = principal; + } + + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-04-19 18:40:49 UTC (rev 235) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-04-19 19:17:16 UTC (rev 236) @@ -181,6 +181,7 @@ <Compile Include="Bugs\BuildUpBug.cs" /> <Compile Include="Bugs\HttpSessionNullRefBug.cs" /> <Compile Include="Bugs\IDictionaryAndXmlBugTester.cs" /> + <Compile Include="Bugs\LambdaCreatesNullBugTester.cs" /> <Compile Include="Bugs\ScanIndexerBugTester.cs" /> <Compile Include="Bugs\SingletonShouldBeLazy.cs" /> <Compile Include="Bugs\SpecifyScopeInConfigureTester.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |