Unity 2.0 System.Collections.Generic.List

1k views Asked by At

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?

1

There are 1 answers

0
onof On

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.