/// <summary> /// Load the object definitions with the given /// <see cref="Spring.Objects.Factory.Xml.XmlObjectDefinitionReader"/>. /// </summary> /// <remarks> /// <p> /// The lifecycle of the object factory is handled by /// <see cref="Spring.Context.Support.AbstractXmlApplicationContext.RefreshObjectFactory"/>; /// therefore this method is just supposed to load and / or register /// object definitions. /// </p> /// </remarks> /// <param name="objectDefinitionReader"> /// The reader containing object definitions.</param> /// <exception cref="ObjectsException"> /// In case of object registration errors. /// </exception> /// <exception cref="Spring.Objects.ObjectsException"> /// In the case of errors encountered reading any of the resources /// yielded by either the <see cref="ConfigurationLocations"/> or /// the <see cref="ConfigurationResources"/> methods. /// </exception> protected virtual void LoadObjectDefinitions(XmlObjectDefinitionReader objectDefinitionReader) { string[] locations = ConfigurationLocations; if (locations != null) { objectDefinitionReader.LoadObjectDefinitions(locations); } IResource[] resources = ConfigurationResources; if (resources != null) { objectDefinitionReader.LoadObjectDefinitions(resources); } }
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(); }
/// <summary> /// Load the object definitions with the given /// <see cref="Oragon.Spring.Objects.Factory.Xml.XmlObjectDefinitionReader"/>. /// </summary> /// <remarks> /// <p> /// The lifecycle of the object factory is handled by /// <see cref="Oragon.Spring.Context.Support.AbstractXmlApplicationContext.RefreshObjectFactory"/>; /// therefore this method is just supposed to load and / or register /// object definitions. /// </p> /// </remarks> /// <param name="objectDefinitionReader"> /// The reader containing object definitions.</param> /// <exception cref="ObjectsException"> /// In case of object registration errors. /// </exception> /// <exception cref="Oragon.Spring.Objects.ObjectsException"> /// In the case of errors encountered reading any of the resources /// yielded by either the <see cref="ConfigurationLocations"/> or /// the <see cref="ConfigurationResources"/> methods. /// </exception> protected virtual void LoadObjectDefinitions(XmlObjectDefinitionReader objectDefinitionReader) { IEnumerable <string> locations = ConfigurationLocations; if (locations != null) { objectDefinitionReader.LoadObjectDefinitions(locations.ToArray()); } IResource[] resources = ConfigurationResources; if (resources != null) { objectDefinitionReader.LoadObjectDefinitions(resources); } }
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='Oragon.Spring.Objects.Factory.SPRNET_1334+ParentClass, Oragon.Spring.Core.Tests'> <property name='Name' value='Foo!'/> <property name='InnerObject'> <object type='Oragon.Spring.Objects.Factory.SPRNET_1334+DisposableClass, Oragon.Spring.Core.Tests'/> </property> </object> <!-- <object id='Parent' type='Oragon.Spring.Objects.Factory.SPRNET_1334+ParentClass, Oragon.Spring.Core.Tests'> <property name='Name' value='Foo!'/> <property name='InnerObject' ref='Inner'/> </object> <object id='Inner' type='Oragon.Spring.Objects.Factory.SPRNET_1334+DisposableClass, Oragon.Spring.Core.Tests'/> --> </objects> ")); }
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); } } }
public void SimpleReader() { GenericApplicationContext applicationContext = new GenericApplicationContext(); IObjectDefinitionReader objectDefinitionReader = new XmlObjectDefinitionReader(applicationContext); objectDefinitionReader.LoadObjectDefinitions("assembly://foo"); applicationContext.Refresh(); }
private static AbstractApplicationContext GetAbstractApplicationContext() { if (!ContextRegistry.IsContextRegistered(_RootContext)) { lock (lock_init) { if (!ContextRegistry.IsContextRegistered(_RootContext)) { GenericApplicationContext ctx = new GenericApplicationContext(); ctx.Name = _RootContext; XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(ctx); reader.LoadObjectDefinitions(new StringResource("<?xml version=\"1.0\" encoding=\"utf-8\" ?><objects></objects>")); ContextRegistry.RegisterContext(ctx); } } } return(ContextRegistry.GetContext(_RootContext) as AbstractApplicationContext); }
private static IApplicationContext CreateContextMixXmlAndProgrammatic() { GenericApplicationContext ctx = new GenericApplicationContext(); IObjectDefinitionReader objectDefinitionReader = new XmlObjectDefinitionReader(ctx); objectDefinitionReader.LoadObjectDefinitions("assembly://Spring.IocQuickStart.MovieFinder/Spring.IocQuickStart.MovieFinder/AppContextContribution.xml"); IObjectDefinitionFactory objectDefinitionFactory = new DefaultObjectDefinitionFactory(); ObjectDefinitionBuilder builder = ObjectDefinitionBuilder.RootObjectDefinition(objectDefinitionFactory, typeof(ColonDelimitedMovieFinder)); builder.AddConstructorArg("movies.txt"); ctx.RegisterObjectDefinition("AnotherMovieFinder", builder.ObjectDefinition); ctx.Refresh(); return(ctx); }
public void ThrowsCannotLoadObjectTypeExceptionOnInvalidTypename() { try { MockApplicationContext myContext = new MockApplicationContext("myContext"); DefaultListableObjectFactory objectFactory = (DefaultListableObjectFactory)myContext.ObjectFactory; XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(objectFactory); reader.LoadObjectDefinitions(new StringResource( @"<?xml version='1.0' encoding='UTF-8' ?> <objects xmlns='http://www.springframework.net'> <object id='test2' type='DOESNOTEXIST' /> </objects> ")); myContext.Refresh(); } catch (Exception e) { // Console.WriteLine(e); Assert.IsInstanceOf(typeof(CannotLoadObjectTypeException), e); } }
protected override void LoadObjectDefinitions(XmlObjectDefinitionReader objectDefinitionReader) { base.LoadObjectDefinitions(objectDefinitionReader); objectDefinitionReader.LoadObjectDefinitions(configurationResources); }