I am struggling to solve this architectural problem. Our system uses the NService bus and the DDD implementation with EventSourcing using NEventStore and NES. The client application is WPF
I still can’t decide what is the best way to update the user interface, for example: I have a user interface to create (Batch {Id, StartDate, EndDate, etc.)) After the user clicks on save, I send a command (CreateBatch),
Bus.Send<CreateBatch> (batch => {batch.Id = Guid.NewGuid(); .... etc });
Now
Option number 1
Do I have to register for an answer as follows:
private void btnSave_Click(object sender,EventsArg e){ Bus.Send<CreateBatch> (batch => {batch.Id = Guid.NewGuid(); .... etc }) .Register<int>(c=> { MessageBox.Show("Command Succeded"); Close();}); }
and server side:
public void Hanlde(CreateBatch cmd){
In this case, how to handle errors? (Validation errors, for example, have batch starts already started on the same date?), Since you can only return int or string !!
Option number 2:
Send a command, close the window, fake the record added to the main grid until the user updates the grid and receives real information from the ReadModel database or finds out that the record has not yet been added, not having a clue about what happened !!
private void btnSave_Click(object sender,EventsArg e){ Bus.Send<CreateBatch> (batch => {batch.Id = Guid.NewGuid(); .... etc }); Close(); }
Option number 3
Send a command, close the window, fake that the record has been added to the main grid, but mark it as (in progress), wait for the (BatchCreated) event to make sure that this is the same batch identifier that we sent earlier, and then mark the entry as saved in the grid.
private void btnSave_Click(object sender,EventsArg e){ Bus.Send<CreateBatch> (batch => {batch.Id = Guid.NewGuid(); .... etc }); Close(); } public class BatchHandler : IHandleMessages<BatchCreated> { public void Handle(BatchCreated evnt) { if(SomeCachForSentIDS.Contains(evnt.BatchId)
If you have any better options or if you have suggestions for these parameters or even some links on how to handle this situation, I would be grateful.
Thanks.