Slide 1

Slide 1 text

Practical Domain-Driven Design With EF Core Hossam Barakat Technical Lead at Willow @hossambarakat_ | www.hossambarakat.net

Slide 2

Slide 2 text

@hossambarakat_ What is Domain-Driven Design? “Domain-Driven Design is an approach to software development that centers the development on programming a domain model that has a rich understanding of the processes and rules of a domain. ” -- Martin Fowler

Slide 3

Slide 3 text

@hossambarakat_ What is Domain Model? “An object model of the domain that incorporates both behavior and data. ” - Martin Fowler “A system of abstractions that describes selected aspects of a domain and can be used to solve problems related to that domain. ” -- Eric Evans

Slide 4

Slide 4 text

@hossambarakat_ Strategic Design

Slide 5

Slide 5 text

@hossambarakat_ Bounded Contexts • A defined part of software where particular terms, definitions and rules apply in a consistent way • Clear boundaries between different parts of the system https://martinfowler.com/bliki/BoundedContext.html

Slide 6

Slide 6 text

@hossambarakat_ Focus on the Core Domain

Slide 7

Slide 7 text

@hossambarakat_ Inside the Core Domain

Slide 8

Slide 8 text

@hossambarakat_ How to apply DDD to my legacy codebase?

Slide 9

Slide 9 text

@hossambarakat_ Sample Domain

Slide 10

Slide 10 text

@hossambarakat_ Sample Domain

Slide 11

Slide 11 text

@hossambarakat_ Domain Model

Slide 12

Slide 12 text

@hossambarakat_ Demo

Slide 13

Slide 13 text

@hossambarakat_ Extract Methods

Slide 14

Slide 14 text

@hossambarakat_ Avoid Public Setters

Slide 15

Slide 15 text

@hossambarakat_ Encapsulate Behavior in Domain Model

Slide 16

Slide 16 text

@hossambarakat_ Encapsulate Collection

Slide 17

Slide 17 text

@hossambarakat_ Encapsulate Behavior in Domain Model

Slide 18

Slide 18 text

@hossambarakat_ Encapsulate Behavior in Domain Service

Slide 19

Slide 19 text

@hossambarakat_ Double Dispatch

Slide 20

Slide 20 text

@hossambarakat_ Domain Events Entity Domain Events DBContext SaveChanges() Event Handler Handle() Event Handler Handle() Event Handler Handle() Mediator Publish() Action() SaveChangesInterceptor SavingChanges()

Slide 21

Slide 21 text

@hossambarakat_ From Primitive Obsession to Value Objects

Slide 22

Slide 22 text

@hossambarakat_ Where is the Repository?

Slide 23

Slide 23 text

@hossambarakat_ Can the Unit of Work help us?

Slide 24

Slide 24 text

@hossambarakat_ Embrace the DbContext

Slide 25

Slide 25 text

@hossambarakat_ What about custom queries? • Query classes • Specification pattern • Extension Methods

Slide 26

Slide 26 text

@hossambarakat_ Specification: Current Query

Slide 27

Slide 27 text

@hossambarakat_ Specification: Base Classes

Slide 28

Slide 28 text

@hossambarakat_ Specification: Concrete Sample

Slide 29

Slide 29 text

@hossambarakat_ Specification: Concrete Sample

Slide 30

Slide 30 text

@hossambarakat_ Specification: Extension Methods

Slide 31

Slide 31 text

@hossambarakat_ Base Entity ID

Slide 32

Slide 32 text

@hossambarakat_ Resources • https://github.com/hossambarakat/Subscriptions-DDD • https://github.com/ardalis/Specification

Slide 33

Slide 33 text

@hossambarakat_ Questions

Slide 34

Slide 34 text

@hossambarakat_ Thanks Hossam Barakat Tech Lead at Willow @HossamBarakat_