domain driven design using.net dave rael. what’s wrong with this code? public void...

17
Domain Driven Design Using .NET Dave Rael

Upload: georgia-hines

Post on 21-Jan-2016

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Domain Driven Design Using.NET Dave Rael. What’s wrong with this code? Public void CallMethodThatMightThrowScaryException(int carelessInputWithoutValidation)

Domain Driven Design

Using .NET

Dave Rael

Page 2: Domain Driven Design Using.NET Dave Rael. What’s wrong with this code? Public void CallMethodThatMightThrowScaryException(int carelessInputWithoutValidation)

What’s wrong with this code?Public void CallMethodThatMightThrowScaryException(int carelessInputWithoutValidation)

{

{

MethodThatMightThrowScaryException(carelessInputWithoutValidation);

}

catch (Exception exception)

{

HandleException(exception);

}

}

Page 3: Domain Driven Design Using.NET Dave Rael. What’s wrong with this code? Public void CallMethodThatMightThrowScaryException(int carelessInputWithoutValidation)

“There is no try.”

Page 4: Domain Driven Design Using.NET Dave Rael. What’s wrong with this code? Public void CallMethodThatMightThrowScaryException(int carelessInputWithoutValidation)
Page 5: Domain Driven Design Using.NET Dave Rael. What’s wrong with this code? Public void CallMethodThatMightThrowScaryException(int carelessInputWithoutValidation)

Why Domain-Driven?

• Collaboration

• Ubiquitous Language

• Using Composition to address complexity in large systems

• “Not all of a large system will be well-designed.” –Eric Evans

• “Is BDD the same as TDD? Yes. If you’re a programmer, and your entire team is programmers, and all your stakeholders are programmers…” –Dan North http://dannorth.net/2012/05/31/bdd-is-like-tdd-if/

Page 6: Domain Driven Design Using.NET Dave Rael. What’s wrong with this code? Public void CallMethodThatMightThrowScaryException(int carelessInputWithoutValidation)

The alternative – One database schema to rule them all

Page 7: Domain Driven Design Using.NET Dave Rael. What’s wrong with this code? Public void CallMethodThatMightThrowScaryException(int carelessInputWithoutValidation)

Pain!

Page 8: Domain Driven Design Using.NET Dave Rael. What’s wrong with this code? Public void CallMethodThatMightThrowScaryException(int carelessInputWithoutValidation)

Bounded Contexts

Page 9: Domain Driven Design Using.NET Dave Rael. What’s wrong with this code? Public void CallMethodThatMightThrowScaryException(int carelessInputWithoutValidation)

Bounded Contexts (or Services) (or Silos)

Page 10: Domain Driven Design Using.NET Dave Rael. What’s wrong with this code? Public void CallMethodThatMightThrowScaryException(int carelessInputWithoutValidation)

Domain-Driven Design

Ubiquitous Language

Bounded Contexts

Domain Events

Top-Level System Architecture

Page 11: Domain Driven Design Using.NET Dave Rael. What’s wrong with this code? Public void CallMethodThatMightThrowScaryException(int carelessInputWithoutValidation)

Domain Driven Design

Ubiquitous Language

Aggregates

CQRS

Architecture/Implementation Within a Bounded Context

Page 12: Domain Driven Design Using.NET Dave Rael. What’s wrong with this code? Public void CallMethodThatMightThrowScaryException(int carelessInputWithoutValidation)

Fitting It Together

public interface IDomainDrivenDesign { }

public abstract class ServiceOrientedArchitecture : IDomainDrivenDesign { }

public class YourDomain : ServiceOrientedArchitecture { }

Page 13: Domain Driven Design Using.NET Dave Rael. What’s wrong with this code? Public void CallMethodThatMightThrowScaryException(int carelessInputWithoutValidation)

Commands

• Sent rather than Published

• Imperative

• Issued with authority to command (within a bounded context)

• DestroyPlanetCommand

• LaunchProtonTorpedoesCommand

Page 14: Domain Driven Design Using.NET Dave Rael. What’s wrong with this code? Public void CallMethodThatMightThrowScaryException(int carelessInputWithoutValidation)

Events

• Published rather than Sent

• Past-tense

• Describe an event that has already happened

• “Look what I have done!”

• PlanetDestroyedEvent

• ProtonTorpedoesLaunchedEvent

• UrineDepositedInToiletEvent

Page 15: Domain Driven Design Using.NET Dave Rael. What’s wrong with this code? Public void CallMethodThatMightThrowScaryException(int carelessInputWithoutValidation)

Commands And EventsBus.Send<BringYoungSkywalkerToMeCommand>();

Bus.Reply<AsYouWishMyMasterResponse>();

Bus.Publish<BroughtLukeBeforeMasterEvent>();

Bus.Publish<IHaveForseenItEvent>();

Page 17: Domain Driven Design Using.NET Dave Rael. What’s wrong with this code? Public void CallMethodThatMightThrowScaryException(int carelessInputWithoutValidation)

You will use a Domain-DrivenDesign Approach