These days I had the opportunity to make a review over an ecommerce application. They tried to use CQRS and they almost succeeded. I notified a problem on their queries classes that can become a big problem in time, if you want to sell this solution as a platform. Also, from some perspective, these problems also violate the CQRS principle. Let’s see some code now: public class Order { Collection<OrderItem> _items; public IEnumerable<OrderItem> Items { get { return _items; } } ... } What do you see here strange? We want to expose the OrderItem collection as a read only collection. To do this, we convert it to IEnumerable. Hmmm… sounds good? Nope. Big mistake! Nobody stop us to convert the Items back to an ICollection and Add/Remove items from it. Order order = new Order(); … var orderItems = (Collection<OrderItem>)oder.Items; What should we do? .NET framework has specials collections that can...
DREAMER, CRAFTER, TECHNOLOGY ENTHUSIAST, SPEAKER, TRAINER, AZURE MVP, SOLVING HARD BUSINESS PROBLEMS WITH CUTTING-EDGE TECHNOLOGY