Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 3 Next »

Problem

  • In complex applications, read side and write side can become complicated. Read side can returns data transfer objects (DTOs) with different shapes; Write side can implement compex validation and business logic.

Solution

  • Separate the read from the write side :

    • example 1 : implement materialized view for the read side and stored procedures for the write side.

    • exemple 2 : implement 2 different data stores, one for the read side which is a document DB and the other, for the write side which is a relational DB.

image-20240819-181716.png
public class ProductsCommandHandler :
    ICommandHandler<AddNewProduct>, ICommandHandler<RateProduct>, ICommandHandler<AddToInventory>, ICommandHandler<ConfirmItemShipped>,
    ICommandHandler<UpdateStockFromInventoryRecount>
{
  private readonly IRepository<Product> repository;

  public ProductsCommandHandler (IRepository<Product> repository)
  {
    this.repository = repository;
  }
  void Handle (AddNewProduct command)
  {
    ...
  }
  void Handle (RateProduct command)
  {
    var product = repository.Find(command.ProductId);
    if (product != null)
    {
      product.RateProduct(command.UserId, command.Rating);
      repository.Save(product);
    }
  }
  void Handle (AddToInventory command)
  {
    ...
  }
  void Handle (ConfirmItemsShipped command)
  {
    ...
  }
  void Handle (UpdateStockFromInventoryRecount command)
  {
    ...
  }
}
  • No labels