I want to create a simple game and use one of IoC containers. Every game has players, so I want to inject them into Game
class. The thing is, there could be different types of players. First player will be always Human (device owner;)), but his opponent: Human (play and pass), Bot or Online (human, but playing through internet).
Here is the code. There different players:
public class Human : IPlayer
{
public int Id { get; set; }
public string Name { get; set; }
public PlayerType Type { get; set; }
}
public class Bot : Human
{
}
public class OnlinePlayer : Human
{
}
public interface IPlayer
{
int Id { get; set; }
string Name { get; set; }
PlayerType Type { get; set; }
}
and Game
class:
public class Game : IGame
{
public GameType Type { get; private set; }
public List<IPlayer> Players { get; private set; }
public Game(GameType type, List<IPlayer> players)
{
Type = type;
Players = players;
}
}
public interface IGame
{
GameType Type { get; }
List<IPlayer> Players { get; }
}
As you can see, I inject List of players in Game's container. Here is my question:
How can I resolve List<IPlayer>
in case of differen type GameType
?
if GameType = Single player -> Inject Human and Bot
if GameType = Pass and play -> Inject Human and Human
if GameType = Online game -> Inject Human and OnlinePlayer