I’m so tempted to have a beer right now! Thought of Hoppiness = Happiness is humming around my head! But…I stay on track :)

Some updates on the application!


Code for this post is in branch: learning-unbeered-6.

  • In this iteration I’m starting to separate out commands from queries. Command is basically an object that represents an action. When a receiver receives a command, it performs certain tasks that might change the state of a data/system. Receiver may or may not respond. Query object on the other hand is a request object that asks the receiver to return certain data. This request does not change the state of the data/system.
  • One of the advantages of separating out commands from queries is that we can isolate the logic create/update logic from read logic, hence taking advantage of cleaner classes, caching on the read side if necessary etc.
  • Command models can be shaped depending on the task on screen. Read models can be shaped to optimize the display. More about CQRS can be found here.
  • I created two commands - AddEntryCommand and DeleteAllEntriesCommand, which represents command to add an entry in the database and delete all the entries from the database respectively.
  • There are command handler(receivers) classes which knows how to handle specific command. This is done by implementing IHandleMessage, where ICommand is a marker class. All commands must implement this interface.
  • When the program starts up, a CommandProcessor class is instantiated with all the handlers available in the assembly.
  • To send a command to receiver, we use Send method on CommandProcessor.
  • CommandProcessor knows which handler to dispatch the command to and executes Handle method on the handlers! So if there are multiple receivers for a specific command, all the receivers will receive the command and perform needed task. For eg. if DeletedAllEntriesCommand is sent, there could be a receiver that deletes the entries and there could be another handler that notifies/logs who sent the command.

Whats next?

  • While the current command/handler/processor implementation works for the state of the project, I’d like to look at MediatR. I’d like to focus on application more than the infrastructure!
  • I think we can replace the static class DataStore with something better.

Have a wonderful day!