Invoke the same method twice?

Sep 10, 2008 at 10:30 AM
Edited Sep 10, 2008 at 10:34 AM
Hey,

I'm trying to add a list that resolves to IEnumerable<> to the Unity configuration - I don't know if I'm doing it wrong, it sure is a lot of work...

<type type="System.Collections.Generic.IEnumerable`1[[ICache, TestProject1]]"

      mapTo="System.Collections.Generic.List`1[[ICache, TestProject1]]">

  <typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration">

    <constructor />

    <method name="Add">

      <param name="item" parameterType="ICache, TestProject1">

        <dependency name="webCache" />

      </param>

    </method>

    <method name="Add">

      <param name="item" parameterType="ICache, TestProject1">

        <dependency name="nullCache" />

      </param>

    </method>

  </typeConfig>

</type>


So this is actually two questions:

1. The add method only gets called once in this scenario - adding a new method Add2() makes it work ... so Unity can't call the same method twice?

2. Are there an easier way to do this? ... injecting a list of dependencies into a object (in configuration)

Thanks,

Poul

Sep 10, 2008 at 7:35 PM
1. This is a limitation / bug in our configuration system. We're looking at how to fix it, but no promises.

2. There will be an easier way in Unity 1.2 - you'll be able to specify "give me an array" and it'll get injected. More details later.

-Chris