SPRNET-863 - Passing name of inner object to IApplicationContext.IsSingleton() throws NullReferenceException
This commit is contained in:
@@ -1507,7 +1507,10 @@ namespace Spring.Objects.Factory.Support
|
||||
return pof.IsSingleton( OriginalObjectName( name ) );
|
||||
}
|
||||
RootObjectDefinition od = GetMergedObjectDefinition( objectName, false );
|
||||
|
||||
if (od == null)
|
||||
{
|
||||
throw new NoSuchObjectDefinitionException(objectName);
|
||||
}
|
||||
// In case of IFactoryObject, return singleton status of created object if not a dereference
|
||||
if (od.IsSingleton)
|
||||
{
|
||||
|
||||
@@ -596,7 +596,7 @@ namespace Spring.Objects.Factory.Support
|
||||
((AbstractObjectFactory) ParentObjectFactory).GetObjectDefinition(name, includeAncestors);
|
||||
}
|
||||
}
|
||||
return definition;
|
||||
return definition;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -35,6 +35,27 @@ namespace Spring.Context.Support
|
||||
[TestFixture]
|
||||
public sealed class XmlApplicationContextTests
|
||||
{
|
||||
[Test]
|
||||
public void InnerObjectWithPostProcessing()
|
||||
{
|
||||
try
|
||||
{
|
||||
XmlApplicationContext ctx = new XmlApplicationContext(false, "assembly://Spring.Core.Tests/Spring.Context.Support/innerObjectsWithPostProcessor.xml");
|
||||
ctx.GetObject("hasInnerObjects");
|
||||
} catch (System.NullReferenceException e)
|
||||
{
|
||||
Assert.Fail("Should not throw NullReferenceException",e);
|
||||
} catch (ObjectCreationException e)
|
||||
{
|
||||
NoSuchObjectDefinitionException ex = e.InnerException as NoSuchObjectDefinitionException;
|
||||
Assert.IsNotNull(ex);
|
||||
//Pass
|
||||
} catch (Exception e)
|
||||
{
|
||||
Assert.Fail("Expect only ObjectCreationException to be thrown", e);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SingleConfigLocation()
|
||||
{
|
||||
@@ -346,6 +367,37 @@ namespace Spring.Context.Support
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
public class SingletonTestingObjectPostProcessor : IObjectPostProcessor, IApplicationContextAware
|
||||
{
|
||||
private IApplicationContext applicationContext;
|
||||
#region IObjectPostProcessor Members
|
||||
|
||||
public object PostProcessBeforeInitialization(object instance, string name)
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
public object PostProcessAfterInitialization(object instance, string objectName)
|
||||
{
|
||||
Console.WriteLine("post process " + objectName);
|
||||
if (this.applicationContext.IsSingleton(objectName))
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IApplicationContextAware Members
|
||||
|
||||
public IApplicationContext ApplicationContext
|
||||
{
|
||||
set { this.applicationContext = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns="http://www.springframework.net">
|
||||
|
||||
|
||||
<object id="objectPostProcessor" type="Spring.Context.Support.SingletonTestingObjectPostProcessor, Spring.Core.Tests"/>
|
||||
|
||||
<object id="hasInnerObjects" type="Spring.Objects.TestObject, Spring.Core.Tests">
|
||||
<constructor-arg>
|
||||
<value>hasInner</value>
|
||||
</constructor-arg>
|
||||
<constructor-arg index="1" type="System.Int32">
|
||||
<value>5</value>
|
||||
</constructor-arg>
|
||||
<property name="spouse">
|
||||
<object type="Spring.Objects.TestObject, Spring.Core.Tests">
|
||||
<property name="name">
|
||||
<value>inner1</value>
|
||||
</property>
|
||||
<property name="age">
|
||||
<value>6</value>
|
||||
</property>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
|
||||
</objects>
|
||||
@@ -32,6 +32,7 @@ using Common.Logging;
|
||||
using Common.Logging.Simple;
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
using Spring.Context;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Core.IO;
|
||||
using Spring.Core.TypeResolution;
|
||||
@@ -560,6 +561,7 @@ namespace Spring.Objects.Factory.Xml
|
||||
Assert.IsTrue(davesJen == jen, "1 jen instance");
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void InnerObjects()
|
||||
{
|
||||
@@ -2042,4 +2044,6 @@ namespace Spring.Objects.Factory.Xml
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -757,6 +757,7 @@
|
||||
<EmbeddedResource Include="Context\Support\invalidType.xml" />
|
||||
<EmbeddedResource Include="Core\TypeResolution\aliasedObjects.xml" />
|
||||
<EmbeddedResource Include="Core\IO\TestResource.txt" />
|
||||
<EmbeddedResource Include="Context\Support\innerObjectsWithPostProcessor.xml" />
|
||||
<EmbeddedResource Include="Core\IO\ConfigSectionResourceTests_config1.xml" />
|
||||
<Content Include="Data\PathMatcher\EmptyPattern.test" />
|
||||
<Content Include="Data\PathMatcher\Examples.test" />
|
||||
@@ -886,4 +887,4 @@
|
||||
xcopy "$(ProjectDir)Data" ..\..\..\..\build\VS.Net.2008\Spring.Core.Tests\$(ConfigurationName)\ /y /s /q /d
|
||||
xcopy "$(ProjectDir)$(TargetFileName).config" ..\..\..\..\build\VS.Net.2008\Spring.Core.Tests\$(ConfigurationName)\ /y /s /q</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user