/// <summary> /// Regard CommandHandler as a kind of application service, /// we do some query in it and also can publish some application event /// and no need to enter the domain layer! /// </summary> /// <param name="command"></param> public async Task Handle(Login command) { var account = await _DomainRepository.FindAsync <Account>(a => a.UserName.Equals(command.UserName) && a.Password.Equals(command.Password)) .ConfigureAwait(false); if (account == null) { throw new SysException(DTO.ErrorCode.WrongUsernameOrPassword); } _EventBus.Publish(new AccountLogined { AccountID = account.ID, LoginTime = DateTime.Now }); await _UnitOfWork.CommitAsync() .ConfigureAwait(false); _CommandContext.Reply = account.ID; }