DomainDriven Design Bounded Contexts Julie Lerman DEVB411 DomainDriven Design Fundamentals Automated Testing for Fraidy Cats Like Me Getting Started with Entity Framework 5 Entity Framework in the Enterprise ID: 645007
Download Presentation The PPT/PDF document "Entity Framework Model Partitioning in" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1Slide2
Entity FrameworkModel Partitioning inDomain-Driven Design Bounded Contexts
Julie Lerman
DEV-B411Slide3
Domain-Driven Design Fundamentals
Automated Testing for
Fraidy
Cats Like Me
Getting Started with Entity Framework 5
Entity Framework in the Enterprise
Entity Framework Code First MigrationsData Layer Validation with Entity Framework 4.1+Entity Framework 4.1 - DbContext Data AccessEntity Framework 4.1 - Code FirstQuerying the Entity FrameworkDesigner Supported EDM CustomizationEntity Framework and Data ModelsEntity Framework 4.0 By Example
My Courses onSlide4
Domain Driven Design“Forget about persistence”
Developer using EF:“But….but … but …”Slide5
Hard to Ignore
ORM
Concerns
Between
Bounded Contexts
Hard to Ignore
ORM Concerns
insideBounded ContextSlide6
Breaking Up is Hard to DoSlide7Slide8
Product
Management
Product
Inventory
Accounting
Sales
HumanResourcesShippingCustomerServiceMarketingSlide9
Product
Management
Sales
Human
Resources
Customer
ServiceMarketingSlide10
Domain-Driven Design, Eric Evans 2003
Bounded Context
Cells can exist because their membranes define what is in and out and determine what can pass.Slide11
Product
Management
Product
Inventory
Sales
ShippingSlide12
Programming 101
“Re-Use is Good”
“Duplication is Bad”
But re-purposing can be even harderSlide13
Accounting
Sales
Shipping
Customer
Service
Marketing
Whenis a Customera Customer?CustomerPurchaser
Recipient
Prospect
Existing C with History
PersonId
PersonId
PersonId
PersonId
A/C Holder
PersonId
PersonId
Customer
ManagementSlide14
Accounting
Sales
Shipping
Customer
Service
Marketing
Whenis a Customera Customer?CustomerCustomer
Recipient
Prospect
Existing C with History
PersonId
ContactId
ContactId
ContactId
A/C Holder
ContactId
ContactId
Contact
ManagementSlide15
Code-SmellSlide16
Not even aContact base class?Slide17
Shared Types
Shared KernelTightly coordinated Entities and Value ObjectsCommon schema and behavior
“Reduce duplication, but not eliminate it” (
Eric Evans, DDD book)
InheritanceInfrastructureNot domain typesFavor inheritance over implementationSlide18
Shared
Types
“Duplicate”
Types
Choose Where to Put the PainSlide19
Domain-Driven Design, Eric Evans 2003
Bounded
ContextSlide20
UniqueEntity Typesper
Bounded Context
Don’t share types from a common assembly
Don’t write application code that assumes BC types match
Guarantees each type works within its Bounded ContextSlide21
Overlapping DataSlide22
Data Model != Domain ModelSlide23
Can EF Handle Your Domain?
Entity Framework/Queries/Commands
Domain Model
Persistence Model
Payments
Invoices
CustomersDB Mappings,DB concerns,Follow EF rules
Domain Model
New
Database
Legacy
Database
Payments
Credit
Invoice
Payee
Payments
Credit
Invoice
Payee
CreditsSlide24
BC#1
Customer
Management
BC#2
Customers
(“Purchasers”)
BC#3Customers
Full CRUD
Id
Name
Addresses
Credit Data
Contact Info
Read, Update
Id
Name
Addresses
Contact Info
Read Only
Id
Name
Customers
Update
Id
Name
Addresses
Contact Info
Update
Shared DataSlide25
Green Field: Existing Database
Database to EDMX or Code FirstAllows smaller, distinct modelsOther problems associated with common DB remain
Extraneous navigations gone
Reshape Types (limitations)Slide26
DbContext
#1
DbContext
#2
DbContext
#3
Customers Table
IdName
Addresses
Credit Data
Contact Info
Customers Table
Id
Name
Addresses
Contact Info
Customers Table
Id
Name
Customers
EF Code First Migrations
?
?
?Slide27
DbContext
#1
DbContext
#2
DbContext
#3
Customers Table
IdName
Addresses
Credit Data
Contact Info
Customers Table
Id
Name
Addresses
Contact Info
Customers Table
Id
Name
Customers
EF Code First MigrationsSlide28
DbContext
#1
DbContext
#2
DbContext
#3
Master
Context
Customers
Migrations
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
DbContext
EF Code First MigrationsSlide29
Database per Bounded Context
BC#1
Customers
BC#2
Customers
BC#3
Customers
Customers
Customers
Customers
Customers Table
Id
Name
Addresses
Credit Data
Contact Info
Customers Table
Id
Name
Addresses
Contact Info
Customers Table
Id
NameSlide30
Database Schema per Bounded Context
BC#1
Customers
BC#2
Customers
BC#3
Customers
Customers
Customers
Customers
DB Schema 1
DB Schema 2
DB Schema 3
Full CRUD
Id
Name
Addresses
Credit Data
Contact Info
Read, Edit Addresses
Id
Name
Addresses
Contact Info
Read Only
Id
NameSlide31
Mirror Data Between Databases/Schemas
Contact
Management
Order
Management
Message
Queue
Service
(Azure Web Job)
Publish
Contact Data
Subscribe
Other
Service
Other
App
Other
Bounded ContextSlide32
DemoShare Data with QueuesSlide33
DemoShare Data with ServicesSlide34
Remember . . .Let DDD drive your
domain design, not EFHonor the
Boundaries
of Bounded Contexts
Recognize that “common types” are not so commonRe-purposing types is hard – harder than you think
Re-purposing data is hard – harder than you thinkMoving data between Bounded Contexts is easier…easier than you thinkSlide35
Further Reading/Viewing
Domain-Driven Design Fundamentals (Pluralsight), bit.ly/PS-DDDJimmy Bogard: Domain Modeling with EF Scorecard,
bit.ly/1x925bu
Julie Lerman: Some DDD+EF Resources
, bit.ly/1mDR2kdDDD Community Website, domaindrivedesign.org
Some DDD & EF Resources, Julie Lerman blog post bit.ly/1mDR2kdDomain-Driven Design, Tackling Complexity in the Heart of SoftwareEric Evans, Addison-Wesley, 2003Implementing Domain-Driven DesignVaughn Vernon , Addison-Wesley Professional, 2013Slide36
Domain-Driven Design Fundamentals
Automated Testing for
Fraidy
Cats Like Me
Getting Started with Entity Framework 5
Entity Framework in the Enterprise
Entity Framework Code First MigrationsData Layer Validation with Entity Framework 4.1+Entity Framework 4.1 - DbContext Data AccessEntity Framework 4.1 - Code FirstQuerying the Entity FrameworkDesigner Supported EDM CustomizationEntity Framework and Data ModelsEntity Framework 4.0 By Example
My Courses onSlide37
EF Concerns inside Bounded Context
Private SettersOne:One Relationships
Value Objects
Favor
1-way
navigationsEF Rules mess up my aggregate EF populates via reflectionRequires FK & Nav. Prop
Map as Complex Types*EF can handle itDitch EF relationship magic for Writes(Adapt CQRS concepts?)(Favor Value Objects)*Jimmy Bogard EF&DDD Scorecard: Wonky issues around null values. He prefers entitiesSlide38
Resources
Learning
Microsoft Certification & Training Resources
www.microsoft.com/learning
Developer Network
http://developer.microsoft.com
TechNet
Resources for IT Professionals
http://microsoft.com/technet
Sessions on Demand
http://channel9.msdn.com/Events/TechEdSlide39
http://www.visualstudio.com
http://blogs.msdn.com/b/developer-tools/
http://msdn.microsoft.com/vstudio
DEV Track Resources
visualstudio
@
visualstudio
visualstudioSlide40
TechEd Mobile app
for session evaluations
is
currently offline
SUBMIT YOUR TECHED EVALUATIONS
Fill out an evaluation via
CommNet Station/PC:
Schedule Builder
LogIn
:
europe.msteched.com/catalog
We value your feedback!Slide41
© 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.
The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.