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);
        }
        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);
        }
Example #3
0
        public void MultipleConfigLocations()
        {
            XmlApplicationContext ctx =
                new XmlApplicationContext(false, "assembly://Spring.Core.Tests/Spring.Context.Support/contextB.xml",
                                          "assembly://Spring.Core.Tests/Spring.Context.Support/contextC.xml",
                                          "assembly://Spring.Core.Tests/Spring.Context.Support/contextA.xml");

            Assert.IsTrue(ctx.ContainsObject("service"));
            Assert.IsTrue(ctx.ContainsObject("logicOne"));
            Assert.IsTrue(ctx.ContainsObject("logicTwo"));
            Service service = (Service)ctx.GetObject("service");

            ctx.Refresh();
            Assert.IsTrue(service.ProperlyDestroyed);
            service = (Service)ctx.GetObject("service");
            ctx.Dispose();
            Assert.IsTrue(service.ProperlyDestroyed);
        }
 public void MultipleConfigLocations()
 {
     XmlApplicationContext ctx =
         new XmlApplicationContext(false, "assembly://Spring.Core.Tests/Spring.Context.Support/contextB.xml",
                                   "assembly://Spring.Core.Tests/Spring.Context.Support/contextC.xml",
                                   "assembly://Spring.Core.Tests/Spring.Context.Support/contextA.xml");
     Assert.IsTrue(ctx.ContainsObject("service"));
     Assert.IsTrue(ctx.ContainsObject("logicOne"));
     Assert.IsTrue(ctx.ContainsObject("logicTwo"));
     Service service = (Service) ctx.GetObject("service");
     ctx.Refresh();
     Assert.IsTrue(service.ProperlyDestroyed);
     service = (Service) ctx.GetObject("service");
     ctx.Dispose();
     Assert.IsTrue(service.ProperlyDestroyed);
 }
Example #5
0
        public void ShouldLoad()
        {
            IList<IObjectFactoryPostProcessor> all = new List<IObjectFactoryPostProcessor>();

            XmlApplicationContext child1 = new XmlApplicationContext("file://Spring/Layered/child1.xml");
            IDictionary processors = child1.GetObjectsOfType(typeof (IObjectFactoryPostProcessor));
            IEnumerator enumerator = processors.Values.GetEnumerator();

            while(enumerator.MoveNext())
            {
                all.Add((IObjectFactoryPostProcessor)enumerator.Current);
            }

            XmlApplicationContext child2 = new XmlApplicationContext(false, null, true, child1, "file://Spring/Layered/child2.xml");
            foreach (IObjectFactoryPostProcessor entry in all)
            {
                child2.AddObjectFactoryPostProcessor(entry);
            }
            child2.Refresh();
            XmlApplicationContext main = new XmlApplicationContext(false, null, true, child2, "file://Spring/Layered/main.xml");

            foreach (IObjectFactoryPostProcessor entry in all)
            {
                main.AddObjectFactoryPostProcessor(entry);
            }
            main.Refresh();
            Aggregate agg = (Aggregate) main.GetObject("agg");
            Assert.IsNotNull(agg);

            Service3 three = (Service3) main.GetObject("service3");

            Assert.IsNotNull(three);

            PostProcessor processor = (PostProcessor)main.GetObject("PostProcessor");

            Assert.IsNotNull(processor);
            IList<string> names = processor.Names;
            Assert.AreEqual(3, names.Count);
            Assert.IsTrue(names.Contains("foo"));
            Assert.IsTrue(names.Contains("barService"));
            Assert.IsTrue(names.Contains("connection"));
        }