SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Implementing DDD with C#
Pascal Laurin
May 2015
@plaurin78
pascal.laurin@outlook.com
www.pascallaurin.com
Microsoft C# MVP
MSDEVMTL user group organizer
Developer & Architect at GSoft
DDD Basics
Overall Architecture
Some Design Patterns to help
Questions
Agenda
Model-Driven Design and the Ubiquitous Language
Entities, Value Objects and Services
Aggregates
Factories
Repositories
Bounded Contexts and Context Map
Anticorruption Layers
Domain Driven Design Basics
Technology should have nothing to do with domain modeling of a
system
Put the domain at the center of the solution
Should use the domain language even in code (at the lowest level:
variable names)
Only one word per concept!
Use ULM if you like but simple diagrams should work too
User stories, use cases, etc.
Model-Driven Design and the Ubiquitous
Language
Order
Order line Product
* 1
Entities have identities
Value Objects don’t have identities (mostly immutable)
Use services only with complex operations requiring multiples
domain entities
Some team use services with anemic entities (better fit for functional
languages?)
Entities, Value Objects and Services
public class Money // Value Object
{
public decimal Amount { get; private set; }
public Currency Currency { get; private set; }
}
public class Product // Entity
{
public int Id { get; private set; }
public string Description { get; private set; }
}
Boundary around objects inside (can't access objects directly, must
go through the Root)
Enforce invariants of the Entities inside
Root Entity has global identity
Internal Entities have local identities
Contains no direct references to other Aggregates, only IDs
Aggregates
public class Product // Aggregate root
{
public int Id { get; private set; }
public int CatalogId { get; private set; }
public Money Price { get; private set; }
public void ChangePrice(Money newPrice)
{
}
}
For creation and initialization of complex objects structures
Respect invariants
Creation as an atomic unit (complete or fail, no partial)
Creates entire Aggregates
Can use simple constructor on Aggregate Root Entity if construction
is simple enough
Factories
public class ProductFactory
{
public Product CreatePhysicalProduct(string name, Weight weight,
Dimensions dimensions)
{
return new Product();
}
public Product CreateDigitalProduct(string name, StorageSize storageSize)
{
return new DigitalProduct();
}
}
Don’t use generic Repository<T>!
Don’t leak DAL concerns in the domain
Most DAL technology today already offer a generic abstraction
Mostly for mocking with unit testing
Repositories
public interface IProductRepository
{
Product LoadProductAggregateById(int id);
void AddNewProduct(Product product);
IEnumerable<Product> QueryProductsByCatalog(string catalogName);
IEnumerable<Product> QueryArchivedProducts(string catalogName);
IEnumerable<Product> QueryDiscountedProducts(string nameFilter,
DateTime? discountExpirationDateFilter, Money maxPriceFilter);
IQueryable<Product> GetById(int id);
IQueryable<Product> GetAll();
}
Split large domains into smaller ones
Especially if two vision of the same domain concept dependent of the
view point
Usually along departments or divisions lines, business units, etc.
Could be still be monolithic apps or separated apps
Bounded Contexts and Context Map
HR
Payroll
Employee
Security
Access
Control
Employee
Don’t pollute your domain with foreign concepts
Abstract external providers, partners, etc.
Translate between two different domains (Bounded Context) using
Adapters
Allow both to evolve independently
Anticorruption Layers
API
Adapter
HR
Payroll
Prep
Employee
Payroll (external)
?
Hexagonal architecture or Port and Adapter
Domain at the center
Demo solution
The overall architecture
Ports are API or contracts in and out of the domain
Adapters translate between Ports and external dependencies
Swap out external dependencies implementation using different
adapters or using mocks
Hexagonal architecture or Port and
Adapter
Domain
UI
API
Data Store
External
Services
Ports
Adapters
Push everything to the sides and concentrate on the middle
For big app components => Hexagonal architecture to split into
smaller chunk
Either monolithic app or micro-services
The Domain at the center of everything
Only testing the Domain
Testing at the Ports entering the Domain
Use mocks or stubs to replace the Adapters
14
Unit Tests
Domain
Unit Test
Mocks or
Stubs
Ports
Adapters
Only testing the Adapters
Testing at the Ports exiting the Domain
Adapters calling real external dependencies
15
Integration Tests
Domain
Integration
Test
Real external
dependencies
Ports
Adapters
Demo Solution
Interfaces and abstractions
Dependency injection
Bootstrapper
MVC, MVVM, MVP (UI)
Command & Query responsibility segregation
Design Patterns (and Architectural
Patterns)
Most useful to mock dependencies
Swap implementations by configuration
Do not overuse!
Interfaces and abstractions
ISomething
Implementation Mock
Inversion of Control
Domain should not depend on DAL, Web Services, IO, etc.
Construction, composition and life cycle of non-domain concerns stay
outside the domain (use Factories for domain objects)
Dependency injection
Presentation
Business
Data
Application startup code
Composition of the application, services and infrastructure code
Load configuration and setup
Should help write integration tests by replacing some external
dependencies in the tests
Bootstrapper
Presentation patterns
Mostly useful when unit testing and reuse if multiple platforms
targeting (mobile)
Model and View always separated
MVC, MVVM, MVP (UI)
View Controller
Model
Web site, web service, API
View ViewModel
Model
Desktop, SPA (data binding)
View Presenter
Model
Desktop (no data binding)
Queries are simple and have no side effect
All changes to entities go through commands
With CommandHandler to execute Command
Could still be using the same data store for both Command and
Query
Command Dispatcher
Command & Query Responsibility
Segregation
Presentation
Read
Repository
Read
DB
Write
Repository
CommandHandler
Write
DB
Controller
or API
Domain
Domain Driven Development improve the quality of the code by
Introducing useful design patterns to structure your application
Knowing where each piece of new code should go
Better communication by using the language of the domain in the team
Clear separation of business and non-business code
24
Conclusion
References
DDD book by Eric Evans
• http://www.amazon.ca/dp/0321125215
DDD Quickly
• http://www.infoq.com/minibooks/domain-driven-design-quickly
SlideShare of the presentation
• http://www.slideshare.net/PascalLaurin
BitBucket for the code
• https://bitbucket.org/pascallaurin/ddd-talk
@plaurin78
pascal.laurin@outlook.com
www.pascallaurin.com
Questions?

Weitere ähnliche Inhalte

Was ist angesagt?

Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignRyan Riley
 
Domain Driven Design(DDD) Presentation
Domain Driven Design(DDD) PresentationDomain Driven Design(DDD) Presentation
Domain Driven Design(DDD) PresentationOğuzhan Soykan
 
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 ModelsAlexander van Trijffel
 
Domain Driven Design: Zero to Hero
Domain Driven Design: Zero to HeroDomain Driven Design: Zero to Hero
Domain Driven Design: Zero to HeroFabrício Rissetto
 
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 Slidesthinkddd
 
Refactoring for Domain Driven Design
Refactoring for Domain Driven DesignRefactoring for Domain Driven Design
Refactoring for Domain Driven DesignDavid Berliner
 
Hexagonal architecture - message-oriented software design
Hexagonal architecture  - message-oriented software designHexagonal architecture  - message-oriented software design
Hexagonal architecture - message-oriented software designMatthias Noback
 
Domain Driven Design Introduction
Domain Driven Design IntroductionDomain Driven Design Introduction
Domain Driven Design Introductionwojtek_s
 
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven DesignModelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven DesignNaeem Sarfraz
 
Domain driven design
Domain driven designDomain driven design
Domain driven designits_skm
 
Domain driven design
Domain driven designDomain driven design
Domain driven designtatyaso
 
Domain Driven Design (Ultra) Distilled
Domain Driven Design (Ultra) DistilledDomain Driven Design (Ultra) Distilled
Domain Driven Design (Ultra) DistilledNicola Costantino
 
D2 domain driven-design
D2 domain driven-designD2 domain driven-design
D2 domain driven-designArnaud Bouchez
 
Introduction au Domain Driven Design
Introduction au Domain Driven DesignIntroduction au Domain Driven Design
Introduction au Domain Driven DesignDNG Consulting
 
Clean architecture
Clean architectureClean architecture
Clean architectureLieven Doclo
 
Brownfield Domain Driven Design
Brownfield Domain Driven DesignBrownfield Domain Driven Design
Brownfield Domain Driven DesignNicolò Pignatelli
 

Was ist angesagt? (20)

Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Domain Driven Design(DDD) Presentation
Domain Driven Design(DDD) PresentationDomain Driven Design(DDD) Presentation
Domain Driven Design(DDD) Presentation
 
Domain driven design
Domain driven designDomain driven design
Domain driven design
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
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
 
Domain driven design
Domain driven designDomain driven design
Domain driven design
 
Domain Driven Design: Zero to Hero
Domain Driven Design: Zero to HeroDomain Driven Design: Zero to Hero
Domain Driven Design: Zero to Hero
 
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
 
Refactoring for Domain Driven Design
Refactoring for Domain Driven DesignRefactoring for Domain Driven Design
Refactoring for Domain Driven Design
 
Hexagonal architecture - message-oriented software design
Hexagonal architecture  - message-oriented software designHexagonal architecture  - message-oriented software design
Hexagonal architecture - message-oriented software design
 
Domain Driven Design Introduction
Domain Driven Design IntroductionDomain Driven Design Introduction
Domain Driven Design Introduction
 
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven DesignModelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
 
Domain driven design
Domain driven designDomain driven design
Domain driven design
 
Domain driven design
Domain driven designDomain driven design
Domain driven design
 
Domain Driven Design (Ultra) Distilled
Domain Driven Design (Ultra) DistilledDomain Driven Design (Ultra) Distilled
Domain Driven Design (Ultra) Distilled
 
D2 domain driven-design
D2 domain driven-designD2 domain driven-design
D2 domain driven-design
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Introduction au Domain Driven Design
Introduction au Domain Driven DesignIntroduction au Domain Driven Design
Introduction au Domain Driven Design
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
Brownfield Domain Driven Design
Brownfield Domain Driven DesignBrownfield Domain Driven Design
Brownfield Domain Driven Design
 

Andere mochten auch

Domain-driven design - tactical patterns
Domain-driven design - tactical patternsDomain-driven design - tactical patterns
Domain-driven design - tactical patternsTom Janssens
 
Domain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVCDomain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVCSteven Smith
 
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 codeMatthias Noback
 
Architecture Principles CodeStock
Architecture Principles CodeStock Architecture Principles CodeStock
Architecture Principles CodeStock Steve Barbour
 
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
 
DDD patterns that were not in the book
DDD patterns that were not in the bookDDD patterns that were not in the book
DDD patterns that were not in the bookCyrille Martraire
 
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 DesignIrwansyah Irwansyah
 
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)IT Arena
 
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 designTim Mahy
 
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 EdwardsHakka Labs
 
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)Tieto Corporation
 
Principles of microservices velocity
Principles of microservices   velocityPrinciples of microservices   velocity
Principles of microservices velocitySam Newman
 

Andere mochten auch (14)

Domain-driven design - tactical patterns
Domain-driven design - tactical patternsDomain-driven design - tactical patterns
Domain-driven design - tactical patterns
 
Domain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVCDomain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVC
 
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
 
Architecture Principles CodeStock
Architecture Principles CodeStock Architecture Principles CodeStock
Architecture Principles CodeStock
 
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?
 
DDD patterns that were not in the book
DDD patterns that were not in the bookDDD patterns that were not in the book
DDD patterns that were not in the book
 
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
 
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)
 
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
 
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
 
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)
 
Principles of microservices velocity
Principles of microservices   velocityPrinciples of microservices   velocity
Principles of microservices velocity
 

Ähnlich wie Implementing DDD with C#

Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestSeb Rose
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The EnterpriseDaniel Egan
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9google
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstEnea Gabriel
 
SPCA2013 - Test-driven Development with SharePoint 2013 and Visual Studio
SPCA2013 - Test-driven Development with SharePoint 2013 and Visual StudioSPCA2013 - Test-driven Development with SharePoint 2013 and Visual Studio
SPCA2013 - Test-driven Development with SharePoint 2013 and Visual StudioNCCOMMS
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011YoungSu Son
 
Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2Daniel Egan
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxdanhaley45372
 
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 2018Steven Smith
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldDavid McCarter
 
Behaviour Driven Development V 0.1
Behaviour Driven Development V 0.1Behaviour Driven Development V 0.1
Behaviour Driven Development V 0.1willmation
 
Data Access Tech Ed India
Data Access   Tech Ed IndiaData Access   Tech Ed India
Data Access Tech Ed Indiarsnarayanan
 
Eclipse 40 - Eclipse Summit Europe 2010
Eclipse 40 - Eclipse Summit Europe 2010Eclipse 40 - Eclipse Summit Europe 2010
Eclipse 40 - Eclipse Summit Europe 2010Lars Vogel
 
Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)Kevin Schultz
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldDavid McCarter
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net coreSam Nasr, MCSA, MVP
 
A Lap Around Visual Studio 2010
A Lap Around Visual Studio 2010A Lap Around Visual Studio 2010
A Lap Around Visual Studio 2010Abram John Limpin
 

Ähnlich wie Implementing DDD with C# (20)

Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under Test
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The Enterprise
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9
 
Design pattern
Design patternDesign pattern
Design pattern
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code First
 
SPCA2013 - Test-driven Development with SharePoint 2013 and Visual Studio
SPCA2013 - Test-driven Development with SharePoint 2013 and Visual StudioSPCA2013 - Test-driven Development with SharePoint 2013 and Visual Studio
SPCA2013 - Test-driven Development with SharePoint 2013 and Visual Studio
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
 
Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
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
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real World
 
Behaviour Driven Development V 0.1
Behaviour Driven Development V 0.1Behaviour Driven Development V 0.1
Behaviour Driven Development V 0.1
 
Data Access Tech Ed India
Data Access   Tech Ed IndiaData Access   Tech Ed India
Data Access Tech Ed India
 
Eclipse 40 - Eclipse Summit Europe 2010
Eclipse 40 - Eclipse Summit Europe 2010Eclipse 40 - Eclipse Summit Europe 2010
Eclipse 40 - Eclipse Summit Europe 2010
 
Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real World
 
T4 presentation
T4 presentationT4 presentation
T4 presentation
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net core
 
A Lap Around Visual Studio 2010
A Lap Around Visual Studio 2010A Lap Around Visual Studio 2010
A Lap Around Visual Studio 2010
 

Mehr von Pascal Laurin

Tests automatisés java script
Tests automatisés java scriptTests automatisés java script
Tests automatisés java scriptPascal Laurin
 
7 astuces pour améliorer vos tests unitaires
7 astuces pour améliorer vos tests unitaires7 astuces pour améliorer vos tests unitaires
7 astuces pour améliorer vos tests unitairesPascal Laurin
 
L'amélioration des tests unitaires par le refactoring
L'amélioration des tests unitaires par le refactoringL'amélioration des tests unitaires par le refactoring
L'amélioration des tests unitaires par le refactoringPascal Laurin
 
Behaviour Driven Development with SpecFlow
Behaviour Driven Development with SpecFlowBehaviour Driven Development with SpecFlow
Behaviour Driven Development with SpecFlowPascal Laurin
 
Cloud design patterns
Cloud design patternsCloud design patterns
Cloud design patternsPascal Laurin
 

Mehr von Pascal Laurin (6)

Tests automatisés java script
Tests automatisés java scriptTests automatisés java script
Tests automatisés java script
 
7 astuces pour améliorer vos tests unitaires
7 astuces pour améliorer vos tests unitaires7 astuces pour améliorer vos tests unitaires
7 astuces pour améliorer vos tests unitaires
 
C# 6
C# 6C# 6
C# 6
 
L'amélioration des tests unitaires par le refactoring
L'amélioration des tests unitaires par le refactoringL'amélioration des tests unitaires par le refactoring
L'amélioration des tests unitaires par le refactoring
 
Behaviour Driven Development with SpecFlow
Behaviour Driven Development with SpecFlowBehaviour Driven Development with SpecFlow
Behaviour Driven Development with SpecFlow
 
Cloud design patterns
Cloud design patternsCloud design patterns
Cloud design patterns
 

Kürzlich hochgeladen

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Kürzlich hochgeladen (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

Implementing DDD with C#

  • 1. Implementing DDD with C# Pascal Laurin May 2015 @plaurin78 pascal.laurin@outlook.com www.pascallaurin.com Microsoft C# MVP MSDEVMTL user group organizer Developer & Architect at GSoft
  • 2. DDD Basics Overall Architecture Some Design Patterns to help Questions Agenda
  • 3. Model-Driven Design and the Ubiquitous Language Entities, Value Objects and Services Aggregates Factories Repositories Bounded Contexts and Context Map Anticorruption Layers Domain Driven Design Basics
  • 4. Technology should have nothing to do with domain modeling of a system Put the domain at the center of the solution Should use the domain language even in code (at the lowest level: variable names) Only one word per concept! Use ULM if you like but simple diagrams should work too User stories, use cases, etc. Model-Driven Design and the Ubiquitous Language Order Order line Product * 1
  • 5. Entities have identities Value Objects don’t have identities (mostly immutable) Use services only with complex operations requiring multiples domain entities Some team use services with anemic entities (better fit for functional languages?) Entities, Value Objects and Services public class Money // Value Object { public decimal Amount { get; private set; } public Currency Currency { get; private set; } } public class Product // Entity { public int Id { get; private set; } public string Description { get; private set; } }
  • 6. Boundary around objects inside (can't access objects directly, must go through the Root) Enforce invariants of the Entities inside Root Entity has global identity Internal Entities have local identities Contains no direct references to other Aggregates, only IDs Aggregates public class Product // Aggregate root { public int Id { get; private set; } public int CatalogId { get; private set; } public Money Price { get; private set; } public void ChangePrice(Money newPrice) { } }
  • 7. For creation and initialization of complex objects structures Respect invariants Creation as an atomic unit (complete or fail, no partial) Creates entire Aggregates Can use simple constructor on Aggregate Root Entity if construction is simple enough Factories public class ProductFactory { public Product CreatePhysicalProduct(string name, Weight weight, Dimensions dimensions) { return new Product(); } public Product CreateDigitalProduct(string name, StorageSize storageSize) { return new DigitalProduct(); } }
  • 8. Don’t use generic Repository<T>! Don’t leak DAL concerns in the domain Most DAL technology today already offer a generic abstraction Mostly for mocking with unit testing Repositories public interface IProductRepository { Product LoadProductAggregateById(int id); void AddNewProduct(Product product); IEnumerable<Product> QueryProductsByCatalog(string catalogName); IEnumerable<Product> QueryArchivedProducts(string catalogName); IEnumerable<Product> QueryDiscountedProducts(string nameFilter, DateTime? discountExpirationDateFilter, Money maxPriceFilter); IQueryable<Product> GetById(int id); IQueryable<Product> GetAll(); }
  • 9. Split large domains into smaller ones Especially if two vision of the same domain concept dependent of the view point Usually along departments or divisions lines, business units, etc. Could be still be monolithic apps or separated apps Bounded Contexts and Context Map HR Payroll Employee Security Access Control Employee
  • 10. Don’t pollute your domain with foreign concepts Abstract external providers, partners, etc. Translate between two different domains (Bounded Context) using Adapters Allow both to evolve independently Anticorruption Layers API Adapter HR Payroll Prep Employee Payroll (external) ?
  • 11. Hexagonal architecture or Port and Adapter Domain at the center Demo solution The overall architecture
  • 12. Ports are API or contracts in and out of the domain Adapters translate between Ports and external dependencies Swap out external dependencies implementation using different adapters or using mocks Hexagonal architecture or Port and Adapter Domain UI API Data Store External Services Ports Adapters
  • 13. Push everything to the sides and concentrate on the middle For big app components => Hexagonal architecture to split into smaller chunk Either monolithic app or micro-services The Domain at the center of everything
  • 14. Only testing the Domain Testing at the Ports entering the Domain Use mocks or stubs to replace the Adapters 14 Unit Tests Domain Unit Test Mocks or Stubs Ports Adapters
  • 15. Only testing the Adapters Testing at the Ports exiting the Domain Adapters calling real external dependencies 15 Integration Tests Domain Integration Test Real external dependencies Ports Adapters
  • 17. Interfaces and abstractions Dependency injection Bootstrapper MVC, MVVM, MVP (UI) Command & Query responsibility segregation Design Patterns (and Architectural Patterns)
  • 18. Most useful to mock dependencies Swap implementations by configuration Do not overuse! Interfaces and abstractions ISomething Implementation Mock
  • 19. Inversion of Control Domain should not depend on DAL, Web Services, IO, etc. Construction, composition and life cycle of non-domain concerns stay outside the domain (use Factories for domain objects) Dependency injection Presentation Business Data
  • 20. Application startup code Composition of the application, services and infrastructure code Load configuration and setup Should help write integration tests by replacing some external dependencies in the tests Bootstrapper
  • 21. Presentation patterns Mostly useful when unit testing and reuse if multiple platforms targeting (mobile) Model and View always separated MVC, MVVM, MVP (UI) View Controller Model Web site, web service, API View ViewModel Model Desktop, SPA (data binding) View Presenter Model Desktop (no data binding)
  • 22. Queries are simple and have no side effect All changes to entities go through commands With CommandHandler to execute Command Could still be using the same data store for both Command and Query Command Dispatcher Command & Query Responsibility Segregation Presentation Read Repository Read DB Write Repository CommandHandler Write DB Controller or API Domain
  • 23. Domain Driven Development improve the quality of the code by Introducing useful design patterns to structure your application Knowing where each piece of new code should go Better communication by using the language of the domain in the team Clear separation of business and non-business code 24 Conclusion
  • 24. References DDD book by Eric Evans • http://www.amazon.ca/dp/0321125215 DDD Quickly • http://www.infoq.com/minibooks/domain-driven-design-quickly SlideShare of the presentation • http://www.slideshare.net/PascalLaurin BitBucket for the code • https://bitbucket.org/pascallaurin/ddd-talk @plaurin78 pascal.laurin@outlook.com www.pascallaurin.com Questions?

Hinweis der Redaktion

  1. Show the projects (dependencies if not already done) First level in Business, Data and Presentation are domain concepts First level in Application and Infrastructure are non-domain concepts One test project per type: unit, integration, system, behaviour or functional
  2. Graph ou code?