本文整理汇总了C#中Spring.Objects.Factory.Xml.XmlObjectFactory类的典型用法代码示例。如果您正苦于以下问题:C# XmlObjectFactory类的具体用法?C# XmlObjectFactory怎么用?C# XmlObjectFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlObjectFactory类属于Spring.Objects.Factory.Xml命名空间,在下文中一共展示了XmlObjectFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetUp
public void SetUp()
{
IObjectFactory grandparent = new XmlObjectFactory(new ReadOnlyXmlTestResource("root.xml", GetType()));
IObjectFactory parent = new XmlObjectFactory(new ReadOnlyXmlTestResource("middle.xml", GetType()), grandparent);
IConfigurableListableObjectFactory child = new XmlObjectFactory(new ReadOnlyXmlTestResource("leaf.xml", GetType()), parent);
_factory = child;
}
示例2: 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);
}
示例3: Setup
public void Setup()
{
NamespaceParserRegistry.RegisterParser(typeof(RabbitNamespaceHandler));
var resourceName = @"assembly://Spring.Messaging.Amqp.Rabbit.Tests/Spring.Messaging.Amqp.Rabbit.Tests.Config/" + typeof(ConnectionFactoryParserTests).Name + "-context.xml";
var resource = new AssemblyResource(resourceName);
this.objectFactory = new XmlObjectFactory(resource);
}
示例4: ConfigureIoC
private void ConfigureIoC()
{
IResource input = new FileSystemResource(Server.MapPath("objects.xml"));
IObjectFactory factory = new XmlObjectFactory(input);
DependencyResolver.InitializeWith(new SpringDependencyResolver(factory));
ControllerBuilder.Current.SetControllerFactory(typeof(IoCControllerFactory));
}
示例5: Setup
public void Setup()
{
NamespaceParserRegistry.RegisterParser(typeof(RabbitNamespaceHandler));
var resourceName = @"assembly://Spring.Messaging.Amqp.Rabbit.Tests/Spring.Messaging.Amqp.Rabbit.Tests.Config/" + typeof(ListenerContainerParserTests).Name + "-context.xml";
var resource = new AssemblyResource(resourceName);
this.objectFactory = new XmlObjectFactory(resource);
// ((IConfigurableObjectFactory)objectFactory).setObjectExpressionResolver(new StandardObjectExpressionResolver());
}
示例6: 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));
}
示例7: 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);
}
示例8: 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);
}
示例9: SetUp
public void SetUp()
{
const string xml =
@"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net'>
<object id='noDecoratedService' type='Spring.Web.Services.WebServiceExporterTests+NoDecoratedService, Spring.Web.Tests'/>
<object id='decoratedService' type='Spring.Web.Services.WebServiceExporterTests+DecoratedService, Spring.Web.Tests'/>
</objects>";
Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(xml));
IObjectFactory objectFactory = new XmlObjectFactory(new InputStreamResource(stream, string.Empty));
wse = new WebServiceExporter();
wse.ObjectFactory = objectFactory;
}
示例10: RejectsConnectStringPlusDetailedConfiguration
public void RejectsConnectStringPlusDetailedConfiguration()
{
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 url='mongodb://localhost/database' username='username' password='password'/>
</objects>";
Assert.That(
delegate
{
var factory = new XmlObjectFactory(new StringResource(xml, Encoding.UTF8));
},
Throws.TypeOf<ObjectDefinitionStoreException>());
}
示例11: 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);
}
示例12: 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()));
}
示例13: SetUp
public void SetUp()
{
const string xml =
@"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net'>
<object id='service' type='Spring.ServiceModel.ServiceExporterTests+Service, Spring.Services.Tests'/>
<object id='serviceWithMultipleInterfaces' type='Spring.ServiceModel.ServiceExporterTests+ServiceWithMultipleInterfaces, Spring.Services.Tests'/>
<object id='decoratedService' type='Spring.ServiceModel.ServiceExporterTests+DecoratedService, Spring.Services.Tests'/>
<object id='anotherService' type='Spring.ServiceModel.ServiceExporterTests+AnotherService, Spring.Services.Tests'/>
</objects>";
using (Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
{
IObjectFactory objectFactory = new XmlObjectFactory(new InputStreamResource(stream, string.Empty));
se = new ServiceExporter();
se.ObjectFactory = objectFactory;
}
}
示例14: Setup
public override void Setup()
{
string objectXml = "<?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=\"SimpleDependency\" singleton=\"false\" type=\"MvcContrib.UnitTests.IoC.SimpleDependency\"/> " +
" <object id=\"NestedDependency\" singleton=\"false\" type=\"MvcContrib.UnitTests.IoC.NestedDependency\" > " +
" <constructor-arg> " +
" <object type=\"MvcContrib.UnitTests.IoC.SimpleDependency\" /> " +
" </constructor-arg> " +
" </object> " +
" </objects>";
Stream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(objectXml));
IResource resource = new InputStreamResource(stream, "In memory xml");
IObjectFactory factory = new XmlObjectFactory(resource);
_dependencyResolver = new SpringDependencyResolver(factory);
}
示例15: 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 );
}