Expert Domain-Driven Design (DDD) Implementation in .NET
2h 30mAdvanced2024-10-10
Authors

Rodrigo Díaz Concha
Solutions Architect, Microsoft Regional Director, and Microsoft MVP
Course details
This course is aimed at .NET developers and architects interested in applying domain-driven design (DDD) in their projects. Instructor Rodrigo Díaz Concha takes you through the steps for creating a solution for a fictional pet medicine company to show you practical techniques to implement DDD using .NET and C#. Learn about using entities, value objects, aggregates, domain events, and more. This course is ideal for those looking to integrate DDD strategies and tools into their development solutions, as well as for software architects and .NET project stakeholders who want to understand how to implement DDD in their current or future initiatives.
Learning objectives
Structure your application around domains and entities.
Establish aggregate classes and determine appropriate behaviors.
Interact with your domains through events and commands.
Learning objectives
Structure your application around domains and entities.
Establish aggregate classes and determine appropriate behaviors.
Interact with your domains through events and commands.
Skills covered
Software Design.NETWeb Development ToolsSoftware Development ToolsWeb DevelopmentMicrosoftSoftware DevelopmentOne-Off
Concepts
Introduction
- Unleash the power of Domain-Driven Design in your .NET projects
- What you should know
- Preparing the development environment
- Domain-Driven Design refresher
- Understanding what you are going to build
Defining and Implementing Entities and Value Objects
- Creating the initial project for the Management domain model
- Implementing an entity
- Refactoring the logic into an entity base class
- Encapsulating and protecting entity state
- Avoiding the primitive obsession anti-pattern
- Implementing a value object for a pet's weight
- Implementing a second entity for pet breeds
- Invoking a domain service in a value object
- Implementing business rules in the Pet entity
- Implementing implicit operators in value objects
Defining and Implementing Aggregates
- Refactoring the solution to add a shared kernel mapping
- Adding necessary properties to the aggregate
- Implementing logic in the aggregate to end a consultation
- Implementing behavior to manage drugs
- Implementing behavior to record multiple vital sign readings
- Unit testing the aggregate
Implementing the Infrastructure Layer
- Creating the ManagementDbContext
- Configuring type and property mappings in the DbContext
- Registering the DbContext in the dependency injection container
- Refactoring the code into a repository interface and class
Implementing the Application Layer
- Implementing the ManagementApplicationService class
- Persisting data in the ManagementApplicationService class
- Rehydrating persisted entities and invoking their behavior
- Creating a command handler interface for handling commands
- Challenge - Implementing the Clinic API
- Solution - Implementing the Clinic API
- Challenge - Refactoring the consultation date and time
- Solution - Refactoring the consultation date and time
Implementing Domain Events
- Implementing domain events
- Publishing domain events
- Subscribing to domain events
Mixing the Event Sourcing Pattern with DDD
- Refactoring the AggregateRoot class for tracking events
- Implementing the first domain event to be tracked
- Implementing more domain events related to the consultation
- Refactoring the DbContext for handling domain events
- Persisting domain events in the database
- Loading domain events from the database
Conclusion
- Next steps in Domain-Driven Design (DDD)