consultant/mentor microsoft mvp, ineta speaker, aspinsider, mcp, vtdotnet leadercontact...

36

Upload: clarence-dawson

Post on 19-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog
Page 2: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

EF in Core Business Apps & Domain-Driven Design ApproachesJulie Lerman

DEV-B336

Page 3: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

consultant/mentorMicrosoft MVP, INETA Speaker,ASPInsider, MCP, VTdotNET Leader

[email protected]

blogtheDataFarm.com/blog

twitter@julielerman

book web siteLearnEntityFramework.com

Julie Lerman

Page 4: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

GoalsEF in yourArchitecture

DDDBounded Context

Repository Pattern(s)& Unit of Work

Entities&Aggregates

Testing

Page 5: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Database

Data Access

UI

LINQ

& some Logic

Busines

s Logic

Page 6: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Separation of Concerns

Extensible

Adaptable Testable

Maintainable

Sensible!

Page 7: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

UIBusiness/Domain LayerRepository/Unit of Work

Infrastructure/Data Access

Entity Framework

LINQTests

Tests

Database

Service Layer

Page 8: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Considering Context

Page 9: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Entity Framework DbContext

The “We Sell Stuff” Domain

CustomersSales

OrdersProducts

PaymentsShipments

Shippers

Promotions

SalesPeopleEmployees

SalaryHistory

Returns

Page 10: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Delimits the applicability of a particular model.

BOUNDING CONTEXTS gives team members

a clear and shared understanding of what has to be consistent

andwhat can develop independently.

- Domain Driven Design, Eric Evans 2003

“bounded context”

Page 11: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

- Domain Driven Design, Eric Evans 2003

Page 12: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Bounded Contexts within a Domain

Customer Service

SalesBilling

Returns

Human Resources

Shipping

Marketing

Page 13: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Bounded Contexts within a Domain

Customer Service

SalesBilling

Returns Marketing

Human Resources

Shipping

Customers

SalesPeople

Shipments

Shippers

Order

Order

Items

Customer

ShipAddress

Customer

Order

Customer

Payments

Employee

SalaryHistory

Order

Customer

RMA

Credit

Items

Customer Service

Customer

SalesPerson

Addresses

ContactHistory

Promotion

Customers

Communications

Page 14: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Bounded Contexts within a Domain

Customer Service

SalesBilling

Returns Marketing

Human Resources

Shipping

Customers

SalesPeople

Shipments

Shippers

Order

ShipAddress

Payments

Employee

SalaryHistoryCustomer

RMA

Credit

Customer Service

Customer

SalesPerson

Addresses

ContactHistory

Promotion

Communications

ItemsToShip

Recipient

ItemsOrdered

Purchaser

Invoice

Payee

ItemReturned

Order Contacts

“Ubiquitous

Language”

Page 15: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Entities, Aggregates, etc.

Page 16: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Collection<EntityA>

Aggregate : Graph of Objects“Parent”

Entity

RelatedEntityA

Related Entity B

RelatedEntityA

RelatedEntityA

Aggregate Root

Page 17: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

The Purchase

Aggregates & Aggregate Roots

Customer Order Stuff I

WantID

Page 18: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Sometimes . . .

All You Need Is CRUD

Page 19: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

So . . .

What aboutthose mappings?Aggregat

e RootsValue

Objects

Page 20: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Can EF Handle Your Domain?

Entity Framework/Queries/Commands

Domain Model

PersistenceModel

Payments

InvoicesCustomers

DB Mappings,DB concerns,Follow EF rules

Domain Model

NewDatabas

e

LegacyDatabas

e

Payments

Credit

Invoice

Payee

Payments

Credit

Invoice

Payee

Credits

Page 21: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Repository &Unit of Work

Page 22: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Repository Essential:

“EncapsulateRedundantData Access

Code”

Page 23: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

UIBusiness/Domain LayerRepository/Unit of Work

Infrastructure/Data Access

Entity Framework

LINQTests

Tests

Database

Service Layer

Page 24: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Basic RepositoryGet

Store

GetOrderById

AddOrder

RemoveOrder

GetAllOrders

GetCurrentOrders

GetCachedOrders

GetOrdersForCustomer

Remove

GetOrdersForProduct

Persist

Page 25: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Many variations…

One repo per

type? Read repos?Write

repos?

One repo per

aggregate?One

repo per

context?

Page 26: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Get

Store

Send to DB

Remove

Get

Store

Send to DB

Remov

e

CustomerRepo

Order Repo

Get

Store

Send to DB

Remove

AddressRepo

Customer

Orders

Addresses

Aggregate

Root

Order

Items

Page 27: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Testing with EF in the MixIntegratio

n/Interactio

n Tests

Unit Tests

EF Validation, State: No biggieDB: DropCreateDatabaseAlways No EF involved: Inconsequential

EF in the way: Abstraction/Interfaces/Mocking Lightweight DB e.g., MySql Refactor?

Page 28: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Unit of Work

Classes

UI

Testability: Faking EF

Tests

System.Data.Entity

Metadata &DbContexts

FakeContext & DataA

FakeDbSet

FakeContext & Data B

ositoriesositoriesositoriesRepositories

ClassesClassesClasses

Page 29: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

SummarySave DB concerns for *later*Bounding contexts reduces complexitySometimes CRUD is all you needUse Aggregate Roots to manage graph objectsRepositories are a gateway to your dataAiming for Testability can Aid in Separating Concerns

Page 30: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

ResourcesPluralsight On-Demand Training: pluralsight.comMSDN Developer Center: msdn.com/data/efEF Team: blogs.msdn.com/adonetLearnEntityFramework.comProgramming Entity Framework: DbContext

by Julie Lerman and Rowan Miller, O’Reilly Media, Feb 22 2012

“Domain Driven Design” Eric Evans, Addison-Wesley, 2003

“Implementing Domain Driven Design”, Vaughn Vernon, 2013

“N-Layered Domain-Oriented Architecture Guide with .NET 4.0” by César de la Torre, Unai Zorrilla, Javier Calvarro and Miguel Ángel Ramos (May 20, 2011)

domaindrivendesign.org“Separation of Concerns”, MSDN Magazine, http://juliel.me/Jhp6Pp

Page 31: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

consultant/mentorMicrosoft MVP, INETA Speaker,ASPInsider, MCP, VTdotNET Leader

[email protected]

blogtheDataFarm.com/blog

twitter@julielerman

book web siteLearnEntityFramework.com

Julie Lerman

Page 32: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Related contentPositioning MS Dev Techs for Custom App Development(DEVB204) Cesar de la Torre

Developing Core Business Apps with DDD and .NET(DEV-B311) Jimmy Nilsson

Real Experiences & Architectural DDD Patterns Applied on .NET(DEV-B343) Per Rovegård

Entity Framework in Core Business Apps & DDD Approaches(DEV-B336) Julie Lerman

.NET Event Driven Applications, CQRS & Event-Sourcing in Mission-Critical Apps(DEVB401) June 6 10:15AM-11:30AM Greg YoungUnderstanding Dependency Injection and Those Pesky Containers(DEVB207) June 6 2:45PM-4:00PM Miguel Castro

TODAY

Page 33: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

msdn

Resources for Developers

http://microsoft.com/msdn

Learning

Microsoft Certification & Training Resources

www.microsoft.com/learning

TechNet

Resources

Sessions on Demand

http://channel9.msdn.com/Events/TechEd

Resources for IT Professionals

http://microsoft.com/technet

Page 34: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Complete an evaluation on CommNet and enter to win!

Page 35: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

Evaluate this session

Scan this QR code to evaluate this session and be automatically entered in a drawing to win a prize

Page 36: consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leadercontact jlerman@theDataFarm.com  twitter theDataFarm.com/blog

© 2013 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.