An array dependency

Apr 15, 2008 at 4:23 PM
Edited Apr 15, 2008 at 4:25 PM
Is this possible:
--------------------------------------------------------------------------------------------------
interface IMyInterface

class MyClass1: IMyInterface
class MyClass2: IMyInterface

class MyDependentClass
{
public MyDependentClass(IMyInterface[] interfaces){}
}
--------------------------------------------------------------------------------------------------

I now have MyDependentClass with a constructor that accepts the UnityContainer and use resolveAll to get all instances of IMyInterface that are registered, but, for obvious reasons, I don't like this setup very much.
Apr 17, 2008 at 6:12 AM
It's not currently supported. We've discussed doing something around this for future versions.
Apr 17, 2008 at 8:16 AM
You might be able to pull it off with the static factory extension, i.e.:

container.Configure<IStaticFactoryConfiguration>()
.RegisterFactory<IMyInterface[]>(c => c.ResolveAll<IMyInterface>().ToArray());

Never tried it myself, of course ;)