コード例 #1
0
 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);
 }