/// <summary> /// 添加事务准备 /// </summary> /// <param name="transactionPreparation">事务准备</param> protected void AddTransactionPreparation(ITransactionPreparation transactionPreparation) { if (_transactionPreparations == null) { _transactionPreparations = new Dictionary <string, ITransactionPreparation>(); } _transactionPreparations.Add(transactionPreparation.TransactionId, transactionPreparation); }
/// <summary> /// 预提交 /// </summary> /// <param name="transactionPreparation">事务准备</param> public void PreCommit(ITransactionPreparation transactionPreparation) { if (transactionPreparation == null) { throw new ArgumentNullException(nameof(transactionPreparation)); } if (SupportedTransactionParticipantTypes == null || !SupportedTransactionParticipantTypes.Contains(transactionPreparation.GetType())) { throw new ApplicationException($"Unknown transaction preparation {transactionPreparation.GetType().Name} for aggregate root {this.GetType().Name}, id={Id}."); } InternalPreCommit(transactionPreparation); }
/// <summary> /// 预提交 /// </summary> /// <param name="transactionPreparation">事务准备</param> public void PreCommit(ITransactionPreparation transactionPreparation) { if (transactionPreparation == null) { throw new ArgumentNullException(nameof(transactionPreparation)); } if (SupportedTransactionParticipantTypes == null || !SupportedTransactionParticipantTypes.Contains(transactionPreparation.GetType())) { throw new ApplicationException($"Unknown transaction preparation {transactionPreparation.GetType().Name} for aggregate root {this.GetType().Name}, id={Id}."); } if (PreventPreCommitOrNotIfTransactionProcessing && IsTransactionProcessing) { throw new AlreadyStartTransactionWhenPreCommitDomainException <TTransactionInitiator, TAggregateRootId>(transactionPreparation.GetType().FullName, transactionPreparation.GetTransactionPreparationInfo()); } InternalPreCommit(transactionPreparation); }
/// <summary> /// 添加一笔预操作 /// </summary> /// <param name="transactionPreparation"></param> protected override void InternalPreCommit(ITransactionPreparation transactionPreparation) { var availableBalance = GetAvailableBalance(); if (transactionPreparation is WithdrawTransactionPreparation) { var theTransactionPreparation = transactionPreparation as WithdrawTransactionPreparation; if (availableBalance < theTransactionPreparation.Amount) { throw new InsufficientBalanceDomainException(theTransactionPreparation.GetType().FullName, theTransactionPreparation.GetTransactionPreparationInfo(), theTransactionPreparation.Amount, _balance, availableBalance); } ApplyEvent(new WithdrawTransactionPreCommitSucceedEvent(theTransactionPreparation)); } else if (transactionPreparation is DepositTransactionPreparation) { var theTransactionPreparation = transactionPreparation as DepositTransactionPreparation; ApplyEvent(new DepositTransactionPreCommitSucceedEvent(theTransactionPreparation)); } }
/// <summary> /// 预提交 /// </summary> /// <param name="transactionPreparation">事务准备</param> protected abstract void InternalPreCommit(ITransactionPreparation transactionPreparation);