views:

453

answers:

2

I cannot seem to get unity working when attempting to pass in an array of strings into a constructor parameter list, while using XML configuration.

When I try the following:

<typeConfig ...>
  <constructor ...>
    <param ... parameterType="System.String[]">
     <array>    
      <value.../>
      <value.../>
     </array>
    </param> 
  </constructor>
</typeConfig>

for a c'tor which looks like this:

void Foo(string[] inputParams_){ ... }

It always fails in Unity's FindConstructor(...) method stating that it cannot find a c'tor mathcing the parameter type of String.String

Does anyone know how to pass an array of stings successfully into this type of c'tor? If not, how can I do so with a list of strings, if the c'tor were to accept an IList?

Thanks!

A: 

Maybe you will have to fully qualify the type name:

System.String[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

Optionally, you may drop the version if you don't care/know.

Peter Lillevold
hmm, not sure will try it, but system.string doesnt require qualification elsewhere.
miguel
A: 

Typically I prefer to configure Unity in code, so I may not be that helpful if config is a must. But ....

Typically I'd use a ConstructorInjector during registration:

container.Configure() .ConfigureInjectionFor(new InjectionConstructor([value]))

But according to: http://stackoverflow.com/questions/787001/can-i-pass-constructor-parameters-to-unitys-resolve-method

Unity 2 should now also includes the ability to pass parameters into the constructor dynamically during resolution:

"container.Resolve(new ParameterOverrides { { "name", "bar" }, { "address", 42 } });"

Doobi
thanks, but the questions is *specifically* about configuratin files
miguel
No worries. Another worthless try is - I've seen the notation "'1" dotted around text configuration, something like "String'1" usually when referring to some sort of generic collection.
Doobi
yes, `1 or `2 indicate the number of generic parameters.
miguel