Unity uses the System.Configuration
namespace supplied with the .NET framework. This means that configuration information can be stored in any .NET configuration file, which is typically your App.config
or Web.config
file, but it could be stored elsewhere. The following example is a simple XML configuration file.
<configuration>
<configSections>
<section name="unity" type="Unity.Configuration.UnityConfigurationSection, Unity.Configuration"/>
</configSections>
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<alias alias="ILogger" type="MyApp.ILogger, MyApp" />
<namespace name="MyApp.Implementations" />
<assembly name="MyApp" />
<container>
<register type="ILogger" name="special" mapTo="SpecialLogger" />
</container>
</unity>
</configuration>
A Unity configuration section consists of a set of type lookup modifiers (aliases, namespaces, and assemblies), and one or more elements. A element has a set of elements that provide the configuration for the container's types. Other elements can also be used in the container, see The Unity Configuration Schema for a full description of the schema. The XML namespace specified with the xmlns attribute in the example is not required at run time. However, it is useful because Visual Studio uses it to match the section with the Unity XML schema and to provide IntelliSense in the XML editor.