WCF - Design Parameter Decision

断了今生、忘了曾经 提交于 2019-11-27 02:26:27

In this case I would not use the existing services in the Renewal Service, like you say they could change.

I follow the principle that in SOA services should have a business meaning.

I would therefore create a new operation: IsContractRenewalInProgress. This removes the need to think about who should be responsible for validating that the list of renewals returned is NULL. More importantly that the list being NULL means that there are no contract renewals in progress.

The UpdateFundApprovalDate would then call and check the result of IsContractRenewalInProgress, before making any changes.

IsContractRenewalInProgress should be in the Renewal Service, since it is the Renewal Service that owns the data and the business logic to know when a contract renewal is in progress.

Any processing of financial information is going to revolve around one key facet - the careful management of status.

Try creating a state model for your contract system, and carefully document what states can be reached from a given state, and what processing has to occur in order to move from one valid state to another valid state. Then, ensure that any move from one state to another occurs in a transaction such that a failure to achieve the next state returns the contract to its previous state.

You may find it will make it easier for you if you granularize your states to reflect current processing - i.e. rather than REVIEWED, RENEWED, APPROVED, REJECTED, FUNDED, also have states that are set to indicate that a contract is in a state of flux - i.e. it is being reviewed right now, it is being funded right now, etc. In this way the system can identify the contracts that are actively being processed right now. It also makes it easy to identify what was going on if the environment were to suddenly crashes without a successful rollback.

Make sure that you have only one service that updates the state of a contract, and that this service locks the contract during the update. All other processes would use this service to perform the required status changes.

So, in your specific case, the UpdateFundApprovalDate(FundDTO fund) would only be run on contracts whose status was PENDING_FUNDING, and would probably only be a part of the total processing - whatever the case, when the process that runs your updateFundApprovalDate(FundDTO fund) completes, the contract status will be either FUNDED if it was successful - or if the attempt to fund failed, all changes will have been rolled back resulting in the original contract status of PENDING_FUNDING. If the system crashed, the contract status could potentially be left in the current processing state, having a status something like FUNDING. FUNDING itself would not be a valid state in your state model - it is an interim state. All processes will only begin processing a contract in a valid state, never interim states.

For patterns which could be used in this situation, look at State Machine patterns.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!