本文整理汇总了C#中Spring.Objects.Factory.Xml.XmlObjectFactory.GetObject方法的典型用法代码示例。如果您正苦于以下问题:C# XmlObjectFactory.GetObject方法的具体用法?C# XmlObjectFactory.GetObject怎么用?C# XmlObjectFactory.GetObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Spring.Objects.Factory.Xml.XmlObjectFactory
的用法示例。
在下文中一共展示了XmlObjectFactory.GetObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MultiplePatterns
public void MultiplePatterns()
{
IObjectFactory iof = new XmlObjectFactory(new ReadOnlyXmlTestResource("RegularExpressionSetterTests.xml", GetType()));
IPerson advised = (IPerson) iof.GetObject("SettersAndReturnsThisAdvised");
// Interceptor behind regexp advisor
NopInterceptor nop = (NopInterceptor) iof.GetObject("NopInterceptor");
Assert.AreEqual(0, nop.Count);
int newAge = 12;
// Not advised
advised.Exceptional(null);
Assert.AreEqual(0, nop.Count);
// This is proxied
advised.ReturnsThis();
Assert.AreEqual(1, nop.Count);
// Only setter is advised
advised.SetAge(newAge);
Assert.AreEqual(2, nop.Count);
Assert.AreEqual(newAge, advised.GetAge());
Assert.AreEqual(2, nop.Count);
}
示例2: SingletonProxyWithPrototypeTarget
public void SingletonProxyWithPrototypeTarget()
{
TestObjectImpl.constructionCount = 0;
IObjectFactory iof = new XmlObjectFactory(new ReadOnlyXmlTestResource("prototypeTarget.xml", GetType()));
for (int i = 0; i < 10; i++)
{
TestObject to = (TestObject) iof.GetObject("testObjectSingleton");
to.DoSomething();
}
TestInterceptor interceptor = (TestInterceptor) iof.GetObject("testInterceptor");
Assert.AreEqual(1, TestObjectImpl.constructionCount);
Assert.AreEqual(10, interceptor.invocationCount);
}
示例3: PrototypeAndSingletonBehaveDifferently
public void PrototypeAndSingletonBehaveDifferently()
{
int initialCount = 10;
IObjectFactory of = new XmlObjectFactory(new ReadOnlyXmlTestResource("prototypeTargetSourceTests.xml", GetType()));
ISideEffectObject singleton = (ISideEffectObject)of.GetObject("singleton");
Assert.AreEqual(initialCount, singleton.Count);
singleton.doWork();
Assert.AreEqual(initialCount + 1, singleton.Count);
ISideEffectObject prototype = (ISideEffectObject)of.GetObject("prototype");
Assert.AreEqual(initialCount, prototype.Count);
singleton.doWork();
Assert.AreEqual(initialCount, prototype.Count);
ISideEffectObject prototypeByName = (ISideEffectObject)of.GetObject("prototypeByName");
Assert.AreEqual(initialCount, prototypeByName.Count);
singleton.doWork();
Assert.AreEqual(initialCount, prototypeByName.Count);
}
示例4: CanApplyConstructorArgsToAbstractType
public void CanApplyConstructorArgsToAbstractType()
{
IResource resource = new ReadOnlyXmlTestResource("ctor-args.xml", GetType());
XmlObjectFactory xof = new XmlObjectFactory(resource);
TestObject rod = (TestObject)xof.GetObject("rod");
Assert.AreEqual(1, rod.Age);
RootObjectDefinition def = (RootObjectDefinition) xof.GetObjectDefinition("rod");
ConstructorResolver resolver = new ConstructorResolver(xof, xof, new SimpleInstantiationStrategy(),
new ObjectDefinitionValueResolver(xof));
ConstructorInstantiationInfo ci = resolver.GetConstructorInstantiationInfo("rod", def, null, null);
AbstractObjectDefinition objDef = (AbstractObjectDefinition)xof.GetObjectDefinition("foo");
objDef.IsAbstract = false;
TestObject foo = (TestObject) xof.GetObject("foo");
Assert.AreEqual(2, foo.Age);
}
示例5: ReadsReplicasWriteConcernCorrectly
public void ReadsReplicasWriteConcernCorrectly()
{
string xml = @"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net' xmlns:mongo='http://www.springframework.net/mongo'>
<mongo:db-factory id='second' write-concern='W2' />
</objects>";
var factory = new XmlObjectFactory(new StringResource(xml, Encoding.UTF8));
var dbFactory = factory.GetObject<IMongoDatabaseFactory>("second");
var db = dbFactory.GetDatabase();
Assert.That(db.Settings.WriteConcern, Is.EqualTo(WriteConcern.W2));
}
示例6: CreatesDbFactoryBean
public void CreatesDbFactoryBean()
{
string xml = @"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net' xmlns:mongo='http://www.springframework.net/mongo'>
<mongo:mongo url='mongodb://localhost' />
<mongo:db-factory id='first' mongo-ref='Mongo' write-concern='WMajority' />
</objects>";
var factory = new XmlObjectFactory(new StringResource(xml, Encoding.UTF8));
var mongoDatabase = factory.GetObject("first");
Assert.That(mongoDatabase, Is.Not.Null);
}
示例7: TestDifferentCollectionTypes
public void TestDifferentCollectionTypes()
{
const string xml = @"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net' xmlns:v='http://www.springframework.net/validation'>
<v:group id='validatePerson' when='T(Spring.Objects.TestObject) == #this.GetType()'>
<v:required id ='req' when='true' test='Name'/>
<v:regex id ='reg' test='Name'>
<v:property name='Expression' value='[a-z]*\s[a-z]*'/>
<v:property name='Options' value='IgnoreCase'/>
<v:message id='reg1' providers='regularni' when='true'>
<v:param value='#this.ToString()'/>
</v:message>
</v:regex>
</v:group>
<v:collection id='collectionValidator' validate-all='true'>
<v:ref name='validatePerson'/>
</v:collection>
</objects>";
MemoryStream stream = new MemoryStream(new UTF8Encoding().GetBytes(xml));
IResource resource = new InputStreamResource(stream, "collectionValidator");
XmlObjectFactory objectFactory = new XmlObjectFactory(resource, null);
CollectionValidator validator = (CollectionValidator) objectFactory.GetObject("collectionValidator");
IList listPersons = new ArrayList();
IDictionary dictPersons = new Hashtable();
ISet setPersons = new ListSet();
listPersons.Add(new TestObject("DAMJAN Tomic", 24));
listPersons.Add(new TestObject("Goran Milosavljevic", 24));
listPersons.Add(new TestObject("Ivan CIKIC", 28));
dictPersons.Add(1, listPersons[0]);
dictPersons.Add(2, listPersons[1]);
dictPersons.Add(3, listPersons[2]);
setPersons.AddAll(listPersons);
IValidationErrors ve = new ValidationErrors();
Assert.IsTrue(validator.Validate(listPersons, ve));
Assert.IsTrue(ve.IsEmpty);
Assert.IsTrue(validator.Validate(dictPersons, ve));
Assert.IsTrue(ve.IsEmpty);
Assert.IsTrue(validator.Validate(setPersons, ve));
Assert.IsTrue(ve.IsEmpty);
}
示例8: ISBNValidatorTests
public void ISBNValidatorTests()
{
const string xml = @"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net' xmlns:v='http://www.springframework.net/validation'>
<v:validator id='urlValidator' test='#this' type='Spring.Validation.Validators.UrlValidator, Spring.Core'/>
</objects>";
MemoryStream stream = new MemoryStream(new UTF8Encoding().GetBytes(xml));
IResource resource = new InputStreamResource(stream, "urlValidator");
XmlObjectFactory objectFactory = new XmlObjectFactory(resource, null);
object obj = objectFactory.GetObject("urlValidator");
Assert.IsTrue(obj is IValidator);
IValidator validator = obj as IValidator;
Assert.IsTrue(validator.Validate("http://www.springframework.net", new ValidationErrors()));
}
示例9: DoesntCallContextRegistryForLocalObjectFactoryReferences
public void DoesntCallContextRegistryForLocalObjectFactoryReferences()
{
string xml = string.Format(
@"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net'>
<object id='foo' type='{0}'>
<property name='MyField' expression='@(theObject)' />
</object>
</objects>"
, typeof(MyTestObject).AssemblyQualifiedName
);
XmlObjectFactory of = new XmlObjectFactory(new StringResource(xml, Encoding.UTF8));
object theObject = new object();
of.RegisterSingleton("theObject", theObject);
MyTestObject to = (MyTestObject) of.GetObject("foo");
Assert.AreSame( theObject, to.MyField );
}
示例10: ISBNValidatorTests
public void ISBNValidatorTests()
{
const string xml = @"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net' xmlns:v='http://www.springframework.net/validation'>
<v:validator id='isbnValidator' test='#this' type='Spring.Validation.Validators.ISBNValidator, Spring.Core'>
<v:message id='error.airportCode.dummy' providers='summary' when='false'/>
</v:validator>
</objects>";
MemoryStream stream = new MemoryStream(new UTF8Encoding().GetBytes(xml));
IResource resource = new InputStreamResource(stream, "isbnValidator");
XmlObjectFactory objectFactory = new XmlObjectFactory(resource, null);
object obj = objectFactory.GetObject("isbnValidator");
Assert.IsTrue(obj is IValidator);
IValidator validator = obj as IValidator;
Assert.IsTrue(validator.Validate("978-1-905158-79-9", new ValidationErrors()));
}
示例11: WithNullCardType
public void WithNullCardType()
{
const string xml = @"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net' xmlns:v='http://www.springframework.net/validation'>
<v:validator id='ccValidator' test='#this' type='Spring.Validation.Validators.CreditCardValidator, Spring.Core'>
<v:message id='error.airportCode.dummy' providers='summary' when='false'/>
</v:validator>
</objects>";
MemoryStream stream = new MemoryStream(new UTF8Encoding().GetBytes(xml));
IResource resource = new InputStreamResource(stream, "ccValidator");
XmlObjectFactory objectFactory = new XmlObjectFactory(resource, null);
object obj = objectFactory.GetObject("ccValidator");
Assert.IsTrue(obj is CreditCardValidator);
CreditCardValidator validator = obj as CreditCardValidator;
Assert.IsNull(validator.CardType);
Assert.IsTrue(validator.Validate("378282246310005", new ValidationErrors()));
}
示例12: AbstractParentObjects
public void AbstractParentObjects()
{
XmlObjectFactory parent = new XmlObjectFactory(new ReadOnlyXmlTestResource("parent.xml", GetType()));
parent.PreInstantiateSingletons();
Assert.IsTrue(parent.IsSingleton("inheritedTestObjectWithoutClass"));
// abstract objects should not match
//TODO add overloaded GetObjectOfType with 1 arg
IDictionary tbs = parent.GetObjectsOfType(typeof(TestObject), true, true);
Assert.AreEqual(2, tbs.Count);
Assert.IsTrue(tbs.Contains("inheritedTestObjectPrototype"));
Assert.IsTrue(tbs.Contains("inheritedTestObjectSingleton"));
// non-abstract object should work, even if it serves as parent
object o1 = parent.GetObject("inheritedTestObjectPrototype");
Assert.IsTrue(o1 is TestObject);
// abstract object should return IObjectInstance itself
object o2 = parent.GetObject("inheritedTestObjectWithoutClass");
Assert.IsTrue(o2 is IObjectDefinition);
}
示例13: LocaleTest
public void LocaleTest()
{
CultureInfo oldCulture = Thread.CurrentThread.CurrentCulture;
try
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
IResource resource = new ReadOnlyXmlTestResource("locale.xml", GetType());
XmlObjectFactory xof = new XmlObjectFactory(resource);
TestObject to = xof.GetObject("jenny") as TestObject;
Assert.IsNotNull(to);
DateTime d = new DateTime(2007, 10, 30);
Assert.AreEqual(d, to.Date);
Assert.AreEqual(30, to.Size.Height);
Assert.AreEqual(30, to.Size.Width);
}
finally
{
Thread.CurrentThread.CurrentCulture = oldCulture;
}
}
示例14: DefaultDestroyMethodDisabled
public void DefaultDestroyMethodDisabled()
{
IResource resource = new ReadOnlyXmlTestResource("default-destroy-methods.xml", GetType());
XmlObjectFactory xof = new XmlObjectFactory(resource);
xof.PreInstantiateSingletons();
DefaultDestroyer dd = (DefaultDestroyer)xof.GetObject("destroy-method2");
Assert.IsTrue(!dd.customDestroyed);
xof.Dispose();
Assert.IsTrue(!dd.customDestroyed);
}
示例15: FactoryReferenceCircle
public void FactoryReferenceCircle()
{
IResource resource = new ReadOnlyXmlTestResource("factoryCircle.xml", GetType());
XmlObjectFactory xof = new XmlObjectFactory(resource);
TestObject tb = (TestObject) xof.GetObject("singletonFactory");
DummyFactory db = (DummyFactory) xof.GetObject("&singletonFactory");
Assert.IsTrue(tb == db.OtherTestObject);
}