Share via


Reusing Configuration Files Based on a Previous Schema

patterns & practices Developer Center

Download codeDownload PDFOrder Paperback

Although this documentation is based on the Unity 3 configuration schema and all examples use Unity 3, partial backward compatibility is provided for the Unity 1.2 configuration schema. However, you cannot simply use a Unity 1.2 configuration file. In order to use the contents of a Unity 1.2 configuration file you must:

  1. Create a new configuration file.

  2. Edit the <configSections> to point to the correct assembly.

  3. Add a <sectionExtension> section if you are using container extensions for Unity.

  4. Cut and paste the portions of the Unity 1.2 configuration file you wish to reuse.

    Note

    Check the results as you still may get errors depending upon the specific portions you cut and paste.

For information on using the Unity 1.2 configuration schema see Unity Configuration Schematic on MSDN.

Migrating Custom Extensions

Unity 1.2 extension configurations cannot just be copied into a Unity 3 configuration file. There is no <extensionConfig> section in Unity 3. However you can often copy the contents of an old <extensionConfig> section to Unity 3 <register> elements.

For example, the following is an excerpt from a Unity 1.2 configuration file.

<extensionConfig>
  <add name="interception"
      type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationElement, Microsoft.Practices.Unity.Interception.Configuration">
    <interceptors>
      <interceptor type="transparentProxy">
        <default type="wrappable"/>
        <key type="wrappableWithProperty"/>
      </interceptor>
      <interceptor type="virtualMethod">
        <key type="wrappableVirtual" name="name"/>
      </interceptor>
    </interceptors>
  </add>
</extensionConfig>

In Unity 3 you would do the following:

  1. Use <sectionExtension> to add the extension elements to the schema and aliases to the configuration section.

    <sectionExtension type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension, Microsoft.Practices.Unity.Interception.Configuration" />
    
  2. You would then use the <extension> element to add the interception extension to the configuration.

        <extension type="Interception" />
    
  3. Then you could copy the interceptor element content and change TransparentProxy to TransparentProxyInterceptor.

    <container name="configuringDefaultInterceptor">
        <extension type="Interception" />
        <interceptors>
          <interceptor type="TransparentProxyInterceptor">
            <default type="wrappable"/>
            <key type="wrappableWithProperty"/>
          </interceptor>
        </interceptors>
    </container>
    

Note

You can use the container element extension or injection members to add extensions. For more information on Unity 3 extensions see Configuration Files for Interception.

Next Topic | Previous Topic | Home | Community