本文整理汇总了C#中Spring.Objects.Factory.Xml.XmlObjectDefinitionReader.LoadObjectDefinitions方法的典型用法代码示例。如果您正苦于以下问题:C# XmlObjectDefinitionReader.LoadObjectDefinitions方法的具体用法?C# XmlObjectDefinitionReader.LoadObjectDefinitions怎么用?C# XmlObjectDefinitionReader.LoadObjectDefinitions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Spring.Objects.Factory.Xml.XmlObjectDefinitionReader
的用法示例。
在下文中一共展示了XmlObjectDefinitionReader.LoadObjectDefinitions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadObjectDefinitionsWithNonExistentResource
public void LoadObjectDefinitionsWithNonExistentResource()
{
XmlObjectDefinitionReader reader
= new XmlObjectDefinitionReader(
new DefaultListableObjectFactory());
reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("/dev/null"));
}
示例2: LoadObjectDefinitionsWithNullResource
public void LoadObjectDefinitionsWithNullResource()
{
XmlObjectDefinitionReader reader
= new XmlObjectDefinitionReader(
new DefaultListableObjectFactory());
reader.LoadObjectDefinitions((string)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: ParsesObjectAttributes
public void ParsesObjectAttributes()
{
DefaultListableObjectFactory of = new DefaultListableObjectFactory();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(of);
reader.LoadObjectDefinitions(new StringResource(
@"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net'>
<object id='test1' type='Spring.Objects.TestObject, Spring.Core.Tests' singleton='false' abstract='true' />
<object id='test2' type='Spring.Objects.TestObject, Spring.Core.Tests' singleton='true' abstract='false' lazy-init='true'
autowire='no' dependency-check='simple'
depends-on='test1'
init-method='init'
destroy-method='destroy'
/>
</objects>
"));
AbstractObjectDefinition od1 = (AbstractObjectDefinition)of.GetObjectDefinition("test1");
Assert.IsFalse(od1.IsSingleton);
Assert.IsTrue(od1.IsAbstract);
Assert.IsFalse(od1.IsLazyInit);
AbstractObjectDefinition od2 = (AbstractObjectDefinition)of.GetObjectDefinition("test2");
Assert.IsTrue(od2.IsSingleton);
Assert.IsFalse(od2.IsAbstract);
Assert.IsTrue(od2.IsLazyInit);
Assert.AreEqual(AutoWiringMode.No, od2.AutowireMode);
Assert.AreEqual("init", od2.InitMethodName);
Assert.AreEqual("destroy", od2.DestroyMethodName);
Assert.AreEqual(1, od2.DependsOn.Length);
Assert.AreEqual("test1", od2.DependsOn[0]);
Assert.AreEqual(DependencyCheckingMode.Simple, od2.DependencyCheck);
}
示例5: ThrowsTypeLoadExceptionIfProxyInterfacesValueIsSpecifiedInsteadOfListElement
public void ThrowsTypeLoadExceptionIfProxyInterfacesValueIsSpecifiedInsteadOfListElement()
{
using (DefaultListableObjectFactory of = new DefaultListableObjectFactory())
{
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(of);
reader.LoadObjectDefinitions(new StringResource(
@"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net' xmlns:r='http://www.springframework.net/remoting'>
<r:saoExporter id='ISimpleCounterExporter' targetName='ISimpleCounterProxy' serviceName='RemotedSaoCounterProxy' />
<object id='ISimpleCounter' type='Spring.Remoting.SimpleCounter, Spring.Services.Tests' />
<object id='ISimpleCounterProxy' type='Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop'>
<property name='proxyInterfaces' value='Spring.Remoting.ISimpleCounter, Spring.Services.Tests' />
<property name='target' ref='ISimpleCounter'/>
</object>
</objects>
"));
try
{
SaoExporter saoExporter = (SaoExporter) of.GetObject("ISimpleCounterExporter");
Assert.Fail();
}
catch (ObjectCreationException oce)
{
TypeLoadException tle = (TypeLoadException) oce.GetBaseException();
Assert.AreEqual("Could not load type from string value ' Spring.Services.Tests'.", tle.Message);
}
}
}
示例6: ConfigureObjectFactory
private void ConfigureObjectFactory(IObjectDefinitionRegistry factory)
{
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(factory);
reader.LoadObjectDefinitions(new StringResource(@"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd'>
<object id='Parent' type='Spring.Objects.Factory.SPRNET_1334+ParentClass, Spring.Core.Tests'>
<property name='Name' value='Foo!'/>
<property name='InnerObject'>
<object type='Spring.Objects.Factory.SPRNET_1334+DisposableClass, Spring.Core.Tests'/>
</property>
</object>
<!--
<object id='Parent' type='Spring.Objects.Factory.SPRNET_1334+ParentClass, Spring.Core.Tests'>
<property name='Name' value='Foo!'/>
<property name='InnerObject' ref='Inner'/>
</object>
<object id='Inner' type='Spring.Objects.Factory.SPRNET_1334+DisposableClass, Spring.Core.Tests'/>
-->
</objects>
"));
}
示例7: EnumProperty
public void EnumProperty()
{
DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(factory);
reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("enums.xml", GetType()));
TestObject obj = factory.GetObject("rod", typeof(TestObject)) as TestObject;
Assert.IsNotNull(obj.FileMode);
Assert.AreEqual(FileMode.Create, obj.FileMode);
}
示例8: InnerObjectsInPrototype
public void InnerObjectsInPrototype()
{
DefaultListableObjectFactory xof = new DefaultListableObjectFactory();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(xof);
reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("reftypes.xml", GetType()));
TestObject hasInnerObjects = (TestObject) xof.GetObject("prototypeHasInnerObjects");
Assert.AreEqual(5, hasInnerObjects.Age);
Assert.IsNotNull(hasInnerObjects.Spouse);
Assert.AreEqual("inner1", hasInnerObjects.Spouse.Name);
Assert.AreEqual(6, hasInnerObjects.Spouse.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);
IList friendsOfInner = (IList) inner2.Friends;
Assert.AreEqual(1, friendsOfInner.Count);
DerivedTestObject innerFriendOfAFriend = (DerivedTestObject) friendsOfInner[0];
Assert.AreEqual("innerFriendOfAFriend", innerFriendOfAFriend.Name);
Assert.AreEqual(7, innerFriendOfAFriend.Age);
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("inner3", inner3.Name);
Assert.AreEqual(8, inner3.Age);
xof.Dispose();
Assert.IsFalse(inner2.WasDestroyed());
Assert.IsFalse(innerFactory.Name == null);
Assert.IsFalse(innerFriendOfAFriend.WasDestroyed());
}
示例9: RefToSingleton
public void RefToSingleton()
{
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 jen = (TestObject) xof.GetObject("jenny");
TestObject dave = (TestObject) xof.GetObject("david");
TestObject jenks = (TestObject) xof.GetObject("jenks");
ITestObject davesJen = dave.Spouse;
ITestObject jenksJen = jenks.Spouse;
Assert.IsTrue(davesJen == jenksJen, "1 jen instance");
Assert.IsTrue(davesJen == jen, "1 jen instance");
}
示例10: DescriptionButNoProperties
public void DescriptionButNoProperties()
{
DefaultListableObjectFactory xof = new DefaultListableObjectFactory();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(xof);
reader.LoadObjectDefinitions(
new ReadOnlyXmlTestResource("collections.xml", GetType()));
TestObject validEmpty
= (TestObject) xof.GetObject("validEmptyWithDescription");
Assert.AreEqual(0, validEmpty.Age);
}
示例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: InstanceFieldRetrievingFactoryMethod
public void InstanceFieldRetrievingFactoryMethod()
{
DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(factory);
reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("field-props-factory.xml", GetType()));
MyTestObject obj = factory.GetObject("instanceCultureAware", typeof(MyTestObject)) as MyTestObject;
Assert.IsNotNull(obj.Culture);
Assert.AreEqual(new MyTestObject().Default, obj.Culture);
}