Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML config changes in Unity 2.0

we've just upgrade a project from prism 2.0 to prism 4.0, and we're having problems with Unity. Apparently there's several changes in unity 2.0 container XML configuration as we get as our first error " Unrecognized element 'typeConfig' ". Here is the code:

//----------------------- App.config

   <configSections>
    <section name="runDataParserConfiguration" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration" />
  </configSections>
  <runDataParserConfiguration>
    <typeAliases>
      <typeAlias alias="IRunDataDispatcher" type="RunDataParser.Interface.IRunDataDispatcher, RunDataParser.Interface" />
      <typeAlias alias="IRunDataParser" type="RunDataParser.Interface.IRunDataParser, RunDataParser.Interface" />
      <typeAlias alias="IRunDataParserArray" type="RunDataParser.Interface.IRunDataParser[], RunDataParser.Interface" />
      <typeAlias alias="Dispatcher" type="RunDataParser.Common.Dispatcher, RunDataParser.Common" />
      <typeAlias alias="Parser1" type="RunDataParser.Parser1, RunDataParser" />
      <typeAlias alias="Parser2" type="RunDataParser.Parser2, RunDataParser" />
      <typeAlias alias="Parser3" type="RunDataParser.Parser3,RunDataParser" />
      <typeAlias alias="Parser4" type="RunDataParser.Parser4, RunDataParser" />
      <typeAlias alias="Parser5" type="RunDataParser.Parser5, RunDataParser" />
      <typeAlias alias="Parser6" type="RunDataParser.Parser6, RunDataParser" />
      <typeAlias alias="Parser7" type="RunDataParser.Parser7, RunDataParser" />
      <typeAlias alias="Parser8" type="RunDataParser.Parser8, RunDataParser" />
      <typeAlias alias="Parser9" type="RunDataParser.Parser9, RunDataParser" />
    </typeAliases>
    <containers>
      <container>
        <types>
          <type type="IRunDataParser" mapTo="Parser1" name="parser1" />
          <type type="IRunDataParser" mapTo="Parser2" name="parser2" />
          <type type="IRunDataParser" mapTo="Parser3" name="parser3" />
          <type type="IRunDataParser" mapTo="Parser4" name="parser4" />
          <type type="IRunDataParser" mapTo="Parser5" name="parser5" />
          <type type="IRunDataParser" mapTo="Parser6" name="parser6" />
          <type type="IRunDataParser" mapTo="Parser7" name="parser7" />
          <type type="IRunDataParser" mapTo="Parser8" name="parser8" />
          <type type="IRunDataParser" mapTo="Parser9" name="parser9" />
          <type type="IRunDataDispatcher" mapTo="Dispatcher" name="runDataDispatcher" />
          <type type="Presentation.RawDataManagement.Wrapper.ParserDispatcherWrapper, RawDataManagement">
            <typeConfig>
              <constructor>
                <param name="runDataDispatcher" parameterType="Dispatcher" />
                <param name="runDataParsers" parameterType="IRunDataParserArray">
                  <array>
                    <dependency name="parser1" />
                    <dependency name="parser2" />
                    <dependency name="parser3" />
                    <dependency name="parser4" />
                    <dependency name="parser5" />
                    <dependency name="parser6" />
                    <dependency name="parser7" />
                    <dependency name="parser8" />
                    <dependency name="parser9" />
                  </array>
                </param>
              </constructor>
            </typeConfig>
          </type>
        </types>
      </container>
    </containers>

  </containers>    

//----------------------------------------------------

I commented typeConfig node and got the error "No valid attributes were found to construct the value for the parameter runDataDispatcher. Please check configuration files."

After that and doing some research I removed parameterType attributes but this didn't work. I commented typeAliases node and change typeAlias nodes to alias, also commented types node (under node) and chage its child nodes type to register. Non of this worked.

like image 225
kima05 Avatar asked Nov 08 '11 13:11

kima05


2 Answers

The XML configuration has changed between Unity versions 1.2 and 2.

As you mention <typeAlias> is now <alias> and <type> should be a <register>.

You can remove the <typeAliases> tags, <containers> tags, <types> and <typeConfig> tags.

If might be helpful for you to change the section name from "runDataParserConfiguration" to "unity" then you should be able to use intellisense to guide the configuration. After configuration you could always change it back to "runDataParserConfiguration" if you like.

Your config will look something like:

<?xml version="1.0"?>
<configuration>
    <configSections>
        <section name="runDataParserConfiguration" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/>
    </configSections>

    <runDataParserConfiguration xmlns="http://schemas.microsoft.com/practices/2010/unity">

        <alias alias="IRunDataDispatcher" type="RunDataParser.Interface.IRunDataDispatcher, RunDataParser.Interface" />
        <alias alias="IRunDataParser" type="RunDataParser.Interface.IRunDataParser, RunDataParser.Interface" />
        <alias alias="IRunDataParserArray" type="RunDataParser.Interface.IRunDataParser[], RunDataParser.Interface" />
        <alias alias="Dispatcher" type="RunDataParser.Common.Dispatcher, RunDataParser.Common" />
        <alias alias="Parser1" type="RunDataParser.Parser1, RunDataParser" />
        <alias alias="Parser2" type="RunDataParser.Parser2, RunDataParser" />

        <container>
            <register name="parser1" type="IRunDataParser" mapTo="Parser1" />
            <register name="parser2" type="IRunDataParser" mapTo="Parser2" />
            <register name="ParserDispatcherWrapper" type="Presentation.RawDataManagement.Wrapper.ParserDispatcherWrapper, RawDataManagement">
                <constructor>
                    <param name="runDataDispatcher"  type="Dispatcher" />
                    <param name="runDataParsers"  type="IRunDataParserArray">
                        <array>
                            <dependency name="parser1" />
                            <dependency name="parser2" />
                        </array>
                    </param>
                </constructor>
            </register>
        </container>

    </runDataParserConfiguration>
</configuration>
like image 58
Randy supports Monica Avatar answered Nov 02 '22 12:11

Randy supports Monica


Although the answer by @RandyLevy helped me with most of the elements, I needed to make a few more changes. Those were not in the OP's file, but I will add them for anyone running into Unity 1.2 to 2.0 upgrade issues.

I my application, dependencies are not injected through the constructor, but through public properties (do not ask why).

So, I have configuration elements like:

<type type="IMyService" mapTo="MyService">
  <typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration">
    <property name="CurrentDataContext" propertyType="IDataContext" />
  </typeConfig>
</type>

that can be modified to:

<register type="IMyService" mapTo="MyService">
  <property name="CurrentDataContext" dependencyType="IDataContext" />
</register>

The Unity Configuration Schema will may help you with yet other elements.

like image 20
R. Schreurs Avatar answered Nov 02 '22 12:11

R. Schreurs