Domain Driven Design Using.NET Dave Rael. What’s wrong with this code? Public void...

Preview:

Citation preview

Domain Driven Design

Using .NET

Dave Rael

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

{

{

MethodThatMightThrowScaryException(carelessInputWithoutValidation);

}

catch (Exception exception)

{

HandleException(exception);

}

}

“There is no try.”

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/

The alternative – One database schema to rule them all

Pain!

Bounded Contexts

Bounded Contexts (or Services) (or Silos)

Domain-Driven Design

Ubiquitous Language

Bounded Contexts

Domain Events

Top-Level System Architecture

Domain Driven Design

Ubiquitous Language

Aggregates

CQRS

Architecture/Implementation Within a Bounded Context

Fitting It Together

public interface IDomainDrivenDesign { }

public abstract class ServiceOrientedArchitecture : IDomainDrivenDesign { }

public class YourDomain : ServiceOrientedArchitecture { }

Commands

• Sent rather than Published

• Imperative

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

• DestroyPlanetCommand

• LaunchProtonTorpedoesCommand

Events

• Published rather than Sent

• Past-tense

• Describe an event that has already happened

• “Look what I have done!”

• PlanetDestroyedEvent

• ProtonTorpedoesLaunchedEvent

• UrineDepositedInToiletEvent

Commands And EventsBus.Send<BringYoungSkywalkerToMeCommand>();

Bus.Reply<AsYouWishMyMasterResponse>();

Bus.Publish<BroughtLukeBeforeMasterEvent>();

Bus.Publish<IHaveForseenItEvent>();

You will use a Domain-DrivenDesign Approach

Recommended