I am trying to utilize dependency injection technique in an application but getting confused if this context require DI or not..
Consider an interface:
public class ICardsHub {
public T GetPlayersList<T>();
}
and its implementation:
public class GenericHub : ICardsHub {
LANPlayers LANPlayers;
WaNPlayers WANPlayers;
bool AlgorithmsUseTildainLambdas=false;
public GenericHub(LANPlayers _LANPlayers, WaNPlayers _WANPlayers,
bool algorithmsUseTildainLambdas=false) {
LANPlayers = _LANPlayers;
WANPlayers = _WANPlayers;
AlgorithmsUseTildainLambdas = algorithmsUseTildainLambdas;
}
public T GetPlayersList<T>() {
....
}
}
and the driver class is supposed to do something like:
ICardsHub _ifCards = new GenericHub(_LANPlayers, _WANPlayers);
listOfPlayers = _ifCards.GetPlayersList<List<string>>();
Now, we have two more implementations of ICardsHub
; RedHub
and BlackHub
which are instantiated later in the driver class.
Questions
- How can the Unity IoC/DI benefit this scenario?
- If striping out method parameters from the interface and injecting them to overload constructor solves the problem, then what is the suitable scenario for DI container usage?