本文整理汇总了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);
}
示例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));
}