CQRS: how do you retrieve information about a completed command?

Most of the command interfaces that I have seen usually use the "Execute" method, which takes an input command and returns either void or some general structure indicating whether the command completed successfully or not (we use the latter). Now I never thought about this before, but we suddenly had the need to find out more detailed information about the result of the team than what you can provide in general terms.

Consider the following example:

You have a team and you create a screen where you can add members to your team. Team members are shown in the grid below "add new member". Now, when you click "add new member", you want to run some jquery / roundohuse / whatever and add the new member to the list of team members. There are no problems at the moment, but: you also want to include some credentials in a hidden field for each member, and these credentials come from the server.

So the problem is, how can I get these credentials from the server? The "AddNewTeamMember" command, which I click on the "ExecuteCommand" method, does not give me anything useful, and if I add a new request method to the service, saying something like: "GetLastAddedTeamMember", then I can just get the last record added by someone to others (at least if it is data that is very aggressively added by different users). In some situations, you have a unique unique identifier created on the client side that we can use, but we did not do this for team members.

+4
source share
2 answers

Given that you have no choice but to update the widget on the page when another command is complete, I see two options for you:

  • Reset the command, display something locally indicating that it was sent, and wait until you receive a notification from the server that the list of team members has changed. Refresh the widget to reflect this.

  • Add the correlation identifier to your team when you submit it and temporarily add the team member to the list. When you receive confirmation from the server that a group member update was due to your correlation identifier, update the local data.

I would suggest the first approach, where a “preliminary indicator” could throw a noticeable version of a normal indication of a place; when you finally receive the update, you must have the necessary data.

Given that you went with CQRS to solve this problem, I assume that you already frequently update the contents of these widgets that happen in the background, so I supposedly solved the "background update" problem.

If this is not the case, I suggest you either use CQRS as a poor complex solution in the problem space, or first solve the background update problem.

+3
source

If you want to add an existing team member, you must request the reading side of your application for this data. If you need to add a new team member, you need to think about whether to immediately show the user in the grid below. Can you wait for a team member to be at the reading location? You can also request a server-side service to get a unique identifier (it can return a GUID). Then you add the team member to the grid and, of course, send the team to the server. But, if possible, try to develop the application in such a way that you do not need to immediately show a member of the team. You can also give the user a message saying something like this: "A member of the team has been added and is awaiting a response from the server." Then use AJAX to request reads for new team members. When it appears on the reading side, show it in the grid. You may need to deal with team members added by other users, but does it matter? CQRS gives you a great way to collaborate with other users, so maybe you should take advantage of this. How do I see it; CQRS makes you think differently, and it can be bad.

0
source

Source: https://habr.com/ru/post/1383577/


All Articles