开发者

In CQRS, how do I communicate a list of allowable methods on an aggrregate to the UI?

I have an 开发者_如何学运维aggregate root 'Order', and it has a number of methods on it which internally set its 'Status' field:

  • Submit
  • Place On Hold
  • Take Off Hold
  • Confirm
  • Cancel
  • etc.

The available actions are dependent upon the current Status of the order (e.g. it can't be put on hold if it's already on hold). The problem is that I need to provide a query to tell the UI which commands are are available so I can hide the operations that would otherwise throw an InvalidOperationException.

How do I do this with minimal DRY violation?


The simplest solution is to project current status along with available transitions to read/query model and select it along with the data to display.

Example: PlaceOnHoldCommand results in OrderPlacedOnHoldEvent which (besides being put in EventStore) is published and handled by OrderTransitionsEventHandler which denormalizes available transitions to a DB table associated with Order. The client selects available transitions and acts accordingly (hides unavailable buttons or sth. like that).

This is of course one of options. Don't expect however that there will be no duplication whatsoever. CQRS helps to manage complexity and sometimes this means slight violations of DRY occur.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜