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 (Ultra) Distilled
Domain Driven Design (Ultra) DistilledDomain Driven Design (Ultra) Distilled
Domain Driven Design (Ultra) DistilledNicola Costantino
 
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
 
Microservice Architecture
Microservice ArchitectureMicroservice Architecture
Microservice ArchitectureNguyen Tung
 
Domain Driven Design(DDD) Presentation
Domain Driven Design(DDD) PresentationDomain Driven Design(DDD) Presentation
Domain Driven Design(DDD) PresentationOğuzhan Soykan
 
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
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignRyan Riley
 
CQRS: Command/Query Responsibility Segregation
CQRS: Command/Query Responsibility SegregationCQRS: Command/Query Responsibility Segregation
CQRS: Command/Query Responsibility SegregationBrian Ritchie
 
Microservice vs. Monolithic Architecture
Microservice vs. Monolithic ArchitectureMicroservice vs. Monolithic Architecture
Microservice vs. Monolithic ArchitecturePaul Mooney
 
Domain Driven Design Demonstrated
Domain Driven Design Demonstrated Domain Driven Design Demonstrated
Domain Driven Design Demonstrated Alan Christensen
 
Clean architecture
Clean architectureClean architecture
Clean architecture.NET Crowd
 
NET304_Deep Dive into the New Network Load Balancer
NET304_Deep Dive into the New Network Load BalancerNET304_Deep Dive into the New Network Load Balancer
NET304_Deep Dive into the New Network Load BalancerAmazon Web Services
 
Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)Tom Kocjan
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignNader Albert
 
Git branching strategies
Git branching strategiesGit branching strategies
Git branching strategiesjstack
 
Azure Logic Apps
Azure Logic AppsAzure Logic Apps
Azure Logic AppsBizTalk360
 
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
 
Monoliths and Microservices
Monoliths and Microservices Monoliths and Microservices
Monoliths and Microservices Bozhidar Bozhanov
 

Was ist angesagt? (20)

Domain Driven Design (Ultra) Distilled
Domain Driven Design (Ultra) DistilledDomain Driven Design (Ultra) Distilled
Domain Driven Design (Ultra) Distilled
 
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
 
Microservice Architecture
Microservice ArchitectureMicroservice Architecture
Microservice Architecture
 
Domain Driven Design(DDD) Presentation
Domain Driven Design(DDD) PresentationDomain Driven Design(DDD) Presentation
Domain Driven Design(DDD) Presentation
 
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
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
CQRS: Command/Query Responsibility Segregation
CQRS: Command/Query Responsibility SegregationCQRS: Command/Query Responsibility Segregation
CQRS: Command/Query Responsibility Segregation
 
Microservice vs. Monolithic Architecture
Microservice vs. Monolithic ArchitectureMicroservice vs. Monolithic Architecture
Microservice vs. Monolithic Architecture
 
Domain Driven Design Demonstrated
Domain Driven Design Demonstrated Domain Driven Design Demonstrated
Domain Driven Design Demonstrated
 
CQRS
CQRSCQRS
CQRS
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
NET304_Deep Dive into the New Network Load Balancer
NET304_Deep Dive into the New Network Load BalancerNET304_Deep Dive into the New Network Load Balancer
NET304_Deep Dive into the New Network Load Balancer
 
Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Git branching strategies
Git branching strategiesGit branching strategies
Git branching strategies
 
Azure Logic Apps
Azure Logic AppsAzure Logic Apps
Azure Logic Apps
 
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
 
Monoliths and Microservices
Monoliths and Microservices Monoliths and Microservices
Monoliths and Microservices
 
Domain Driven Design
Domain Driven Design Domain Driven Design
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
 
Domain Driven Design Quickly
Domain Driven Design QuicklyDomain Driven Design Quickly
Domain Driven Design QuicklyMariam Hakobyan
 
Principles of microservices velocity
Principles of microservices   velocityPrinciples of microservices   velocity
Principles of microservices velocitySam Newman
 

Andere mochten auch (15)

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)
 
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
 

Ä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

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Kürzlich hochgeladen (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

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?