Why would you try and use an InjectionConstructor in the first place? Unity knows how to handle arrays out of the box.
The params keyword is just some syntactic sugar for the compiler. Under the cover args2 is just a simple array.
[TestMethod]
public void TestMethod1()
{
var container = new UnityContainer();
// if you absolutely have to use an InjectionConstructor this should do the trick
// container.RegisterType<IMyClass, MyClass>(
// new InjectionConstructor(typeof(Class1), typeof(Class2[])));
container.RegisterType<IMyClass, MyClass>(
new InjectionConstructor(typeof(Class1), typeof(Class2[])));
container.RegisterType<Class2>("1");
container.RegisterType<Class2>("2");
container.RegisterType<Class2>("3");
var myClass = container.Resolve<IMyClass>() as MyClass;
Assert.IsNotNull(myClass);
Assert.IsNotNull(myClass.Arg2);
Assert.AreEqual(3, myClass.Arg2.Length);
}
interface IMyClass
{
}
class MyClass : IMyClass
{
public Class1 Arg1 { get; set; }
public Class2[] Arg2 { get; set; }
public MyClass(Class1 arg1, params Class2[] arg2)
{
Arg1 = arg1;
Arg2 = arg2;
}
}
class Class1
{
}
class Class2
{
}
Update
If you are only using some of the named registrations you will have to use the ResolvedArrayParameter.
container.RegisterType<IMyClass, MyClass>(
new InjectionConstructor(
typeof(Class1),
new ResolvedArrayParameter<Class2>(
new ResolvedParameter<Class2>("1"),
new ResolvedParameter<Class2>("2"))));
Brrr! This is super ugly but it should solve your problem.