This project is read-only.

The XmlConfigurationReader Class

The Drill.Configuration.XmlConfigurationReader class is used to read Drill configuration XML from various sources including XML files, streams, XDocument instances, manifest resources and strings. The Drill configuration XML that is parsed by the XmlConfigurationReader class can be less structured than that required by .NET config files.

Creating an instance of XmlConfigurationReader

An instance of the XmlConfigurationReader can be created by using on of the static "From" methods. The XmlConfigurationReader class does not expose a public constructor. The methods used to create an instance of the XmlConfigurationReader class are outlined below:
  • FromFile(string filename) - This method is used to create a new XmlConfigurationReader instance that reads the Drill configuration XML from a file (or URI). This method uses an underlying XDocument instance to read the XML and is not designed for very large files.
  • FromManifestResource(string manifestResourceName, Assembly assembly = null) - This method is used to create a new XmlConfigurationReader instance that reads the Drill configuration XML from an embedded manifest resource using the specified resource name in the specified assembly. If an assembly is not specified, the assembly of the caller of FromManifestResource is used. This method is useful when Drill is used in class library where it may not be appropriate to have the Drill confiugration reside in an external file.
  • FromStream(Stream stream) - This method is used to create a new XmlConfigurationReader instance that reads the Drill configuration XML from a stream.
  • FromXDocument(XDocument xdocument) - This method is used to create a new XmlConfigurationReader instance that reads the Drill configuration XML from an XDocument instance.
  • FromXmlString(string xml) - This method is used to create a new XmlConfigurationReader instance that reads the Drill configuration XML from a string containing Drill configuration XML.

Using XmlConfigurationReader

Once an XmlConfigurationReader instance has been created, one of the following methods is used to parse the XML and return a Drill configuration object graph.
  • ReadAllDependencyResolversConfiguration - This method reads all of the dependency resolver configuration data from the source and returns a collection of dependency resolver configuration data.
  • ReadDependencyResolverConfiguration(string name) - This method reads the specified dependency resolver configuration data from the source and returns the dependency resolver configuration object graph.

Usage Example

The example below shows how to create a new dependency resolver instance ("MyResolver") by reading the Drill configuration XML from a stream. For the sake of simplicity, we will arbitrarily create a stream from a file. The example assumes that the configFilename variable has been declared and assigned an appropriate value.

IDependencyResolverConfiguration config;
using (FileStream stream = 
    new FileStream(configFilename, 
        FileMode.Open, FileAccess.Read))
{
    XmlConfigurationReader reader = 
        XmlConfigurationReader.FromStream(stream);

    config = reader.ReadDependencyResolverConfiguration("MyResolver");
}

IDependencyResolver dependencyResolver = 
    DependencyResolverManager.Create(config);



Last edited Nov 21, 2012 at 12:47 AM by wreynolds, version 2

Comments

No comments yet.