Spring.NET 1.3.0 RC1 for .NET 2.0 API Reference

ContextHandler Class

Creates an IApplicationContext instance using context definitions supplied in a custom configuration and configures the ContextRegistry with that instance.

For a list of all members of this type, see ContextHandler Members .

System.Object
   ContextHandler
      WebContextHandler
      ServicedComponentContextHandler

[Visual Basic]
Public Class ContextHandler
    Implements IConfigurationSectionHandler
[C#]
public class ContextHandler : IConfigurationSectionHandler

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

Implementations of the IApplicationContext interface must provide the following two constructors:

  1. A constructor that takes a string array of resource locations.
  2. A constructor that takes a reference to a parent application context and a string array of resource locations (and in that order).

Note that if the type attribute is not present in the declaration of a particular context, then a default IApplicationContextType is assumed. This default IApplicationContextType is currently the XmlApplicationContextType; please note the exact Type of this default IApplicationContext is an implementation detail, that, while unlikely, may do so in the future. to

Example

This is an example of specifying a context that reads its resources from an embedded Spring.NET XML object configuration file...

  <configuration>
    <configSections>
      <sectionGroup name="spring">
        <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
      </sectionGroup>
    </configSections>
    <spring>
      <context>
        <resource uri="assembly://MyAssemblyName/MyResourceNamespace/MyObjects.xml" />
      </context>
    </spring>
  </configuration>

This is an example of specifying a context that reads its resources from a custom configuration section within the same application / web configuration file and uses case insensitive object lookups.

Please note that you must adhere to the naming of the various sections (i.e. '<sectionGroup name="spring">' and '<section name="context">'.

  <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 caseSensitive="false" type="Spring.Context.Support.XmlApplicationContext, Spring.Core">
        <resource uri="config://spring/objects" />
      </context>
      <objects xmlns="http://www.springframework.net">
        <!-- object definitions... -->
      </objects>
    </spring>
  </configuration>

And this is an example of specifying a hierarchy of contexts. The hierarchy in this case is only a simple parent->child hierarchy, but hopefully it illustrates the nesting of context configurations. This nesting of contexts can be arbitrarily deep, and is one way... child contexts know about their parent contexts, but parent contexts do not know how many child contexts they have (if any), or have references to any such child contexts.

  <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 name="child">
          <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
        </sectionGroup>
      </sectionGroup>
    </configSections>
    <spring>
      <context name="Parent">
        <resource uri="config://spring/objects" />
        <context name="Child">
          <resource uri="config://spring/childObjects" />
        </context>
      </context>
      <!-- parent context's objects -->
      <objects xmlns="http://www.springframework.net">
        <object id="Parent" type="Spring.Objects.TestObject,Spring.Core.Tests">
          <property name="name" value="Parent" />
        </object>
      </objects>
      <!-- child context's objects -->
      <child>
        <objects xmlns="http://www.springframework.net">
          <object id="Child" type="Spring.Objects.TestObject,Spring.Core.Tests">
            <property name="name" value="Child" />
          </object>
        </objects>
      </child>
    </spring>
  </configuration>

Requirements

Namespace: Spring.Context.Support

Assembly: Spring.Core (in Spring.Core.dll)

See Also

ContextHandler Members | Spring.Context.Support Namespace | ContextRegistry