mardi 9 août 2016

Inversion of Control on a list

I have been thinking about how Inversion of Control would work when working with lists. For example somthing like this would work fine:-

public class MyClass
{
private readonly IMyInterface _instance;

public MyClass(IMyInterface instance)
{
   _instance = instance;
}

Is the below violating the Open/Closed SOLID Design Principle, and if so how can the list be implemented using IoC like in the above example?

private readonly List<IMyInterface> _interface;

    public MyClass()
    {
        _interface= new List<IMyInterface>();
        _interface.Add(new Class1());
        _interface.Add(new Class2());
        _interface.Add(new Class3());
    }
...

Aucun commentaire:

Enregistrer un commentaire