当前位置: 首页>>代码示例>>C#>>正文


C# DefaultListableObjectFactory.AddObjectPostProcessor方法代码示例

本文整理汇总了C#中Spring.Objects.Factory.Support.DefaultListableObjectFactory.AddObjectPostProcessor方法的典型用法代码示例。如果您正苦于以下问题:C# DefaultListableObjectFactory.AddObjectPostProcessor方法的具体用法?C# DefaultListableObjectFactory.AddObjectPostProcessor怎么用?C# DefaultListableObjectFactory.AddObjectPostProcessor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Spring.Objects.Factory.Support.DefaultListableObjectFactory的用法示例。


在下文中一共展示了DefaultListableObjectFactory.AddObjectPostProcessor方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProxyObjectWithoutInterface

        public void ProxyObjectWithoutInterface()
        {
            DefaultListableObjectFactory of = new DefaultListableObjectFactory();
            of.RegisterObjectDefinition("bar", new RootObjectDefinition(typeof(ObjectWithoutInterface)));

            TestAutoProxyCreator apc = new TestAutoProxyCreator(of);
            of.AddObjectPostProcessor(apc);

            ObjectWithoutInterface o = of.GetObject("bar") as ObjectWithoutInterface;
            Assert.IsTrue(AopUtils.IsAopProxy(o));
            o.Foo();
            Assert.AreEqual(1, apc.NopInterceptor.Count);
        }
开发者ID:smnbss,项目名称:spring-net,代码行数:13,代码来源:AbstractAutoProxyCreatorTests.cs

示例2: TestIInstantiationAwareObjectPostProcessorsPassThrough

        public void TestIInstantiationAwareObjectPostProcessorsPassThrough()
        {
            NullInstantiationAwareObjectPostProcessorStub proc
                = new NullInstantiationAwareObjectPostProcessorStub();

            MutablePropertyValues props = new MutablePropertyValues();
            props.Add("Name", "Rick");
            RootObjectDefinition not
                = new RootObjectDefinition(typeof(TestObject), props);

            DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
            lof.AddObjectPostProcessor(proc);
            lof.RegisterObjectDefinition("notToBeProxied", not);

            object foo = lof["notToBeProxied"];
            Assert.IsNotNull(foo);
            Assert.AreEqual(typeof(TestObject), foo.GetType());
            TestObject to = (TestObject)foo;
            Assert.AreEqual("Rick", to.Name);
        }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:20,代码来源:DefaultListableObjectFactoryTests.cs

示例3: TestIInstantiationAwareObjectPostProcessorsInterception

        public void TestIInstantiationAwareObjectPostProcessorsInterception()
        {
            ProxyingInstantiationAwareObjectPostProcessorStub proc
                = new ProxyingInstantiationAwareObjectPostProcessorStub("TheAgony");

            MutablePropertyValues props = new MutablePropertyValues();
            props.Add("Name", "Rick");
            RootObjectDefinition toBeProxied
                = new RootObjectDefinition(typeof(TestObject), props);

            DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
            lof.AddObjectPostProcessor(proc);
            lof.RegisterObjectDefinition("toBeProxied", toBeProxied);

            object proxy = lof["toBeProxied"];
            Assert.IsNotNull(proxy);
            Assert.AreEqual("TheAgony", proxy);
        }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:18,代码来源:DefaultListableObjectFactoryTests.cs

示例4: GetObjectPostProcessorCountDoesntRespectHierarchy

        public void GetObjectPostProcessorCountDoesntRespectHierarchy()
        {

            IObjectPostProcessor proc1 = mocks.StrictMock<IObjectPostProcessor>();
            IObjectPostProcessor proc2 = mocks.StrictMock<IObjectPostProcessor>();

            DefaultListableObjectFactory child = new DefaultListableObjectFactory();
            DefaultListableObjectFactory parent = new DefaultListableObjectFactory(child);

            const string errMsg = "Wrong number of IObjectPostProcessors being reported by the ObjectPostProcessorCount property.";
            Assert.AreEqual(0, child.ObjectPostProcessorCount, errMsg);
            Assert.AreEqual(0, parent.ObjectPostProcessorCount, errMsg);
            child.AddObjectPostProcessor(proc1);
            Assert.AreEqual(1, child.ObjectPostProcessorCount, errMsg);
            Assert.AreEqual(0, parent.ObjectPostProcessorCount, errMsg);
            parent.AddObjectPostProcessor(proc2);
            Assert.AreEqual(1, child.ObjectPostProcessorCount, errMsg);
            Assert.AreEqual(1, parent.ObjectPostProcessorCount, errMsg);
            child.AddObjectPostProcessor(proc2);
            Assert.AreEqual(2, child.ObjectPostProcessorCount, errMsg);
            Assert.AreEqual(1, parent.ObjectPostProcessorCount, errMsg);
        }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:22,代码来源:DefaultListableObjectFactoryTests.cs

示例5: GetObjectPostProcessorCount

        public void GetObjectPostProcessorCount()
        {
            IObjectPostProcessor proc1 = mocks.StrictMock<IObjectPostProcessor>();
            IObjectPostProcessor proc2 = mocks.StrictMock<IObjectPostProcessor>();

            DefaultListableObjectFactory lof = new DefaultListableObjectFactory();

            const string errMsg = "Wrong number of IObjectPostProcessors being reported by the ObjectPostProcessorCount property.";
            Assert.AreEqual(0, lof.ObjectPostProcessorCount, errMsg);
            lof.AddObjectPostProcessor(proc1);
            Assert.AreEqual(1, lof.ObjectPostProcessorCount, errMsg);
            lof.AddObjectPostProcessor(proc2);
            Assert.AreEqual(2, lof.ObjectPostProcessorCount, errMsg);

        }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:15,代码来源:DefaultListableObjectFactoryTests.cs

示例6: ConfigureObjectDoesNotApplyObjectPostProcessorsIfNoDefinition

        public void ConfigureObjectDoesNotApplyObjectPostProcessorsIfNoDefinition()
        {
            DefaultListableObjectFactory of = new DefaultListableObjectFactory();
            object wrapperObject = "WrapperObject";
            of.AddObjectPostProcessor( new TestObjectPostProcessor(wrapperObject));
 
            object testObject = "TestObject";
            object resultObject = of.ConfigureObject(testObject, "non-existant definition");
            Assert.AreSame(testObject, resultObject);            
        }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:10,代码来源:DefaultListableObjectFactoryTests.cs

示例7: ConfigureObjectAppliesObjectPostProcessorsUsingDefinition

        public void ConfigureObjectAppliesObjectPostProcessorsUsingDefinition()
        {
            DefaultListableObjectFactory of = new DefaultListableObjectFactory();
            object wrapperObject = "WrapperObject";
            of.AddObjectPostProcessor( new TestObjectPostProcessor(wrapperObject));
            of.RegisterObjectDefinition("myObjectDefinition", new RootObjectDefinition());

            object testObject = "TestObject";
            object resultObject = of.ConfigureObject(testObject, "myObjectDefinition");
            Assert.AreSame(wrapperObject, resultObject);            
        }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:11,代码来源:DefaultListableObjectFactoryTests.cs

示例8: CreateObjectDoesAffectContainerManagedSingletons

        public void CreateObjectDoesAffectContainerManagedSingletons()
        {
            using (DefaultListableObjectFactory lof = new DefaultListableObjectFactory())
            {
                lof.AddObjectPostProcessor(new SharedStateAwareProcessor(new ISharedStateFactory[] { new ByTypeSharedStateFactory() }, Int32.MaxValue ));

                MutablePropertyValues properties = new MutablePropertyValues();
                properties.Add(new PropertyValue("Age", 27));
                properties.Add(new PropertyValue("Name", "Bruno"));
                RootObjectDefinition singleton = new RootObjectDefinition(typeof(TestObject), null, properties);
                singleton.IsSingleton = true;
                lof.RegisterObjectDefinition("singleton", singleton);

                // a call to GetObject() results in a normally configured instance
                TestObject to = lof.GetObject("singleton") as TestObject;
                Assert.IsNotNull(to);
                // props set
                Assert.AreEqual(27, to.Age);
                Assert.AreEqual("Bruno", to.Name);
                // object postprocessors executed!
                Assert.AreEqual("singleton", to.ObjectName);
                Assert.AreEqual(lof, to.ObjectFactory);
                Assert.IsNotNull(to.SharedState);

                // altough configured as singleton, calling CreateObject prevents the instance from being cached
                // otherwise the container could not guarantee the results of calling GetObject() to other clients.
                TestObject to2 = lof.CreateObject("singleton", typeof(TestObject), null) as TestObject;
                Assert.IsNotNull(to2);
                // no props set
                Assert.AreEqual(0, to2.Age);
                Assert.AreEqual(null, to2.Name);
                // no object postprocessors executed!
                Assert.AreEqual(null, to2.ObjectName);
                Assert.AreEqual(null, to2.ObjectFactory);
                Assert.AreEqual(null, to2.SharedState);

                // a call to GetObject() results in a normally configured instance
                TestObject to3 = lof.GetObject("singleton") as TestObject;
                Assert.IsNotNull(to3);
                // props set
                Assert.AreEqual(27, to3.Age);
                Assert.AreEqual("Bruno", to3.Name);
                // object postprocessors executed!
                Assert.AreEqual("singleton", to3.ObjectName);
                Assert.AreEqual(lof, to3.ObjectFactory);
                Assert.IsNotNull(to3.SharedState);
            }
        }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:48,代码来源:DefaultListableObjectFactoryTests.cs

示例9: ProxyTransparentProxy

        public void ProxyTransparentProxy()
        {
            DefaultListableObjectFactory of = new DefaultListableObjectFactory();

            ConstructorArgumentValues ctorArgs = new ConstructorArgumentValues();
            ctorArgs.AddNamedArgumentValue("objectType", typeof(ITestObject));
            of.RegisterObjectDefinition("bar", new RootObjectDefinition(typeof(TransparentProxyFactory), ctorArgs, null));

            TestAutoProxyCreator apc = new TestAutoProxyCreator(of);
            of.AddObjectPostProcessor(apc);

            ITestObject o = of.GetObject("bar") as ITestObject;
            Assert.IsTrue(AopUtils.IsAopProxy(o));

            // ensure interceptors get called
            o.Foo();
            Assert.AreEqual(1, apc.NopInterceptor.Count);
            IAdvised advised = (IAdvised) o;

            // ensure target was called
            object target = advised.TargetSource.GetTarget();
            Assert.AreEqual(1, TransparentProxyFactory.GetRealProxy(target).Count);
        }
开发者ID:smnbss,项目名称:spring-net,代码行数:23,代码来源:AbstractAutoProxyCreatorTests.cs

示例10: IgnoreObjectPostProcessorDuplicates

        public void IgnoreObjectPostProcessorDuplicates()
        {
            IObjectPostProcessor proc1 = (IObjectPostProcessor)mocks.CreateMock(typeof(IObjectPostProcessor));

            DefaultListableObjectFactory lof = new DefaultListableObjectFactory();

            const string errMsg = "Wrong number of IObjectPostProcessors being reported by the ObjectPostProcessorCount property.";
            Assert.AreEqual(0, lof.ObjectPostProcessorCount, errMsg);
            lof.AddObjectPostProcessor(proc1);
            Assert.AreEqual(1, lof.ObjectPostProcessorCount, errMsg);
            lof.AddObjectPostProcessor(proc1);
            Assert.AreEqual(1, lof.ObjectPostProcessorCount, errMsg);
        }
开发者ID:smnbss,项目名称:spring-net,代码行数:13,代码来源:DefaultListableObjectFactoryTests.cs


注:本文中的Spring.Objects.Factory.Support.DefaultListableObjectFactory.AddObjectPostProcessor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。