Presentation is loading. Please wait.

Presentation is loading. Please wait.

Domain-Driven Design for the Database-Driven Mind

Similar presentations


Presentation on theme: "Domain-Driven Design for the Database-Driven Mind"— Presentation transcript:

1 Domain-Driven Design for the Database-Driven Mind
Julie Lerman theDataFarm.com @julielerman

2 My Courses on Getting Started with EF6
Domain-Driven Design Fundamentals Looking Ahead to Entity Framework 7 EF6 Ninja Edition: What’s New in EF6 Automated Testing for Fraidy Cats Like Me Getting Started with Entity Framework 5 Entity Framework in the Enterprise Entity Framework Code First Migrations Data Layer Validation with Entity Framework 4.1+ Entity Framework DbContext Data Access Entity Framework Code First Querying the Entity Framework Designer Supported EDM Customization Entity Framework and Data Models Entity Framework 4.0 By Example

3 Your Workflow? Software Solution

4 database domain

5 Forget persistence? What about shared data & types? How will DDD
patterns resolve with my ORM?

6 Value of Domain-Driven Design
Patterns for Implementing Persistence for DDD

7 Focus on the Business Problem

8 Data Storage is not the Business Problem

9 Domain Problem Cross-Cutting Concerns Data Persistence

10 DDD Thinking: Divide and Conquer
Bounded Context Bounded Context Bounded Context Bounded Context Human Resources Production Shipping Sales

11 Each Bounded Context Learn & Evolve Design with Domain Experts
Software Implementation public class Customer{ } “Customer” private Customer (string Name, Date regDate){} public static Create (string Name, Date regDate){ return new Customer(name,regDate); “A Customer Registers” Register Ubiquitous Language

12 Domain-Driven Design Thinking
Bounded Context Bounded Context Bounded Context Bounded Context Ubiquitous Language Domain Model Types Rules Ubiquitous Language Domain Model Types Rules Ubiquitous Language Domain Model Types Rules Ubiquitous Language Domain Model Types Rules

13 Entities: More than data containers
Anemic Type for CRUD Rich Domain Model for DDD public class Schedule : Entity<Guid> { public int ClinicId { get; private set; } public DateTimeRange DateRange { get; private set; } private List<Appointment> _appointments; public IEnumerable<Appointment> Appointments {...} public Schedule(Guid id, DateTimeRange dateRange, int clinicId, IEnumerable<Appointment> appointments) : base(id) { ... MarkConflictingAppointments(); DomainEvents.Register<AppointmentUpdatedEvent>(Handle); } public Appointment AddNewAppointment(Appointment appt) { if (_appointments.Any(a => a.Id == appt)) { throw new ArgumentException(“Duplicate", "appointment"); } appt.State = TrackingState.Added; _appointments.Add(appt); public class Patient { public int Id { get; set; } public Client PetOwner { get; set; } public int ClientId { get; set; } public string Name { get; set; } public Gender Gender { get; set; } public int? DoctorId { get; set; } } private private

14 No Shared Data? No Shared Types? PANIC!

15 Data Sharing Patterns & Anti-Patterns
Bad (No-Op) Read/Write from BCs to common tables Good* Read reference data from shared tables Write BC types to different tables Better Each BC persists to its own tables Best Database or DB Schema per model Even Better than Best Event Sourcing (rather than persist state) Bounded Context Ubiquitous Language Domain Model Types Rules Bounded Context Ubiquitous Language Domain Model Types Rules Bounded Context Ubiquitous Language Domain Model Types Rules Bounded Context Ubiquitous Language Domain Model Types Rules

16 Anti-Corruption Layer Not Just for Connecting Apps
Anti-Corruption Layers Services Message Queues Adapters Mappers Bounded Context Ubiquitous Language Domain Model Types Rules Bounded Context Ubiquitous Language Domain Model Types Rules Bounded Context Ubiquitous Language Domain Model Types Rules Bounded Context Ubiquitous Language Domain Model Types Rules

17 Shared Kernel Inheritance When to Share Types
Tightly coordinated Entities and Value Objects Common schema and behavior “Reduce duplication, but not eliminate it” (Eric Evans, DDD book) Inheritance Infrastructure Not domain types Favor composition over inheritance

18 Domain Model and Persistence Model
Data Layer Bounded Context Bounded Context Anti- Corruption Layer e.g. Mapper DB Domain Model Domain Model Persistence Model ORM Aggregate Root Aggregate Root Entities Entities Value Objects Value Objects

19 Domain as Persistence Model
Bounded Context Anti-Corruption Layer DB Domain Model Entity Framework API, DbContext & Mappings Aggregate Root Entities Value Objects

20 Design with DDD, Today & Persist data with EF, Tomorrow
Yes You Can Design with DDD, Today & Persist data with EF, Tomorrow

21 Code Sample for this session is at github
Code Sample for this session is at github.com/julielerman/DomainDrivenDesignforDatabaseDrivenMind

22 Resources MY STUFF: Domain-Driven Design Fundamentals on Pluralsight bit.ly/PS-DDD All of my Pluralsight courses: pluralsight.com/author/julie-lerman A Pattern for Sharing Data Across DDD Bounded Contexts (Part 1&2) MSDN Magazine, Oct & Dec 2014: bit.ly/DataPoints_Dec2014 Entity Framework Model Partitioning in Domain-Driven Design Bounded Contexts TechEd Europe 2014: bit.ly/TEE2014_EFDDD Coding for Domain-Driven Design: Tips for Data-Focused Devs (3 Parts) MSDN Magazine, Aug, Sept & Oct 2013 bit.ly/15xMlDL BOOKS: Domain-Driven Design, Eric Evans amzn.to/1kstiRg Implementing Domain-Driven Design, Vaughn Vernon amzn.to/1dgYRY3 Domain Modeling with Entity Framework Scorecard, Jimmy Bogard, bit.ly/1x925bu CQRS Journey from MS Patterns & Practices: bit.ly/cqrsjourney

23 Julie Lerman Web: theDataFarm.com


Download ppt "Domain-Driven Design for the Database-Driven Mind"

Similar presentations


Ads by Google