public IGame Create(IDomainEventChannel domainEventChannel) { if (domainEventChannel == null) { throw new ArgumentNullException("domainEventChannel"); } return(new Game(domainEventChannel, GameId, new Player[] { player1, player2 }, currentPlayer, new Grid(grid))); }
public Game(IDomainEventChannel domainEventChannel, Guid gameId, Player[] players, int?iCurrentPlayer, Grid grid) { if (domainEventChannel == null) { throw new ArgumentNullException("domainEventChannel"); } this.domainEventChannel = domainEventChannel; if (gameId == null) { throw new ArgumentNullException("gameId"); } this.gameId = gameId; if (players == null) { throw new ArgumentNullException("players"); } if (players.GetLength(0) != 2) { throw new InvalidOperationException( string.Format("invalid players range. Expected : 2. actual : {0}", players.GetLength(0))); } this.players = players; if (!new int?[] { 0, 1, null }.Contains(iCurrentPlayer)) { throw new InvalidOperationException( string.Format("invalid current player value. Expected : 0, 1 or null. actual : {0}", iCurrentPlayer) ); } this.iCurrentPlayer = iCurrentPlayer; this.grid = grid; }
public CompositionRoot(IDomainEventChannelFactory domainEventChannelFactory, IGameBuilder gameBuilder, IUICommandChannelFactory commandChannelFactory, IGameViewFactory gameViewFactory) { // Domain this.domainEventChannel = domainEventChannelFactory.Create(); this.game = gameBuilder.Create(this.domainEventChannel); // View this.uiCommandChannel = commandChannelFactory.Create(); this.gameView = gameViewFactory.Create(this.uiCommandChannel); // Handlers this.fromUICommandsToDomainHandler = new FromUICommandsToDomainHandler(this.uiCommandChannel, this.game); this.fromDomainEventsToViewHandler = new FromDomainEventsToViewHandler(this.domainEventChannel, this.gameView); }
public FromDomainEventsToViewHandler(IDomainEventChannel domainEventChannel, IGameView gameView) { this.gameView = gameView; domainEventChannel.AddSubscriber(this); }