Here is one solution that I found, but it's a little impudent. You need a wrapper class to help Unity recognize that the array is IEnumerable .
public class ArrayWrapper<T> : IEnumerable<T> { public ArrayWrapper(T[] things) { this.things = things; } private IEnumerable<T> things; IEnumerator<T> IEnumerable<T>.GetEnumerator() { return this.things.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return this.things.GetEnumerator(); } }
You can then configure Unity to enter one of them using the idea of ββEthan EnumberableThing .
<alias alias="IThing" type="TestConsoleApplication.IThing, TestConsoleApplication" /> <alias alias="SimpleThing" type="TestConsoleApplication.SimpleThing, TestConsoleApplication" /> <alias alias="CompositeThing" type="TestConsoleApplication.CompositeThing, TestConsoleApplication" /> <alias alias="EnumerableThing" type="System.Collections.Generic.IEnumerable`1[[TestConsoleApplication.IThing, TestConsoleApplication]], mscorlib"/> <alias alias="ThingArrayWrapper" type="TestConsoleApplication.ArrayWrapper`1[[TestConsoleApplication.IThing, TestConsoleApplication]], TestConsoleApplication"/> <container> <register type="EnumerableThing" mapTo="ThingArrayWrapper"> <constructor> <param name="things"> <array> <dependency type="SimpleThing"/> <dependency type="SimpleThing"/> <dependency type="SimpleThing"/> <dependency type="SimpleThing"/> </array> </param> </constructor> </register> <register type="IThing" mapTo="SimpleThing" name="SimpleThing" /> <register type="IThing" mapTo="CompositeThing" name="CompositeThing"> <constructor> <param name="otherThings" dependencyType="EnumerableThing" /> </constructor> </register> </container>
As I said, a little impudent and uncomfortable when you want another CompositeThing with three, five, six things, etc.
Does Unity really need to be able to recognize that the array is IEnumberable and enter it?
source share