Académique Documents
Professionnel Documents
Culture Documents
CQRS
CQRS
NEXT STEPS
What is DDD?
isolate domain with
NEXT STEPS
evolve towards
HOW?
How?
Cesar de la Torre
Architect Evangelist Microsoft - DPE
" Blog: http://blogs.msdn.com/cesardelatorre * Email: cesardl@microsoft.com
| Architecture
| Architecture
| Architecture
| Architecture
| Architecture
Logic Layers
Physical Tiers
How?
Elaborating a Reference Architecture Guide for Complex Enterprise Apps Mapping Architecture & Design patterns to .NET 4.0 technologies
| Architecture
| Architecture
White Book
| Architecture
| Architecture
| Architecture
| Architecture
Sample Application based on our Domain Oriented NLayered Architectures with .NET 4.0 guide.
| Architecture
| Architecture
Communication with
Domain Experts
Developers Feedback
Development
| Architecture
| Architecture
| Architecture
DDD Definitions
| Architecture
DDD Definitions
| Architecture
Domain Model
| Architecture
DDD Definitions
Domain Model Helps us to solve specific problems in our Domain Is not necessarily realistic Forms the basics of a language Is not the only model
| Architecture
DDD Definitions
Ubiquitous Language: A language structured around the Domain model and used by all team members to conect all the activities of the team with the software.
It must be the same language used by the Domain Experts
| Architecture
DDD Definitions
Context: The setting in which a word or statement appears that determines its meaning
| Architecture
DDD Definitions
Bounded Context: An operational definition of where a particular model is well-defined and applicable (Typically a sub-system or the work owned by a particular team)
| Architecture
80%
| Architecture
20%
Building Blocks
(*) In our Architecture Guide we currently focus just on this area (20%)
Architecture
Domain Oriented N-Layered Architecture SOLID: Base Design & Dev. principles
| Architecture
| Architecture
Decople all Infrastructure Layers from the Domain Layer! Specific Architecture & Design DDD artifacts (Layers & Patterns) ORMs help a lot
Entity-Framework, NHibernate, etc.
| Architecture
| Architecture
DDD patterns
QUERY SPECIFICATIONS UNIT OF WORK
POCO / IPOCO
CQRS
| Architecture
Tasks
Applciation
Application Services
Domain
Domain Entities
Domain Services
Infrastructure
CrossCutting Infrastructure
(Security, Logging, etc.)
CrossCutting Infrastructure
(Security, Logging, etc.)
| Architecture
Fuentes Datos
Servicios Externos
UI Views
Controllers Svc Agents
UI Views
Controllers
Presentation
Application Layer
Tasks
App. Services
Operations
Security
Cache
Domain Layer
Domain Services
Domain Entities
Bases (SuperTypes)
Data Sources
External Services
| Architecture
Relation mapping to layers projects and .NET code We can even validate our Architecture diagram against actual .NET code in our solution!
| Architecture
| Architecture
Most Dependencies must be based on ABSTRACTIONS/INTERFACES (Ideally using IoC & Depend.Injection) Swappable Implementations
| Architecture
ENTITY pattern
Tasks
App. Services
Domain Services
Domain Entities
Bases (SuperTypes)
| Architecture
Entity pattern
Object that has its own Identity It is characterized by itself (Identity), not by its attributes Attributes can change, but its identity is always the same Continuous Trazability in Time It has its own logic situated within the entity class
No Anemic Domain Model (MFowler)
| Architecture
| Architecture
[DEMO]
-Implementing the Entity pattern: - EF T4 templates (POCO or STE) - EF Code-First approach
| Architecture
Value-Object pattern
Value-Object pattern
They have no Identity. They just describe things They are interchangeable, transitory They must be immutable.. When V-O or Entity? Depends on the Domain Model
Color Address Route between two cities
| Architecture
Person Entity
Person Entity
Address VALUEOBJECT
| Architecture
[DEMO]
- Implementing Value-Object pattern:
| Architecture
Aggregate pattern
Aggregate pattern
Objects within an Aggregate can reference other root entities When we delete a root-entity we must delete the whole aggregate (cascade delete)
| Architecture
Aggregates
| Architecture
| Architecture
Modules
They allow dividing a complex Domain Model in several simpler modules Divide and youll win Could be related to Domain Entity Models (1:1 or 1:many) We should seek for high internal cohesion and low coupling between several Modules Group by Domain concepts not by infrastructure/technical concepts Example:
| Architecture
Model delimitation. We must create explicit boundaries at code level managed by each development team
Anticorruption Layer
Special Layer to isolate Bounded Contexts. It can provide translation artifacts between several models
Shared Kernel
| Architecture
[DEMO]
- Implementing Modules:
| Architecture
Domain Services
They are the backbone, the glue in order to coordinate all the domain rules and entities logic
| Architecture
[DEMO]
- Implementing Domain Services:
| Architecture
| Architecture
| Architecture
Repository pattern
QUERY SPECIFICATIONS UNIT OF WORK
POCO / IPOCO
| Architecture
Nice to have
Having an ORM is much easier to implement the Repository and Unit of Work patterns. ORMs like:
Microsoft Entity-Framework NHibernate
| Architecture
V2.0
Mapping
Conceptual Models Independent from RDBMS ORM Linq pattern for entities
Conceptual Model
DAL class
Works directly against a DB/Data source Does not provide an object oriented view of the data For a developer it is like a object collection Provides an object oriented view of the data Separation between the Domain Model and the data mapping Layer
Repository class
| Architecture
| Architecture
Implementing Repositories
Using Layer Supertype
It allows to create common methods for all your Repositories Very powerful when using GENERICS Inject dependencies in the constructor (like Icontext depend.)
| Architecture
Implementing a Repository
| Architecture
[DEMO]
- Implementing Repositories:
| Architecture
| Architecture
UNIT OF WORK
POCO / IPOCO
| Architecture
| Architecture
[DEMO]
- Using UoW and Repository pattern from the Application Layer:
| Architecture
| Architecture
| Architecture
- Workflow-Services (WCF+WF)
| Architecture
CustomerService
Service Contract / Interface
Customer Entity
Query Specification
Repository CustomerRepository
SuperType
Domain Entity
Methods including Domain Logic within the entitity classes!! No Anemic Domain Application Service Repository
Application Layer
| Architecture
Domain Layer
Presentation Layer
| Architecture
Presentation Layer
Main Presentation Layer pattners and when to use them:
MVC Web and ASP.NET MVC MVP WinForms MVVM WPF & Silverlight
| Architecture
Cross-Cutting Layers
| Architecture
- Cache
Check-in counter
Passenger
Tokens Granter
(STS: Security Token Service)
Security Token
Web-Service Or Web-App
Security Token
Application Server
(Relaying Party)
WS-Trust Issue()
ADFS 2.0
(STS: Security Token Service)
Authentication
SAML token
App-Server
WIF API (Relaying Party)
Deployment patterns
- Physical Architectures - N-Tier Architectures - Security in Tiers
| Architecture
Presentation
Reads Model
Writes Model
(Queries)
(Domain Model)
| Architecture
Slide 92
Buy a product
Presentation
Commands
| Architecture
Slide 93
Presentation
DTO Query
(sync.)
ack Command (Async) Domain Model Persistence Writes Store Transactional Store
Commands Handler
Query
(Sync)
Reads Store
Events Handler
| Architecture
Slide 94
Next Steps
1
Download SampleApp from CODEPLEX
| Architecture
Contact
http://microsoftnlayerapp.codeplex.com/
Csar de la Torre
Architect Evangelist Microsoft DPE
| Architecture