Book Image

Hands-On Domain-Driven Design with .NET Core

By : Alexey Zimarev
5 (1)
Book Image

Hands-On Domain-Driven Design with .NET Core

5 (1)
By: Alexey Zimarev

Overview of this book

Developers across the world are rapidly adopting DDD principles to deliver powerful results when writing software that deals with complex business requirements. This book will guide you in involving business stakeholders when choosing the software you are planning to build for them. By figuring out the temporal nature of behavior-driven domain models, you will be able to build leaner, more agile, and modular systems. You’ll begin by uncovering domain complexity and learn how to capture the behavioral aspects of the domain language. You will then learn about EventStorming and advance to creating a new project in .NET Core 2.1; you’ll also and write some code to transfer your events from sticky notes to C#. The book will show you how to use aggregates to handle commands and produce events. As you progress, you’ll get to grips with Bounded Contexts, Context Map, Event Sourcing, and CQRS. After translating domain models into executable C# code, you will create a frontend for your application using Vue.js. In addition to this, you’ll learn how to refactor your code and cover event versioning and migration essentials. By the end of this DDD book, you will have gained the confidence to implement the DDD approach in your organization and be able to explore new techniques that complement what you’ve learned from the book.
Table of Contents (14 chapters)

Projections and Queries

In Chapter 9, CQRS - The Read Side, we changed our application to use events as the consistent aggregate storage. Instead of updating a snapshot of the state after handling a command, we can add new events to the stream that represents a single aggregate. We can then do a left fold on those events to reconstruct the aggregate state each time we load it again, before handling another command. In two lines of pseudo code, the essence of Event Sourcing can be represented as follows:

// Loading:
state = foreach(event in history: state = when(state, event))

// Command handling:
event = handle(state, command)

Here, history is what we load from the aggregate stream, when is the AggregateRoot.When method and Handle is one of the methods in the application service.

But, as I mentioned before, I removed all read models and the code associated with queries from the...