SlideShare a Scribd company logo
1 of 41
Download to read offline
Domain-Driven Designwith ASP.NET MVC 
Steve Smith 
CTO, Falafel Software 
@ardalis| steve.smith@falafel.com
What is Domain-Driven Design (DDD)?
Communication 
•Ubiquitous Language 
•Domain Expert Interaction 
Modeling 
•Core Domain 
•Generic Subdomains 
•Bounded Context 
•Context Map 
•Shared Kernel 
•Anti-Corruption Layer 
Implementation 
•Model-Driven Design 
•Layered Architecture 
•Entities 
•Value Objects 
•Services 
•Factories 
•Aggregates 
•Repositories 
•Domain Events
DDD is BIG 
“The more you know, the more you realize you know nothing.” 
Socrates
DDD Fundamentals Course 
•Over 4 hours of content (demos using MVC + SignalR) 
•http://bit.ly/PS-DDD
DDD Benefits 
•Flexibility 
•Software models customer’s understanding of problem 
•Breaks complexity into manageable pieces 
•Well-organized; easily tested 
•Business logic lives in one place
DDD Drawbacks 
•Time and Effort 
•Learning Curve 
•Overkill without Complexity 
•“Anemic” domain model problem
Communication 
“As software developers, we fail in two ways: we build the thing wrong, or we build the wrong thing.” 
Me
Ubiquitous Language 
http://upload.wikimedia.org/wikipedia/commons/2/23/Rosetta_Stone.JPG
Language 
“A project faces serious problems when its language is fractured.” 
Eric Evans
Ubiquitous Language 
•Ubiquitous–adjective. Present, appearing, or found everywhere. 
•Synonyms: pervasive, universal 
•Used within a given Bounded Context 
•Used in code, design documents, and conversations 
--Everywhere
DomainTerms 
Domain Experts 
Problem Domain 
Core Domain 
Sub-Domains
Bounded Contexts 
•Provide Separation of Concerns 
•Limit complexity 
•Should be clearly boundedand separate
Appointment Scheduling 
Billing
Appointment Scheduling 
Billing 
Anti- 
Corruption 
Layer
Model Driven Design 
Not Data-Driven
Layered Architecture 
•Ports and Adapters 
•Hexagonal 
•Onion
Organizing in a Solution
Entities 
“Many objects are not fundamentally defined by their attributes, but rather by a thread of continuity and identity.” 
Eric Evans
Changing Attributes Doesn’t Change Which One We’re Talking About 
ID:1 
•Name: Steve Smith 
•Twitter: @ardalis 
•Favorite Color: Blue 
ID: 1 
•Name: StevenSmith 
•Twitter: @ardalis 
•Favorite Color: Blue 
ID: 1 
•Name: Steven Smith 
•Twitter: @ardalis 
•Favorite Color: Orange
Value Objects 
•Defined by their attributes 
•Immutable 
•Should have no side effects 
•Examples: strings, addresses, currency
Immutable!
Domain Services 
•Not a natural part of an Entity or Value Object 
•Interfacedefined in terms of other model elements 
•Should be stateless(but may have side effects)
Services in Different Layers 
UI Layer 
& Application Layer 
Infrastructure 
Domain 
(“Application Core”) 
Message Sending 
Message Processing 
XML Parsing 
UI Services 
Transfer Between Accounts 
Process Order 
Send Email 
Log to a File
Domain Events 
“Use a Domain Event to capture an occurrence of something that happened in the domain.” 
Vaughn Vernon 
Implementing Domain-Driven Design
Domain Event Tips 
•Consider for cases of “whenthis happens, then…” 
•Or “Notify someone when…” 
•Domain events represent the past 
•They already happened 
•Thus, they should be immutable
Examples of Domain Events 
UserAuthenticated 
Appointment 
Confirmed 
PaymentReceived 
$¢£¥
Designing Domain Events 
•Each Event is a Class 
•Use a common interface (e.g. IDomainEvent) 
•Capture when the event took place 
•Include details 
•What would you need to know to trigger this event again? 
•Include identitiesof any entitiesinvolved 
•Initialize all state in constructor 
•No behavior or side effects –just state
More DDD Topics 
•Aggregates 
•Repositories 
•Factories 
DDD Fundamentals on Pluralsight 
Eric Evans’ DDD Book 
steve.smith@falafel.com
Domain Models and MVC Models 
•UI interacts directly with Domain Model 
•Entities, Value Objects 
•Interfaces, Services 
•Views may work with custom ViewModels 
•Client (HTML/JS) code may use another ViewModelas well
Controllers 
•Keep as small as possible 
•Eliminate business logic 
•Inject all dependencies
Views 
•No logic unless encapsulated in tested helpers 
•No business logic if it can instead be modeled in the domain
SignalR 
•Awesome addition to ASP.NET 
•Great for notifications to multiple users 
•Ties in easily with Domain Events
Solution Structure 
•Core 
•Interfaces 
•Model (Entities, Value Objects) 
•Domain Services 
•Infrastructure 
•DbContext 
•File Access 
•System Clock Access 
•Email services 
•Web 
•MVC Project 
•No direct use of Infrastructure
Demo 
Putting DDD into ASP.NET MVC
Domain-Driven Design with ASP.NET MVC

More Related Content

What's hot

What's hot (20)

Web api
Web apiWeb api
Web api
 
Big Data Redis Mongodb Dynamodb Sharding
Big Data Redis Mongodb Dynamodb ShardingBig Data Redis Mongodb Dynamodb Sharding
Big Data Redis Mongodb Dynamodb Sharding
 
CQRS and Event Sourcing
CQRS and Event Sourcing CQRS and Event Sourcing
CQRS and Event Sourcing
 
Kafka as an event store - is it good enough?
Kafka as an event store - is it good enough?Kafka as an event store - is it good enough?
Kafka as an event store - is it good enough?
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
A Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation SlidesA Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation Slides
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
Spring integration을 통해_살펴본_메시징_세계
Spring integration을 통해_살펴본_메시징_세계Spring integration을 통해_살펴본_메시징_세계
Spring integration을 통해_살펴본_메시징_세계
 
Design patterns for microservice architecture
Design patterns for microservice architectureDesign patterns for microservice architecture
Design patterns for microservice architecture
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Mucon 2019: OOps I DDD it again and again
Mucon 2019: OOps I DDD it again and againMucon 2019: OOps I DDD it again and again
Mucon 2019: OOps I DDD it again and again
 
Getting started with entity framework
Getting started with entity framework Getting started with entity framework
Getting started with entity framework
 
Event Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQEvent Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQ
 
Domain driven design
Domain driven designDomain driven design
Domain driven design
 
CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony application
 
Domain Driven Design Demonstrated
Domain Driven Design Demonstrated Domain Driven Design Demonstrated
Domain Driven Design Demonstrated
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 

Viewers also liked

Domain Driven Design in the Browser - Cameron Edwards
Domain Driven Design in the Browser - Cameron EdwardsDomain Driven Design in the Browser - Cameron Edwards
Domain Driven Design in the Browser - Cameron Edwards
Hakka Labs
 
Why Domain-Driven Design and Reactive Programming?
Why Domain-Driven Design and Reactive Programming?Why Domain-Driven Design and Reactive Programming?
Why Domain-Driven Design and Reactive Programming?
VMware Tanzu
 
Principles of microservices velocity
Principles of microservices   velocityPrinciples of microservices   velocity
Principles of microservices velocity
Sam Newman
 

Viewers also liked (14)

Architecting iOS Project
Architecting iOS ProjectArchitecting iOS Project
Architecting iOS Project
 
Domain-Driven Design (Artur Trosin Product Stream)
Domain-Driven Design (Artur Trosin Product Stream)Domain-Driven Design (Artur Trosin Product Stream)
Domain-Driven Design (Artur Trosin Product Stream)
 
Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#
 
Solid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven DesignSolid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven Design
 
Domain-driven design - tactical patterns
Domain-driven design - tactical patternsDomain-driven design - tactical patterns
Domain-driven design - tactical patterns
 
Automation of functional tests using JMeter Part II (in Polish)
Automation of functional tests using JMeter Part II (in Polish)Automation of functional tests using JMeter Part II (in Polish)
Automation of functional tests using JMeter Part II (in Polish)
 
Domain Driven Design in the Browser - Cameron Edwards
Domain Driven Design in the Browser - Cameron EdwardsDomain Driven Design in the Browser - Cameron Edwards
Domain Driven Design in the Browser - Cameron Edwards
 
2011 iska - tim m - domain driven design
2011   iska - tim m - domain driven design2011   iska - tim m - domain driven design
2011 iska - tim m - domain driven design
 
Architecture Principles CodeStock
Architecture Principles CodeStock Architecture Principles CodeStock
Architecture Principles CodeStock
 
Beyond design patterns and principles - writing good OO code
Beyond design patterns and principles - writing good OO codeBeyond design patterns and principles - writing good OO code
Beyond design patterns and principles - writing good OO code
 
Go-jek's Go-Food Chatbot
Go-jek's Go-Food ChatbotGo-jek's Go-Food Chatbot
Go-jek's Go-Food Chatbot
 
Why Domain-Driven Design and Reactive Programming?
Why Domain-Driven Design and Reactive Programming?Why Domain-Driven Design and Reactive Programming?
Why Domain-Driven Design and Reactive Programming?
 
Domain Driven Design Quickly
Domain Driven Design QuicklyDomain Driven Design Quickly
Domain Driven Design Quickly
 
Principles of microservices velocity
Principles of microservices   velocityPrinciples of microservices   velocity
Principles of microservices velocity
 

Similar to Domain-Driven Design with ASP.NET MVC

Android application development
Android application developmentAndroid application development
Android application development
Linh Vi Tường
 
Introduction to Neo4j for the Emirates & Bahrain
Introduction to Neo4j for the Emirates & BahrainIntroduction to Neo4j for the Emirates & Bahrain
Introduction to Neo4j for the Emirates & Bahrain
Neo4j
 

Similar to Domain-Driven Design with ASP.NET MVC (20)

Add Some DDD to Your ASP.NET MVC, OK?
Add Some DDD to Your ASP.NET MVC, OK?Add Some DDD to Your ASP.NET MVC, OK?
Add Some DDD to Your ASP.NET MVC, OK?
 
2019-Nov: Domain Driven Design (DDD) and when not to use it
2019-Nov: Domain Driven Design (DDD) and when not to use it2019-Nov: Domain Driven Design (DDD) and when not to use it
2019-Nov: Domain Driven Design (DDD) and when not to use it
 
Schibsted Spain - Day 1 - DDD Course
Schibsted Spain - Day 1 - DDD CourseSchibsted Spain - Day 1 - DDD Course
Schibsted Spain - Day 1 - DDD Course
 
Domain Driven Design Big Picture Strategic Patterns
Domain Driven Design Big Picture Strategic PatternsDomain Driven Design Big Picture Strategic Patterns
Domain Driven Design Big Picture Strategic Patterns
 
Lecture3
Lecture3Lecture3
Lecture3
 
Introduction to DDD
Introduction to DDDIntroduction to DDD
Introduction to DDD
 
An Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHPAn Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHP
 
Domain Driven Design - Building Blocks
Domain Driven Design - Building BlocksDomain Driven Design - Building Blocks
Domain Driven Design - Building Blocks
 
Designing microservices part2
Designing microservices part2Designing microservices part2
Designing microservices part2
 
Design for scale
Design for scaleDesign for scale
Design for scale
 
Pros & Cons of Microservices Architecture
Pros & Cons of Microservices ArchitecturePros & Cons of Microservices Architecture
Pros & Cons of Microservices Architecture
 
Implementing DDD Concepts in PHP
Implementing DDD Concepts in PHPImplementing DDD Concepts in PHP
Implementing DDD Concepts in PHP
 
Introduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregationIntroduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregation
 
Android application development
Android application developmentAndroid application development
Android application development
 
Applying Domain-Driven Design to craft Rich Domain Models
Applying Domain-Driven Design to craft Rich Domain ModelsApplying Domain-Driven Design to craft Rich Domain Models
Applying Domain-Driven Design to craft Rich Domain Models
 
Azure Digital Twins 2.0
Azure Digital Twins 2.0Azure Digital Twins 2.0
Azure Digital Twins 2.0
 
Software Architecture and Architectors: useless VS valuable
Software Architecture and Architectors: useless VS valuableSoftware Architecture and Architectors: useless VS valuable
Software Architecture and Architectors: useless VS valuable
 
Introduction to Neo4j for the Emirates & Bahrain
Introduction to Neo4j for the Emirates & BahrainIntroduction to Neo4j for the Emirates & Bahrain
Introduction to Neo4j for the Emirates & Bahrain
 
Why We Need Architects (and Architecture) on Agile Projects
Why We Need Architects (and Architecture) on Agile ProjectsWhy We Need Architects (and Architecture) on Agile Projects
Why We Need Architects (and Architecture) on Agile Projects
 
Xamarin 9/10 San Diego Meetup
Xamarin 9/10 San Diego MeetupXamarin 9/10 San Diego Meetup
Xamarin 9/10 San Diego Meetup
 

More from Steven Smith

More from Steven Smith (20)

Clean architecture with asp.net core by Ardalis
Clean architecture with asp.net core by ArdalisClean architecture with asp.net core by Ardalis
Clean architecture with asp.net core by Ardalis
 
Finding Patterns in the Clouds - Cloud Design Patterns
Finding Patterns in the Clouds - Cloud Design PatternsFinding Patterns in the Clouds - Cloud Design Patterns
Finding Patterns in the Clouds - Cloud Design Patterns
 
Introducing domain driven design - dogfood con 2018
Introducing domain driven design - dogfood con 2018Introducing domain driven design - dogfood con 2018
Introducing domain driven design - dogfood con 2018
 
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
 
Introducing Domain Driven Design - codemash
Introducing Domain Driven Design - codemashIntroducing Domain Driven Design - codemash
Introducing Domain Driven Design - codemash
 
Most Useful Design Patterns
Most Useful Design PatternsMost Useful Design Patterns
Most Useful Design Patterns
 
Improving the Design of Existing Software
Improving the Design of Existing SoftwareImproving the Design of Existing Software
Improving the Design of Existing Software
 
Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0
 
Decoupling with Domain Events
Decoupling with Domain EventsDecoupling with Domain Events
Decoupling with Domain Events
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016
Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016
Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016
 
Improving the Quality of Existing Software - DevIntersection April 2016
Improving the Quality of Existing Software - DevIntersection April 2016Improving the Quality of Existing Software - DevIntersection April 2016
Improving the Quality of Existing Software - DevIntersection April 2016
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
A Whirldwind Tour of ASP.NET 5
A Whirldwind Tour of ASP.NET 5A Whirldwind Tour of ASP.NET 5
A Whirldwind Tour of ASP.NET 5
 
Domain events
Domain eventsDomain events
Domain events
 
My Iraq Experience
My Iraq ExperienceMy Iraq Experience
My Iraq Experience
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
 
Improving The Quality of Existing Software
Improving The Quality of Existing SoftwareImproving The Quality of Existing Software
Improving The Quality of Existing Software
 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Recently uploaded (20)

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 

Domain-Driven Design with ASP.NET MVC

  • 1. Domain-Driven Designwith ASP.NET MVC Steve Smith CTO, Falafel Software @ardalis| steve.smith@falafel.com
  • 2. What is Domain-Driven Design (DDD)?
  • 3.
  • 4. Communication •Ubiquitous Language •Domain Expert Interaction Modeling •Core Domain •Generic Subdomains •Bounded Context •Context Map •Shared Kernel •Anti-Corruption Layer Implementation •Model-Driven Design •Layered Architecture •Entities •Value Objects •Services •Factories •Aggregates •Repositories •Domain Events
  • 5. DDD is BIG “The more you know, the more you realize you know nothing.” Socrates
  • 6. DDD Fundamentals Course •Over 4 hours of content (demos using MVC + SignalR) •http://bit.ly/PS-DDD
  • 7. DDD Benefits •Flexibility •Software models customer’s understanding of problem •Breaks complexity into manageable pieces •Well-organized; easily tested •Business logic lives in one place
  • 8. DDD Drawbacks •Time and Effort •Learning Curve •Overkill without Complexity •“Anemic” domain model problem
  • 9. Communication “As software developers, we fail in two ways: we build the thing wrong, or we build the wrong thing.” Me
  • 10.
  • 12. Language “A project faces serious problems when its language is fractured.” Eric Evans
  • 13. Ubiquitous Language •Ubiquitous–adjective. Present, appearing, or found everywhere. •Synonyms: pervasive, universal •Used within a given Bounded Context •Used in code, design documents, and conversations --Everywhere
  • 14. DomainTerms Domain Experts Problem Domain Core Domain Sub-Domains
  • 15. Bounded Contexts •Provide Separation of Concerns •Limit complexity •Should be clearly boundedand separate
  • 17. Appointment Scheduling Billing Anti- Corruption Layer
  • 18. Model Driven Design Not Data-Driven
  • 19. Layered Architecture •Ports and Adapters •Hexagonal •Onion
  • 20. Organizing in a Solution
  • 21. Entities “Many objects are not fundamentally defined by their attributes, but rather by a thread of continuity and identity.” Eric Evans
  • 22. Changing Attributes Doesn’t Change Which One We’re Talking About ID:1 •Name: Steve Smith •Twitter: @ardalis •Favorite Color: Blue ID: 1 •Name: StevenSmith •Twitter: @ardalis •Favorite Color: Blue ID: 1 •Name: Steven Smith •Twitter: @ardalis •Favorite Color: Orange
  • 23.
  • 24.
  • 25. Value Objects •Defined by their attributes •Immutable •Should have no side effects •Examples: strings, addresses, currency
  • 26.
  • 28. Domain Services •Not a natural part of an Entity or Value Object •Interfacedefined in terms of other model elements •Should be stateless(but may have side effects)
  • 29. Services in Different Layers UI Layer & Application Layer Infrastructure Domain (“Application Core”) Message Sending Message Processing XML Parsing UI Services Transfer Between Accounts Process Order Send Email Log to a File
  • 30. Domain Events “Use a Domain Event to capture an occurrence of something that happened in the domain.” Vaughn Vernon Implementing Domain-Driven Design
  • 31. Domain Event Tips •Consider for cases of “whenthis happens, then…” •Or “Notify someone when…” •Domain events represent the past •They already happened •Thus, they should be immutable
  • 32. Examples of Domain Events UserAuthenticated Appointment Confirmed PaymentReceived $¢£¥
  • 33. Designing Domain Events •Each Event is a Class •Use a common interface (e.g. IDomainEvent) •Capture when the event took place •Include details •What would you need to know to trigger this event again? •Include identitiesof any entitiesinvolved •Initialize all state in constructor •No behavior or side effects –just state
  • 34. More DDD Topics •Aggregates •Repositories •Factories DDD Fundamentals on Pluralsight Eric Evans’ DDD Book steve.smith@falafel.com
  • 35. Domain Models and MVC Models •UI interacts directly with Domain Model •Entities, Value Objects •Interfaces, Services •Views may work with custom ViewModels •Client (HTML/JS) code may use another ViewModelas well
  • 36. Controllers •Keep as small as possible •Eliminate business logic •Inject all dependencies
  • 37. Views •No logic unless encapsulated in tested helpers •No business logic if it can instead be modeled in the domain
  • 38. SignalR •Awesome addition to ASP.NET •Great for notifications to multiple users •Ties in easily with Domain Events
  • 39. Solution Structure •Core •Interfaces •Model (Entities, Value Objects) •Domain Services •Infrastructure •DbContext •File Access •System Clock Access •Email services •Web •MVC Project •No direct use of Infrastructure
  • 40. Demo Putting DDD into ASP.NET MVC