tags:

views:

20

answers:

1

Using a Unity 2.0 xml file, I am trying to populate an object that contains a generic list. According to the Unity Configuration Schema, the array element is only supported. Has anyone ever tried to use unity to populate a generic list?

A: 

You can work around this limitation, in the constructor or with a setter:

public class MyService : IMyService {
    List<IMyDependency> _myDeps;

    [Dependency]
    public IMyDependency[] Deps { 
       set {
          _myDeps = new List<IMyDependency>(Deps);
       }
    }
    ...
}

If you can not change your class you can still use a factory.

onof