net applying domain-driven design jimmy nilsson

23
.NET Applying Domain-Driven Design Jimmy Nilsson

Upload: dangtuyen

Post on 07-Jan-2017

249 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: NET Applying Domain-Driven Design Jimmy Nilsson

.NET

Applying Domain-Driven Design

Jimmy Nilsson

Page 2: NET Applying Domain-Driven Design Jimmy Nilsson

About Jimmy Nilsson

• Primarily a developer, but also a trainer and author

• Blogs at www.jnsk.se/weblog/

• Author of ”Applying Domain-Driven Design and Patterns” and ”.NET Enterprise Design”

Page 3: NET Applying Domain-Driven Design Jimmy Nilsson

Main Focus of DDD?

• The core is the main focus!

• Forget distractions!

Page 4: NET Applying Domain-Driven Design Jimmy Nilsson

?1

Relational

database

Page 5: NET Applying Domain-Driven Design Jimmy Nilsson

Why DDD?

Why DDD?

Knowledge-rich design

Mappingto domain

Reduced complexity

Testability

Maintainability

• Etc, etc...

Page 6: NET Applying Domain-Driven Design Jimmy Nilsson

Problem Description

• A complex, large scale and long lived order application will be built

• Some very simple examples of requirements:• Order has a customer, customer has orders

• Order has one or more lines

• Order has a value

• Customer has address

• ...

Page 7: NET Applying Domain-Driven Design Jimmy Nilsson

Transaction Script [PoEAA]

+RunScript1()

+RunScript2()

TransactionScriptA

+Run()

TransactionScript

+Run()

ConcreteTransactionScriptA

+Run()

ConcreteTransactionScriptB

Page 8: NET Applying Domain-Driven Design Jimmy Nilsson

Table Module [PoEAA]

+Process1(in id)

+Process2()

TableModuleRecordSet

1

Page 9: NET Applying Domain-Driven Design Jimmy Nilsson

Domain Model [PoEAA]

1

Page 10: NET Applying Domain-Driven Design Jimmy Nilsson

• Because of the problem description, we choose Domain Model

• Now we need a Domain Model style...

Page 11: NET Applying Domain-Driven Design Jimmy Nilsson

Entities [DDD]

+CustomerId

+Name

+AverageSalesVolume

+ProductCategory

Customer

+SalesRepresentative

+Priority

+ContactPhone

+ContactAddress

SalesContact

1

1

+CustomerId

+Name

+ContactPhone

+ContactAddress

Customer

+SalesRepresentative

+Priority

SalesContact

1

1

+AverageSalesVolume

+ProductCategory

BusinessLine

1 1

Page 12: NET Applying Domain-Driven Design Jimmy Nilsson

Value Objects [DDD]

+CustomerId

+Name

+Street

+City

+State

Customer+CustomerId

+Name

Customer

+Street

+City

+State

Address

1

1

Page 13: NET Applying Domain-Driven Design Jimmy Nilsson

Aggregates [DDD]

«Aggregate Root»

Car

«Aggregate Root»

Engine

Customer

Wheel

TirePosition

1

41

4

*

Page 14: NET Applying Domain-Driven Design Jimmy Nilsson

Repositories [DDD]

client repository database

selection criteria

matching objects Delegate

Page 15: NET Applying Domain-Driven Design Jimmy Nilsson

Factories [DDD]

client FACTORY product

new(parameters)

product Create

Page 16: NET Applying Domain-Driven Design Jimmy Nilsson

What problems remain?

• Infrastructure...

• Assumption 1: Relational database

• How?

• Assumption 2: O/R Mapping

• Which?

• Assumption 3: For eg NHibernate

Page 17: NET Applying Domain-Driven Design Jimmy Nilsson

NHibernate• Domain Model style: POCO / Persistent Ignorant (PI)

• Mapper style: Framework

• Start with: Domain Model, Tables, Metadata

• API-Focus: Domain Model

• Query language: String-based, Query Object-based

• Open source, production version

• Many databases are supported

• Port of Hibernate 2.0.3

• Focus: ”Only” O/R Mapping

Page 18: NET Applying Domain-Driven Design Jimmy Nilsson

Data Mapper [PoEAA]

• For example Customer.hbm.xml

• <class name="Customer" table="Customers">

• <id name="Id" access="field">

• <unsaved-value="00000000-0000-0000-000000000000”>

• <generator class="guid.comb" />

• </id>

• <property name="Name" access="field.camelcase-underscore" />

Page 19: NET Applying Domain-Driven Design Jimmy Nilsson

CRUD – C• _session.Reconnect();

• try

• {

• _session.SaveOrUpdate(customer);

• _session.Flush();

• }

• finally

• {

• _session.Disconnect();

• }

Page 20: NET Applying Domain-Driven Design Jimmy Nilsson

CRUD – R

• (Customer)_session

• .Load(typeof(Customer), id);

Page 21: NET Applying Domain-Driven Design Jimmy Nilsson

Summary...

?1

Relational

database

Page 22: NET Applying Domain-Driven Design Jimmy Nilsson

References

• [DDD] Eric Evans; Domain-Driven Design

• [PoEAA] Martin Fowler; Patterns of Enterprise Application Architecture

• [NHibernate] nhibernate.sourceforge.net

• [ADDDP] Jimmy Nilsson; Applying Domain-Driven Design and Patterns

Page 23: NET Applying Domain-Driven Design Jimmy Nilsson

Remember! Enter the evaluation form and be a part of making Øredev even better.

You will automatically be part of the lottery tomorrow