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


C# DefaultListableObjectFactory.IsSingleton方法代码示例

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


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

示例1: RegisterExistingSingletonWithAutowire

 public void RegisterExistingSingletonWithAutowire()
 {
     DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
     MutablePropertyValues pvs = new MutablePropertyValues();
     pvs.Add("name", "Tony");
     pvs.Add("age", "48");
     RootObjectDefinition rod = new RootObjectDefinition(typeof(DependenciesObject), pvs, true);
     rod.DependencyCheck = DependencyCheckingMode.Objects;
     rod.AutowireMode = AutoWiringMode.ByType;
     lof.RegisterObjectDefinition("test", rod);
     object singletonObject = new TestObject();
     lof.RegisterSingleton("singletonObject", singletonObject);
     Assert.IsTrue(lof.ContainsObject("singletonObject"));
     Assert.IsTrue(lof.IsSingleton("singletonObject"));
     Assert.AreEqual(0, lof.GetAliases("singletonObject").Count);
     DependenciesObject test = (DependenciesObject)lof.GetObject("test");
     Assert.AreEqual(singletonObject, lof.GetObject("singletonObject"));
     Assert.AreEqual(singletonObject, test.Spouse);
 }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:19,代码来源:DefaultListableObjectFactoryTests.cs

示例2: RegisterExistingSingletonWithReference

        public void RegisterExistingSingletonWithReference()
        {
            DefaultListableObjectFactory lof = new DefaultListableObjectFactory();

            RootObjectDefinition def = new RootObjectDefinition();
            def.ObjectType = typeof(TestObject);
            def.PropertyValues.Add("Name", "Rick");
            def.PropertyValues.Add("Age", 30);
            def.PropertyValues.Add("Spouse", new RuntimeObjectReference("singletonObject"));
            lof.RegisterObjectDefinition("test", def);

            object singletonObject = new TestObject();
            lof.RegisterSingleton("singletonObject", singletonObject);
            Assert.IsTrue(lof.IsSingleton("singletonObject"));
            TestObject test = (TestObject)lof.GetObject("test");
            Assert.AreEqual(singletonObject, lof.GetObject("singletonObject"));
            Assert.AreEqual(singletonObject, test.Spouse);
            IDictionary<string, object> objectsOfType = lof.GetObjectsOfType(typeof(TestObject), false, true);
            Assert.AreEqual(2, objectsOfType.Count);
            Assert.IsTrue(objectsOfType.Values.Contains(test));
            Assert.IsTrue(objectsOfType.Values.Contains(singletonObject));
        }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:22,代码来源:DefaultListableObjectFactoryTests.cs


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