(Available in 1.0)
Most of this section is well traveled territory for those familiar with editing XML files in their favorite XML editor. The XML configuration data that defines the objects that Spring will manage for you are validated against the Spring.NET XML Schema at runtime. The location of the XML configuration data to create an IApplicationContext can be any of the resource locations supported by Spring's IResource abstraction. (See Section 3.11, “The IResource abstraction” for more information.) To create an IApplicationContext using a "standalone" XML configuration file the custom configuration section in the standard .NET application configuration would read:
<spring>
<context>
<resource uri="file://objects.xml"/>
</context>
</spring>
The XML document objects.xml should reference
the Spring.NET XML schema as shown below
<?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="..." type="..."> ... </object> <object id="..." type="..."> ... </object> ... </objects>
To aid XML editors in associating the physical loation of the schema file with the xml document, the attribute xsi:schemaLocation is used. This also requires declaring the XMLSchema-instance namespace. The schema is also in the doc/schema directory of the distribution. The benefits of associating an XML document with a schema are to validate the document and to use editing features such as IntelliSense/content completion assistance.
The XML editor in VS.NET 2002/2003 does not recognize the xsi:schemaLocation as a hint to associate a schema with a XML document. Instead you should add the schema to either your VS.NET project or in your VS.NET installation directory. The VS.NET directory will be either
C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Packages\schemas\xml for VS.NET 2003
or
C:\Program Files\Microsoft Visual Studio .NET\Common7\Packages\schemas\xml for VS.NET 2002
depending on your version of VS.NET. VS.NET 2005 does recognize the xsi:schemaLocation. If you would like to have a local fallback installation of the schema for use when you are not connected to the internet, the VS.NET 2005 directory for XML schemas is
C:\Program Files\Microsoft Visual Studio 8\Common7\Packages\schemas\xml
or similar.
It is typically easier to place the file in the well known location under the VS.NET installation directory than to copy the XSD file for each project you create. As simple aid in this task, you can use the the NAnt build file located in the doc/schema directory that comes with Spring and execute
nant
The default nant target will copy the file spring-object.xsd from the doc/schema directory to the appropriate VS.NET directory.
Once you have registered the schema with VS.NET you can adding only the namespace declaration to the objects element,
<objects xmlns="http://www.springframework.net">
will be enough to get IntelliSense and validation of the configuration file from within VS.NET. Alternatively, you can select the targetSchema property to be Spring.NET Configuration in the Property Sheet for the configuration file.
As shown in the section Section 3.7, “Interacting with the IObjectFactory” Spring.NET supports using .NET's application configuration file as the location to store the object defintions that will be managed by the object factory.
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="config://spring/objects"/>
</context>
<objects xmlns="http://www.springframework.net">
...
</objects>
</spring>
</configuration>
In this case VS.NET will still provide you with IntelliSense help but you will not be able to fully validate the document as the entire schema for App.config is not known the VS.NET (strange isn't that...) To be able to validate this document one would need to install the .NET Configuration File schema and and addition schema that incorporates the <spring> and <context> section in addition to the <objects> would need to be created.
Keep these tradeoffs in mind as you decide where to place the bulk of your configuration information. Conventional wisdom is do quick prototyping with App.config and use another IResource location, file or embedded assembly resource, for serious development.
The schema was updated from Spring 1.0.1 to 1.0.2 in order to support generics. The schema for version 1.0.1 is located under http://www.springframework.net/xsd/1.0.1/ The schema for the latest version will always be located under http://www.springframework.net/xsd/
As part of the installation process the API documentation for Spring.NET is registered with Visual Studio. There are two versions of the documentation, one for VS.NET 2002/2003 and the other for VS.NET 2005. They differ only in the format applied, VS.NET 2005 using the sexy new format. Enjoy!