本文整理汇总了C#中Spring.Objects.Factory.Xml.XmlObjectDefinitionReader类的典型用法代码示例。如果您正苦于以下问题:C# XmlObjectDefinitionReader类的具体用法?C# XmlObjectDefinitionReader怎么用?C# XmlObjectDefinitionReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlObjectDefinitionReader类属于Spring.Objects.Factory.Xml命名空间,在下文中一共展示了XmlObjectDefinitionReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadObjectDefinitionsWithNullResource
public void LoadObjectDefinitionsWithNullResource()
{
XmlObjectDefinitionReader reader
= new XmlObjectDefinitionReader(
new DefaultListableObjectFactory());
reader.LoadObjectDefinitions((string)null);
}
示例2: LoadObjectDefinitionsWithNonExistentResource
public void LoadObjectDefinitionsWithNonExistentResource()
{
XmlObjectDefinitionReader reader
= new XmlObjectDefinitionReader(
new DefaultListableObjectFactory());
reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("/dev/null"));
}
示例3: InstanceEventWiring
public virtual void InstanceEventWiring()
{
DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(factory);
reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("event-wiring.xml", GetType()));
ITestObject source = factory["source"] as ITestObject;
TestEventHandler instanceHandler = factory["instanceEventListener"] as TestEventHandler;
// raise the event... handlers should be notified at this point (obviously)
source.OnClick();
Assert.IsTrue(instanceHandler.EventWasHandled,
"The instance handler did not get notified when the instance event was raised (and was probably not wired up in the first place).");
}
示例4: InitObjectDefinitionReader
/// <summary>
/// Initialize the object definition reader used for loading the object
/// definitions of this context.
/// </summary>
/// <remarks>
/// <p>
/// The default implementation of this method is a no-op; i.e. it does
/// nothing. Can be overridden in subclasses to provide custom
/// initialization of the supplied
/// <paramref name="objectDefinitionReader"/>; for example, a derived
/// class may want to turn off XML validation.
/// </p>
/// </remarks>
/// <param name="objectDefinitionReader">
/// The object definition reader used by this context.
/// </param>
protected virtual void InitObjectDefinitionReader(
XmlObjectDefinitionReader objectDefinitionReader)
{ }
示例5: LoadObjectDefinitions
protected override void LoadObjectDefinitions(XmlObjectDefinitionReader objectDefinitionReader)
{
base.LoadObjectDefinitions(objectDefinitionReader);
objectDefinitionReader.LoadObjectDefinitions(configurationResources);
}
示例6: SimpleReader
public void SimpleReader()
{
GenericApplicationContext applicationContext = new GenericApplicationContext();
IObjectDefinitionReader objectDefinitionReader = new XmlObjectDefinitionReader(applicationContext);
objectDefinitionReader.LoadObjectDefinitions("assembly://foo");
applicationContext.Refresh();
}
示例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");
}
示例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);
}
示例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.");
}
示例10: FactoryMethodsOnExternalClass
public void FactoryMethodsOnExternalClass()
{
DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(factory);
reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("factory-methods.xml", GetType()));
TestObject to = (TestObject) factory["externalFactoryMethodWithoutArgs"];
Assert.AreEqual(2, to.Age);
Assert.AreEqual("Tristan", to.Name);
to = (TestObject) factory["externalFactoryMethodWithArgs"];
Assert.AreEqual(33, to.Age);
Assert.AreEqual("Rod", to.Name);
}
示例11: FactoryMethodsPrototypeOnTargetClass
public void FactoryMethodsPrototypeOnTargetClass()
{
DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(factory);
reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("factory-methods.xml", GetType()));
FactoryMethods fm = (FactoryMethods) factory["defaultPrototype"];
FactoryMethods fm2 = (FactoryMethods) factory["defaultPrototype"];
Assert.AreEqual(0, fm.Number);
Assert.AreEqual("default", fm.Name);
Assert.AreEqual("defaultInstance", fm.Object.Name);
Assert.AreEqual("setterString", fm.Value);
Assert.AreEqual(fm.Number, fm2.Number);
Assert.AreEqual(fm.Value, fm2.Value);
// The TestObject is created separately for each object
Assert.IsFalse(ReferenceEquals(fm.Object, fm2.Object));
Assert.IsFalse(ReferenceEquals(fm, fm2));
fm = (FactoryMethods) factory["testObjectOnlyPrototype"];
fm2 = (FactoryMethods) factory["testObjectOnlyPrototype"];
Assert.AreEqual(0, fm.Number);
Assert.AreEqual("default", fm.Name);
// This comes from the test object
Assert.AreEqual("Juergen", fm.Object.Name);
Assert.AreEqual(fm.Number, fm2.Number);
Assert.AreEqual(fm.Value, fm2.Value);
// The TestObject reference is resolved to a prototype in the factory
Assert.AreSame(fm.Object, fm2.Object);
Assert.IsFalse(ReferenceEquals(fm, fm2));
fm = (FactoryMethods) factory["fullPrototype"];
fm2 = (FactoryMethods) factory["fullPrototype"];
Assert.AreEqual(27, fm.Number);
Assert.AreEqual("gotcha", fm.Name);
Assert.AreEqual("Juergen", fm.Object.Name);
Assert.AreEqual(fm.Number, fm2.Number);
Assert.AreEqual(fm.Value, fm2.Value);
// The TestObject reference is resolved to a prototype in the factory
Assert.AreSame(fm.Object, fm2.Object);
Assert.IsFalse(ReferenceEquals(fm, fm2));
}
示例12: FactoryMethodsSingletonOnTargetClass
public void FactoryMethodsSingletonOnTargetClass()
{
DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(factory);
reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("factory-methods.xml", GetType()));
FactoryMethods fm = (FactoryMethods) factory["default"];
Assert.AreEqual(0, fm.Number);
Assert.AreEqual("default", fm.Name);
Assert.AreEqual("defaultInstance", fm.Object.Name);
Assert.AreEqual("setterString", fm.Value);
fm = (FactoryMethods) factory["testObjectOnly"];
Assert.AreEqual(0, fm.Number);
Assert.AreEqual("default", fm.Name);
// This comes from the test object
Assert.AreEqual("Juergen", fm.Object.Name);
fm = (FactoryMethods) factory["full"];
Assert.AreEqual(27, fm.Number);
Assert.AreEqual("gotcha", fm.Name);
Assert.AreEqual("Juergen", fm.Object.Name);
FactoryMethods fm2 = (FactoryMethods) factory["full"];
Assert.AreSame(fm, fm2);
}
示例13: DefaultXmlResolverIsUsedIfNullSuppliedOrSet
public void DefaultXmlResolverIsUsedIfNullSuppliedOrSet()
{
DefaultListableObjectFactory xof = new DefaultListableObjectFactory();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(xof, null);
try
{
reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("invalid.xml", GetType()));
Assert.Fail("Should have thrown XmlObjectDefinitionStoreException");
}
catch (ObjectDefinitionStoreException e)
{
Assert.AreEqual(0, e.Message.IndexOf("Line 21 in XML document"));
}
}
示例14: GenericApplicationContextWithXmlObjectDefinitions
public void GenericApplicationContextWithXmlObjectDefinitions()
{
GenericApplicationContext ctx = new GenericApplicationContext();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(ctx);
reader.LoadObjectDefinitions("assembly://Spring.Core.Tests/Spring.Context.Support/contextB.xml");
reader.LoadObjectDefinitions("assembly://Spring.Core.Tests/Spring.Context.Support/contextC.xml");
reader.LoadObjectDefinitions("assembly://Spring.Core.Tests/Spring.Context.Support/contextA.xml");
ctx.Refresh();
Assert.IsTrue(ctx.ContainsObject("service"));
Assert.IsTrue(ctx.ContainsObject("logicOne"));
Assert.IsTrue(ctx.ContainsObject("logicTwo"));
ctx.Dispose();
}
示例15: 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));
}