diff --git a/src/Spring/Spring.Core/Context/Support/AbstractApplicationContext.cs b/src/Spring/Spring.Core/Context/Support/AbstractApplicationContext.cs
index 4b14379c..b9e4f0d6 100644
--- a/src/Spring/Spring.Core/Context/Support/AbstractApplicationContext.cs
+++ b/src/Spring/Spring.Core/Context/Support/AbstractApplicationContext.cs
@@ -523,9 +523,9 @@ namespace Spring.Context.Support
#endregion
}
- private void ProcessObjectFactoryPostProcessors(IList orderedFactoryProcessors)
+ private void ProcessObjectFactoryPostProcessors(IList objectFactoryPostProcessors)
{
- foreach (IObjectFactoryPostProcessor processor in orderedFactoryProcessors)
+ foreach (IObjectFactoryPostProcessor processor in objectFactoryPostProcessors)
{
processor.PostProcessObjectFactory(ObjectFactory);
}
diff --git a/src/Spring/Spring.Core/Core/IO/ConfigSectionResource.cs b/src/Spring/Spring.Core/Core/IO/ConfigSectionResource.cs
index db343ac4..77db37d0 100644
--- a/src/Spring/Spring.Core/Core/IO/ConfigSectionResource.cs
+++ b/src/Spring/Spring.Core/Core/IO/ConfigSectionResource.cs
@@ -177,7 +177,14 @@ namespace Spring.Core.IO
///
public override Stream InputStream
{
- get { return new MemoryStream(Encoding.UTF8.GetBytes(configElement.OuterXml)); }
+ get
+ {
+ if (configElement == null)
+ {
+ throw new FileNotFoundException(string.Format("Configuration Section '{0}' does not exist", this.sectionName), this.sectionName);
+ }
+ return new MemoryStream(Encoding.UTF8.GetBytes(configElement.OuterXml));
+ }
}
#endregion
diff --git a/src/Spring/Spring.Core/Objects/Factory/Config/DelegateObjectFactoryConfigurer.cs b/src/Spring/Spring.Core/Objects/Factory/Config/DelegateObjectFactoryConfigurer.cs
new file mode 100644
index 00000000..a2d35dc3
--- /dev/null
+++ b/src/Spring/Spring.Core/Objects/Factory/Config/DelegateObjectFactoryConfigurer.cs
@@ -0,0 +1,72 @@
+#region License
+
+/*
+ * Copyright 2002-2009 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#endregion
+
+namespace Spring.Objects.Factory.Config
+{
+ ///
+ /// A generic implementation of an , that delegates post processing to a passed delegate
+ ///
+ ///
+ /// This comes in handy when you want to perform specific tasks on an object factory, e.g. doing special initialization.
+ ///
+ ///
+ /// The example below is taken from a unit test. The snippet causes 'someObject' to be registered each time is called on
+ /// the context instance:
+ ///
+ /// IConfigurableApplicationContext ctx = new XmlApplicationContext(false, "name", false, null);
+ /// ctx.AddObjectFactoryPostProcessor(new DelegateObjectFactoryConfigurer( of =>
+ /// {
+ /// of.RegisterSingleton("someObject", someObject);
+ /// }));
+ ///
+ ///
+ /// Erich Eichinger
+ public class DelegateObjectFactoryConfigurer : IObjectFactoryPostProcessor
+ {
+ public delegate void ObjectFactoryConfigurationHandler(IConfigurableListableObjectFactory objectFactory);
+
+ private ObjectFactoryConfigurationHandler _configurationHandler;
+
+ ///
+ /// Get or Set the handler to delegate configuration to
+ ///
+ public ObjectFactoryConfigurationHandler ConfigurationHandler
+ {
+ get { return _configurationHandler; }
+ set { _configurationHandler = value; }
+ }
+
+ public DelegateObjectFactoryConfigurer()
+ { }
+
+ public DelegateObjectFactoryConfigurer(ObjectFactoryConfigurationHandler configurationHandler)
+ {
+ _configurationHandler = configurationHandler;
+ }
+
+ public void PostProcessObjectFactory(IConfigurableListableObjectFactory factory)
+ {
+ if (_configurationHandler != null)
+ {
+ _configurationHandler(factory);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Spring/Spring.Core/Spring.Core.2003.csproj b/src/Spring/Spring.Core/Spring.Core.2003.csproj
index e7b605f8..439f1b91 100644
--- a/src/Spring/Spring.Core/Spring.Core.2003.csproj
+++ b/src/Spring/Spring.Core/Spring.Core.2003.csproj
@@ -2070,6 +2070,11 @@
SubType = "Code"
BuildAction = "Compile"
/>
+
+
diff --git a/src/Spring/Spring.Core/Spring.Core.2008.csproj b/src/Spring/Spring.Core/Spring.Core.2008.csproj
index dda1bb0d..95974b3d 100644
--- a/src/Spring/Spring.Core/Spring.Core.2008.csproj
+++ b/src/Spring/Spring.Core/Spring.Core.2008.csproj
@@ -665,6 +665,7 @@
+
diff --git a/test/Spring/Spring.Core.Tests/Core/IO/ConfigSectionResourceTests.cs b/test/Spring/Spring.Core.Tests/Core/IO/ConfigSectionResourceTests.cs
index acff95db..3042fce2 100644
--- a/test/Spring/Spring.Core.Tests/Core/IO/ConfigSectionResourceTests.cs
+++ b/test/Spring/Spring.Core.Tests/Core/IO/ConfigSectionResourceTests.cs
@@ -70,5 +70,20 @@ namespace Spring.Core.IO
{
new ConfigSectionResource((XmlElement)null);
}
+
+ [Test]
+ public void ThrowsIoExceptionIfConfigSectionDoesNotExist()
+ {
+ IResource res = new ConfigSectionResource("DOES NOT EXIST");
+ try
+ {
+ Stream istm = res.InputStream;
+ Assert.Fail();
+ }
+ catch(IOException ioex)
+ {
+ Console.WriteLine(ioex);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/test/Spring/Spring.Core.Tests/Objects/Factory/Config/DelegateObjectFactoryConfigurerTests.cs b/test/Spring/Spring.Core.Tests/Objects/Factory/Config/DelegateObjectFactoryConfigurerTests.cs
new file mode 100644
index 00000000..f7efb412
--- /dev/null
+++ b/test/Spring/Spring.Core.Tests/Objects/Factory/Config/DelegateObjectFactoryConfigurerTests.cs
@@ -0,0 +1,80 @@
+#region License
+
+/*
+ * Copyright 2002-2009 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#endregion
+
+#if NET_2_0
+
+using NUnit.Framework;
+using Spring.Context;
+using Spring.Context.Support;
+
+namespace Spring.Objects.Factory.Config
+{
+ ///
+ ///
+ /// Erich Eichinger
+ [TestFixture]
+ public class DelegateObjectFactoryConfigurerIntegrationTests
+ {
+ private class MockObjectFactoryPostProcessor : IObjectFactoryPostProcessor
+ {
+ public bool Called;
+
+ public void PostProcessObjectFactory(IConfigurableListableObjectFactory factory)
+ {
+ Called = true;
+ }
+ }
+
+ [Test]
+ public void ExecutesBeforeObjectFactoryPostProcessing()
+ {
+ MockObjectFactoryPostProcessor mofp = new MockObjectFactoryPostProcessor();
+
+ IConfigurableApplicationContext ctx = new XmlApplicationContext(false, "name", false, null);
+ ctx.AddObjectFactoryPostProcessor(new DelegateObjectFactoryConfigurer(delegate(IConfigurableListableObjectFactory of)
+ {
+ of.RegisterSingleton("mofp", mofp);
+ }));
+
+ ctx.Refresh();
+ Assert.IsTrue(mofp.Called);
+ }
+
+ [Test]
+ public void CanBeUsedToReconfigureAnApplicationContextOnRefresh()
+ {
+ MockObjectFactoryPostProcessor mofp = new MockObjectFactoryPostProcessor();
+
+ IConfigurableApplicationContext ctx = new XmlApplicationContext(false, "name", false, null);
+ ctx.AddObjectFactoryPostProcessor(new DelegateObjectFactoryConfigurer(of =>
+ {
+ of.RegisterSingleton("mofp", mofp);
+ }));
+
+ ctx.Refresh();
+
+ mofp.Called = false;
+ ctx.Refresh();
+ Assert.IsTrue(mofp.Called);
+ }
+ }
+}
+
+#endif
\ No newline at end of file
diff --git a/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2003.csproj b/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2003.csproj
index 782d4b03..5696aa84 100644
--- a/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2003.csproj
+++ b/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2003.csproj
@@ -1347,6 +1347,11 @@
SubType = "Code"
BuildAction = "Compile"
/>
+
+
diff --git a/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj b/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj
index 09517648..6639fcd1 100644
--- a/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj
+++ b/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj
@@ -320,6 +320,7 @@
+