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


C# DefaultListableObjectFactory.GetObject方法代码示例

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


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

示例1: Can_Create_Custom_Scan_Routine

 public void Can_Create_Custom_Scan_Routine()
 {
     var scanner = new ScanOverridingAssemblyObjectDefinitionScanner();
     var registry = new DefaultListableObjectFactory();
     scanner.ScanAndRegisterTypes(registry);
     Assert.That(registry.ObjectDefinitionCount, Is.EqualTo(1), "found multiple definitions");
     Assert.That(registry.GetObject<ComponentScan.ScanComponentsAndAddToContext.ConfigurationImpl>(), Is.Not.Null,
                 "correct single defintion was not registered");
 }
开发者ID:spring-projects,项目名称:spring-net-codeconfig,代码行数:9,代码来源:AssemblyObjectDefinitionScannerTests.cs

示例2: ShouldAllowConfigurationClassInheritance

        public void ShouldAllowConfigurationClassInheritance()
        {
            var factory = new DefaultListableObjectFactory();
            factory.RegisterObjectDefinition("DerivedConfiguration", new GenericObjectDefinition
                                                                         {
                                                                             ObjectType = typeof(DerivedConfiguration)
                                                                         });

            var processor = new ConfigurationClassPostProcessor();

            processor.PostProcessObjectFactory(factory);

            // we should get singleton instances only
            TestObject testObject = (TestObject) factory.GetObject("DerivedDefinition");
            string singletonParent = (string) factory.GetObject("BaseDefinition");

            Assert.That(testObject.Value, Is.SameAs(singletonParent));
        }
开发者ID:spring-projects,项目名称:spring-net-codeconfig,代码行数:18,代码来源:ConfigurationClassPostProcessorTests.cs

示例3: AddPersistenceExceptionTranslation

        protected override void AddPersistenceExceptionTranslation(ProxyFactory pf, IPersistenceExceptionTranslator pet)
        {
            if (AttributeUtils.FindAttribute(pf.TargetType, typeof(RepositoryAttribute)) != null)
            {
                DefaultListableObjectFactory of = new DefaultListableObjectFactory();
                of.RegisterObjectDefinition("peti", new RootObjectDefinition(typeof(PersistenceExceptionTranslationInterceptor)));
                of.RegisterSingleton("pet", pet);
                pf.AddAdvice((PersistenceExceptionTranslationInterceptor) of.GetObject("peti"));

            }
        }
开发者ID:fgq841103,项目名称:spring-net,代码行数:11,代码来源:PersistenceExceptionTranslationInterceptorTests.cs

示例4: 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

示例5: ConvertsWriteConcernCorrectly

        public void ConvertsWriteConcernCorrectly()
        {
            DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
            factory.RegisterCustomConverter(typeof(WriteConcern), new WriteConcernTypeConverter());

            RootObjectDefinition definition = new RootObjectDefinition(typeof(MongoFactoryObject));
            definition.PropertyValues.Add("Url", "mongodb://localhost");
            definition.PropertyValues.Add("WriteConcern", "Acknowledged");
            factory.RegisterObjectDefinition("factory", definition);

            MongoFactoryObject obj = factory.GetObject<MongoFactoryObject>("&factory");
            Assert.That(ReflectionUtils.GetInstanceFieldValue(obj, "_writeConcern"),
                        Is.EqualTo(WriteConcern.Acknowledged));
        }
开发者ID:thomast74,项目名称:spring-net-data-mongodb,代码行数:14,代码来源:MongoFactoryObjectTests.cs

示例6: Test

        public void Test()
        {
            int numIterations = 10000;
            start = DateTime.Now;
            DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
            InitFactory(factory);
            for (int i = 0; i < numIterations; i++)
            {
              FFoo foo = (FFoo)factory.GetObject("foo");
            }
            stop = DateTime.Now;
            double timeElapsed = Elapsed;
            PrintTest("Creations", numIterations, timeElapsed);


        }
开发者ID:fgq841103,项目名称:spring-net,代码行数:16,代码来源:DefaultListableObjectFactoryPerfTests.cs

示例7: CircularReferences

 public void CircularReferences()
 {
     DefaultListableObjectFactory xof = new DefaultListableObjectFactory();
     XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(xof);
     reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("reftypes.xml", GetType()));
     TestObject jenny = (TestObject) xof.GetObject("jenny");
     TestObject david = (TestObject) xof.GetObject("david");
     TestObject ego = (TestObject) xof.GetObject("ego");
     Assert.IsTrue(jenny.Spouse == david, "Correct circular reference");
     Assert.IsTrue(david.Spouse == jenny, "Correct circular reference");
     Assert.IsTrue(ego.Spouse == ego, "Correct circular reference");
 }
开发者ID:fgq841103,项目名称:spring-net,代码行数:12,代码来源:XmlObjectFactoryTests.cs

示例8: InnerObjects

        public void InnerObjects()
        {
            DefaultListableObjectFactory xof = new DefaultListableObjectFactory();
            XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(xof);
            reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("reftypes.xml", GetType()));

            // Let's create the outer bean named "innerObject",
            // to check whether it doesn't create any conflicts
            // with the actual inner object named "innerObject".
            xof.GetObject("innerObject");

            TestObject hasInnerObjects = (TestObject) xof.GetObject("hasInnerObjects");
            Assert.AreEqual(5, hasInnerObjects.Age);           
            TestObject inner1 = (TestObject) hasInnerObjects.Spouse;
            Assert.IsNotNull(inner1);            
            Assert.AreEqual("Spring.Objects.TestObject#", inner1.ObjectName.Substring(0, inner1.ObjectName.IndexOf("#")+1));            
            Assert.AreEqual("inner1", inner1.Name);
            Assert.AreEqual(6, inner1.Age);
            
            
            Assert.IsNotNull(hasInnerObjects.Friends);
            IList friends = (IList) hasInnerObjects.Friends;
            Assert.AreEqual(2, friends.Count);
            DerivedTestObject inner2 = (DerivedTestObject) friends[0];
            Assert.AreEqual("inner2", inner2.Name);
            Assert.AreEqual(7, inner2.Age);
            Assert.AreEqual("Spring.Objects.DerivedTestObject#", inner2.ObjectName.Substring(0, inner2.ObjectName.IndexOf("#") + 1));      
            TestObject innerFactory = (TestObject) friends[1];
            Assert.AreEqual(DummyFactory.SINGLETON_NAME, innerFactory.Name);

            
            Assert.IsNotNull(hasInnerObjects.SomeMap);
            Assert.IsFalse((hasInnerObjects.SomeMap.Count == 0));
            TestObject inner3 = (TestObject) hasInnerObjects.SomeMap["someKey"];
            Assert.AreEqual("Jenny", inner3.Name);
            Assert.AreEqual(30, inner3.Age);
            xof.Dispose();
            Assert.IsTrue(inner2.WasDestroyed());
            Assert.IsTrue(innerFactory.Name == null);
        }
开发者ID:fgq841103,项目名称:spring-net,代码行数:40,代码来源:XmlObjectFactoryTests.cs

示例9: RefToSeparatePrototypeInstances

 public void RefToSeparatePrototypeInstances()
 {
     DefaultListableObjectFactory xof = new DefaultListableObjectFactory();
     XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(xof);
     reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("reftypes.xml", GetType()));
     Assert.IsTrue(xof.ObjectDefinitionCount == 9, "9 objects in reftypes, not " + xof.ObjectDefinitionCount);
     TestObject emma = (TestObject) xof.GetObject("emma");
     TestObject georgia = (TestObject) xof.GetObject("georgia");
     ITestObject emmasJenks = emma.Spouse;
     ITestObject georgiasJenks = georgia.Spouse;
     Assert.IsTrue(emmasJenks != georgiasJenks, "Emma and georgia think they have a different boyfriend.");
     Assert.IsTrue(emmasJenks.Name.Equals("Andrew"), "Emmas jenks has right name");
     Assert.IsTrue(emmasJenks != xof.GetObject("jenks"), "Emmas doesn't equal new ref.");
     Assert.IsTrue(emmasJenks.Name.Equals("Andrew"), "Georgias jenks has right name.");
     Assert.IsTrue(emmasJenks.Equals(georgiasJenks), "They are object equal.");
     Assert.IsTrue(emmasJenks.Equals(xof.GetObject("jenks")), "They object equal direct ref.");
 }
开发者ID:fgq841103,项目名称:spring-net,代码行数:17,代码来源:XmlObjectFactoryTests.cs

示例10: BailsOnRubbishPropertyRetrievingFactoryMethod

 public void BailsOnRubbishPropertyRetrievingFactoryMethod()
 {
     DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
     XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(factory);
     reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("field-props-factory.xml", GetType()));
     factory.GetObject("rubbishProperty", typeof(MyTestObject));
 }
开发者ID:fgq841103,项目名称:spring-net,代码行数:7,代码来源:XmlObjectFactoryTests.cs

示例11: StaticFieldRetrievingFactoryMethod

 public void StaticFieldRetrievingFactoryMethod()
 {
     DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
     XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(factory);
     reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("field-props-factory.xml", GetType()));
     MyTestObject obj = factory.GetObject("withTypesField", typeof(MyTestObject)) as MyTestObject;
     Assert.IsNotNull(obj.Types);
     Assert.AreEqual(Type.EmptyTypes.Length, obj.Types.Length);
 }
开发者ID:fgq841103,项目名称:spring-net,代码行数:9,代码来源:XmlObjectFactoryTests.cs

示例12: AutowireWithSatisfiedConstructorDependency

 public void AutowireWithSatisfiedConstructorDependency()
 {
     DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
     MutablePropertyValues pvs = new MutablePropertyValues();
     pvs.Add(new PropertyValue("name", "Rod"));
     RootObjectDefinition rood = new RootObjectDefinition(typeof(TestObject), pvs);
     lof.RegisterObjectDefinition("rod", rood);
     Assert.AreEqual(1, lof.ObjectDefinitionCount);
     object registered = lof.Autowire(typeof(ConstructorDependency), AutoWiringMode.AutoDetect, false);
     Assert.AreEqual(1, lof.ObjectDefinitionCount);
     ConstructorDependency kerry = (ConstructorDependency)registered;
     TestObject rod = (TestObject)lof.GetObject("rod");
     Assert.AreSame(rod, kerry._spouse);
 }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:14,代码来源:DefaultListableObjectFactoryTests.cs

示例13: AutowireExistingObjectByType

 public void AutowireExistingObjectByType()
 {
     DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
     RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject));
     lof.RegisterObjectDefinition("test", rod);
     DependenciesObject existingObj = new DependenciesObject();
     lof.AutowireObjectProperties(existingObj, AutoWiringMode.ByType, true);
     TestObject test = (TestObject)lof.GetObject("test");
     Assert.AreEqual(existingObj.Spouse, test);
 }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:10,代码来源:DefaultListableObjectFactoryTests.cs

示例14: AutowireExistingObjectByName

 public void AutowireExistingObjectByName()
 {
     DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
     RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject));
     lof.RegisterObjectDefinition("Spouse", rod);
     DependenciesObject existingObj = new DependenciesObject();
     lof.AutowireObjectProperties(existingObj, AutoWiringMode.ByName, true);
     TestObject spouse = (TestObject)lof.GetObject("Spouse");
     Assert.AreEqual(existingObj.Spouse, spouse);
     Assert.IsTrue(ObjectFactoryUtils.ObjectOfType(lof, typeof(TestObject)) == spouse);
 }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:11,代码来源:DefaultListableObjectFactoryTests.cs

示例15: AutowireObjectByNameIsNotCaseInsensitive

 public void AutowireObjectByNameIsNotCaseInsensitive()
 {
     DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
     RootObjectDefinition rodDefinition = new RootObjectDefinition(typeof(TestObject));
     rodDefinition.PropertyValues.Add("name", "Rod");
     rodDefinition.AutowireMode = AutoWiringMode.ByName;
     RootObjectDefinition kerryDefinition = new RootObjectDefinition(typeof(TestObject));
     kerryDefinition.PropertyValues.Add("name", "Kerry");
     lof.RegisterObjectDefinition("rod", rodDefinition);
     lof.RegisterObjectDefinition("spouse", kerryDefinition); // property name is Spouse (capital S)
     TestObject objRod = (TestObject)lof.GetObject("rod");
     Assert.IsNull(objRod.Spouse, "Mmm, Spouse property appears to have been autowired by name, even though there is no object in the factory with a name 'Spouse'.");
 }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:13,代码来源:DefaultListableObjectFactoryTests.cs


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