Details

Patterns, Principles, and Practices of Domain-Driven Design


Patterns, Principles, and Practices of Domain-Driven Design


1. Aufl.

von: Scott Millett, Nick Tune

39,99 €

Verlag: Wiley
Format: EPUB
Veröffentl.: 20.04.2015
ISBN/EAN: 9781118714690
Sprache: englisch
Anzahl Seiten: 800

DRM-geschütztes eBook, Sie benötigen z.B. Adobe Digital Editions und eine Adobe ID zum Lesen.

Beschreibungen

<p><b>Methods for managing complex software construction following the practices, principles and patterns of Domain-Driven Design with code examples in C# </b></p> <p>This book presents the philosophy of Domain-Driven Design (DDD) in a down-to-earth and practical manner for experienced developers building applications for complex domains. A focus is placed on the principles and practices of decomposing a complex problem space as well as the implementation patterns and best practices for shaping a maintainable solution space. You will learn how to build effective domain models through the use of tactical patterns and how to retain their integrity by applying the strategic patterns of DDD. Full end-to-end coding examples demonstrate techniques for integrating a decomposed and distributed solution space while coding best practices and patterns advise you on how to architect applications for maintenance and scale.</p> <ul> <li>Offers a thorough introduction to the philosophy of DDD for professional developers</li> <li>Includes masses of code and examples of concept in action that other books have only covered theoretically</li> <li>Covers the patterns of CQRS, Messaging, REST, Event Sourcing and Event-Driven Architectures</li> <li>Also ideal for Java developers who want to better understand the implementation of DDD</li> </ul>
<p>INTRODUCTION xxxv</p> <p><b>PART I: THE PRINCIPLES AND PRACTICES OF DOMAIN</b><b>‐DRIVEN DESIGN</b></p> <p><b>CHAPTER 1: WHAT IS DOMAIN</b><b>‐DRIVEN DESIGN? 3</b></p> <p>The Challenges of Creating Software for Complex Problem Domains 4</p> <p>Code Created Without a Common Language 4</p> <p>A Lack of Organization 5</p> <p>The Ball of Mud Pattern Stifles Development 5</p> <p>A Lack of Focus on the Problem Domain 6</p> <p>How the Patterns of Domain‐Driven Design Manage Complexity 6</p> <p>The Strategic Patterns of DDD 6</p> <p>Distilling the Problem Domain to Reveal What Is Important 7</p> <p>Creating a Model to Solve Domain Problems 7</p> <p>Using a Shared Language to Enable Modeling Collaboration 7</p> <p>Isolate Models from Ambiguity and Corruption 8</p> <p>Understanding the Relationships between Contexts 9</p> <p>The Tactical Patterns of DDD 9</p> <p>The Problem Space and the Solution Space 9</p> <p>The Practices and Principles of Domain‐Driven Design 11</p> <p>Focusing on the Core Domain 11</p> <p>Learning through Collaboration 11</p> <p>Creating Models through Exploration and Experimentation 11</p> <p>Communication 11</p> <p>Understanding the Applicability of a Model 12</p> <p>Constantly Evolving the Model 12</p> <p>Popular Misconceptions of Domain‐Driven Design 12</p> <p>Tactical Patterns Are Key to DDD 12</p> <p>DDD Is a Framework 13</p> <p>DDD Is a Silver Bullet 13</p> <p>The Salient Points 13</p> <p><b>CHAPTER 2: DISTILLING THE PROBLEM DOMAIN 15</b></p> <p>Knowledge Crunching and Collaboration 15</p> <p>Reaching a Shared Understanding through a Shared Language 16</p> <p>The Importance of Domain Knowledge 17</p> <p>The Role of Business Analysts 17</p> <p>An Ongoing Process 17</p> <p>Gaining Domain Insight with Domain Experts 18</p> <p>Domain Experts vs Stakeholders 18</p> <p>Deeper Understanding for the Business 19</p> <p>Engaging with Your Domain Experts 19</p> <p>Patterns for Effective Knowledge Crunching 19</p> <p>Focus on the Most Interesting Conversations 19</p> <p>Start from the Use Cases 20</p> <p>Ask Powerful Questions 20</p> <p>Sketching 20</p> <p>Class Responsibility Collaboration Cards 21</p> <p>Defer the Naming of Concepts in Your Model 21</p> <p>Behavior‐Driven Development 22</p> <p>Rapid Prototyping 23</p> <p>Look at Paper‐Based Systems 24</p> <p>Look For Existing Models 24</p> <p>Understanding Intent 24</p> <p>Event Storming 25</p> <p>Impact Mapping 25</p> <p>Understanding the Business Model 27</p> <p>Deliberate Discovery 28</p> <p>Model Exploration Whirlpool 29</p> <p>The Salient Points 29</p> <p><b>CHAPTER 3: FOCUSING ON THE CORE DOMAIN 31</b></p> <p>Why Decompose a Problem Domain? 31</p> <p>How to Capture the Essence of the Problem 32</p> <p>Look Beyond Requirements 32</p> <p>Capture the Domain Vision for a Shared Understanding of What Is Core 32</p> <p>How to Focus on the Core Problem 33</p> <p>Distilling a Problem Domain 34</p> <p>Core Domains 35</p> <p>Treat Your Core Domain as a Product Rather than a Project 36</p> <p>Generic Domains 37</p> <p>Supporting Domains 37</p> <p>How Subdomains Shape a Solution 37</p> <p>Not All Parts of a System will be Well Designed 37</p> <p>Focus on Clean Boundaries over Perfect Models 38</p> <p>The Core Domain Doesn’t Always Have to Be Perfect the First Time 39</p> <p>Build Subdomains for Replacement Rather than Reuse 39</p> <p>What if You Have no Core Domain? 39</p> <p>The Salient Points 40</p> <p><b>CHAPTER 4: MODEL</b><b>‐DRIVEN DESIGN 41</b></p> <p>What Is a Domain Model? 42</p> <p>The Domain versus the Domain Model 42</p> <p>The Analysis Model 43</p> <p>The Code Model 43</p> <p>The Code Model Is the Primary Expression of the Domain Model 44</p> <p>Model‐Driven Design 44</p> <p>The Challenges with Upfront Design 44</p> <p>Team Modeling 45</p> <p>Using a Ubiquitous Language to Bind the Analysis to the Code Model 47</p> <p>A Language Will Outlive Your Software 47</p> <p>The Language of the Business 48</p> <p>Translation between the Developers and the Business 48</p> <p>Collaborating on a Ubiquitous Language 48</p> <p>Carving Out a Language by Working with Concrete Examples 49</p> <p>Teach Your Domain Experts to Focus on the Problem and Not Jump to a Solution 50</p> <p>Best Practices for Shaping the Language 51</p> <p>How to Create Effective Domain Models 52</p> <p>Don’t Let the Truth Get in the Way of a Good Model 52</p> <p>Model Only What Is Relevant 54</p> <p>Domain Models Are Temporarily Useful 54</p> <p>Be Explicit with Terminology 54</p> <p>Limit Your Abstractions 54</p> <p>Focus Your Code at the Right Level of Abstraction 55</p> <p>Abstract Behavior Not Implementations 55</p> <p>Implement the Model in Code Early and Often 56</p> <p>Don’t Stop at the First Good Idea 56</p> <p>When to Apply Model‐Driven Design 56</p> <p>If It’s Not Worth the Effort Don’t Try and Model It 56</p> <p>Focus on the Core Domain 57</p> <p>The Salient Points 57</p> <p><b>CHAPTER 5: DOMAIN MODEL IMPLEMENTATION PATTERNS 59</b></p> <p>The Domain Layer 60</p> <p>Domain Model Implementation Patterns 60</p> <p>Domain Model 62</p> <p>Transaction Script 65</p> <p>Table Module 67</p> <p>Active Record 67</p> <p>Anemic Domain Model 67</p> <p>Anemic Domain Model and Functional Programming 68</p> <p>The Salient Points 71</p> <p><b>CHAPTER 6: MAINTAINING THE INTEGRITY OF DOMAIN MODELS WITH BOUNDED CONTEXTS 73</b></p> <p>The Challenges of a Single Model 74</p> <p>A Model Can Grow in Complexity 74</p> <p>Multiple Teams Working on a Single Model 74</p> <p>Ambiguity in the Language of the Model 75</p> <p>The Applicability of a Domain Concept 76</p> <p>Integration with Legacy Code or Third Party Code 78</p> <p>Your Domain Model Is not Your Enterprise Model 79</p> <p>Use Bounded Contexts to Divide and Conquer a Large Model 79</p> <p>Defining a Model’s Boundary 82</p> <p>Define Boundaries around Language 82</p> <p>Align to Business Capabilities 83</p> <p>Create Contexts around Teams 83</p> <p>Try to Retain Some Communication between Teams 84</p> <p>Context Game 85</p> <p>The Difference between a Subdomain and a Bounded Context 85</p> <p>Implementing Bounded Contexts 85</p> <p>The Salient Points 89</p> <p><b>CHAPTER 7: CONTEXT MAPPING 91</b></p> <p>A Reality Map 92</p> <p>The Technical Reality 92</p> <p>The Organizational Reality 93</p> <p>Mapping a Relevant Reality 94</p> <p>X Marks the Spot of the Core Domain 94</p> <p>Recognising the Relationships between Bounded Contexts 95</p> <p>Anticorruption Layer 95</p> <p>Shared Kernel 96</p> <p>Open Host Service 97</p> <p>Separate Ways 97</p> <p>Partnership 98</p> <p>An Upstream/Downstream Relationship 98</p> <p>Customer‐Supplier 99</p> <p>Conformist 100</p> <p>Communicating the Context Map 100</p> <p>The Strategic Importance of Context Maps 101</p> <p>Retaining Integrity 101</p> <p>The Basis for a Plan of Attack 101</p> <p>Understanding Ownership and Responsibility 101</p> <p>Revealing Areas of Confusion in Business Work Flow 102</p> <p>Identifying Nontechnical Obstacles 102</p> <p>Encourages Good Communication 102</p> <p>Helps On‐Board New Starters 102</p> <p>The Salient Points 103</p> <p><b>CHAPTER 8: APPLICATION ARCHITECTURE 105</b></p> <p>Application Architecture 105</p> <p>Separating the Concerns of Your Application 106</p> <p>Abstraction from the Complexities of the Domain 106</p> <p>A Layered Architecture 106</p> <p>Dependency Inversion 107</p> <p>The Domain Layer 107</p> <p>The Application Service Layer 108</p> <p>The Infrastructural Layers 108</p> <p>Communication Across Layers 108</p> <p>Testing in Isolation 109</p> <p>Don t Share Data Schema between Bounded Contexts 109</p> <p>Application Architectures versus Architectures for Bounded Contexts 111</p> <p>Application Services 112</p> <p>Application Logic versus Domain Logic 114</p> <p>Defining and Exposing Capabilities 114</p> <p>Business Use Case Coordination 115</p> <p>Application Services Represent Use Cases, Not Create, Read, Update, and Delete 115</p> <p>Domain Layer As an Implementation Detail 115</p> <p>Domain Reporting 116</p> <p>Read Models versus Transactional Models 116</p> <p>Application Clients 117</p> <p>The Salient Points 120</p> <p><b>CHAPTER 9: COMMON PROBLEMS FOR TEAMS STARTING OUT WITH DOMAIN</b><b>‐DRIVEN DESIGN 121</b></p> <p>Overemphasizing the Importance of Tactical Patterns 122</p> <p>Using the Same Architecture for All Bounded Contexts 122</p> <p>Striving for Tactical Pattern Perfection 122</p> <p>Mistaking the Building Blocks for the Value of DDD 123</p> <p>Focusing on Code Rather Than the Principles of DDD 123</p> <p>Missing the Real Value of DDD: Collaboration, Communication, and Context 124</p> <p>Producing a Big Ball of Mud Due to Underestimating the Importance of Context 124</p> <p>Causing Ambiguity and Misinterpretations by Failing to Create a UL 125</p> <p>Designing Technical‐Focused Solutions Due to a Lack of Collaboration 125</p> <p>Spending Too Much Time on What’s Not Important 126</p> <p>Making Simple Problems Complex 126</p> <p>Applying DDD Principles to a Trivial Domain with Little Business Expectation 126</p> <p>Disregarding CRUD as an Antipattern 127</p> <p>Using the Domain Model Pattern for Every Bounded Context 127</p> <p>Ask Yourself: Is It Worth This Extra Complexity? 127</p> <p>Underestimating the Cost of Applying DDD 127</p> <p>Trying to Succeed Without a Motivated and Focused Team 128</p> <p>Attempting Collaboration When a Domain Expert Is Not Behind the Project 128</p> <p>Learning in a Noniterative Development Methodology 128</p> <p>Applying DDD to Every Problem 129</p> <p>Sacrificing Pragmatism for Needless Purity 129</p> <p>Wasted Effort by Seeking Validation 129</p> <p>Always Striving for Beautiful Code 130</p> <p>DDD Is About Providing Value 130</p> <p>The Salient Points 130</p> <p><b>CHAPTER 10: APPLYING THE PRINCIPLES, PRACTICES, AND PATTERNS OF DDD 131</b></p> <p>Selling DDD 132</p> <p>Educating Your Team 132</p> <p>Speaking to Your Business 132</p> <p>Applying the Principles of DDD 133</p> <p>Understand the Vision 133</p> <p>Capture the Required Behaviors 134</p> <p>Distilling the Problem Space 134</p> <p>Focus on What Is Important 134</p> <p>Understand the Reality of the Landscape 135</p> <p>Modeling a Solution 135</p> <p>All Problems Are Not Created Equal 136</p> <p>Engaging with an Expert 136</p> <p>Select a Behavior and Model Around a Concrete Scenario 137</p> <p>Collaborate with the Domain Expert on the Most Interesting Parts 137</p> <p>Evolve UL to Remove Ambiguity 138</p> <p>Throw Away Your First Model, and Your Second 138</p> <p>Implement the Model in Code 139</p> <p>Creating a Domain Model 139</p> <p>Keep the Solution Simple and Your Code Boring 139</p> <p>Carve Out an Area of Safety 140</p> <p>Integrate the Model Early and Often 140</p> <p>Nontechnical Refactoring 140</p> <p>Decompose Your Solution Space 140</p> <p>Rinse and Repeat 141</p> <p>Exploration and Experimentation 142</p> <p>Challenge Your Assumptions 142</p> <p>Modeling Is a Continuous Activity 142</p> <p>There Are No Wrong Models 142</p> <p>Supple Code Aids Discovery 143</p> <p>Making the Implicit Explicit 143</p> <p>Tackling Ambiguity 144</p> <p>Give Things a Name 145</p> <p>A Problem Solver First, A Technologist Second 146</p> <p>Don’t Solve All the Problems 146</p> <p>How Do I Know That I Am Doing It Right? 146</p> <p>Good Is Good Enough 147</p> <p>Practice, Practice, Practice 147</p> <p>The Salient Points 147</p> <p><b>PART II: STRATEGIC PATTERNS: COMMUNICATING BETWEEN BOUNDED CONTEXTS</b></p> <p><b>CHAPTER 11: INTRODUCTION TO BOUNDED CONTEXT INTEGRATION 151</b></p> <p>How to Integrate Bounded Contexts 152</p> <p>Bounded Contexts Are Autonomous 153</p> <p>The Challenges of Integrating Bounded Contexts at the Code Level 153</p> <p>Multiple Bounded Contexts Exist within a Solution 153</p> <p>Namespaces or Projects to Keep Bounded Contexts Separate 154</p> <p>Integrating via the Database 155</p> <p>Multiple Teams Working in a Single Codebase 156</p> <p>Models Blur 156</p> <p>Use Physical Boundaries to Enforce Clean Models 157</p> <p>Integrating with Legacy Systems 158</p> <p>Bubble Context 158</p> <p>Autonomous Bubble Context 158</p> <p>Exposing Legacy Systems as Services 160</p> <p>Integrating Distributed Bounded Contexts 161</p> <p>Integration Strategies for Distributed Bounded Contexts 161</p> <p>Database Integration 162</p> <p>Flat File Integration 163</p> <p>RPC 164</p> <p>Messaging 165</p> <p>REST 165</p> <p>The Challenges of DDD with Distributed Systems 165</p> <p>The Problem with RPC 166</p> <p>RPC Is Harder to Make Resilient 167</p> <p>RPC Costs More to Scale 167</p> <p>RPC Involves Tight Coupling 168</p> <p>Distributed Transactions Hurt Scalability and Reliability 169</p> <p>Bounded Contexts Don’t Have to Be Consistent with Each Other 169</p> <p>Eventual Consistency 169</p> <p>Event‐Driven Reactive DDD 170</p> <p>Demonstrating the Resilience and Scalability of Reactive Solutions 171</p> <p>Challenges and Trade‐Offs of Asynchronous Messaging 173</p> <p>Is RPC Still Relevant? 173</p> <p>SOA and Reactive DDD 174</p> <p>View Your Bounded Contexts as SOA Services 175</p> <p>Decompose Bounded Contexts into Business Components 175</p> <p>Decompose Business Components into Components 176</p> <p>Going Even Further with Micro Service Architecture 178</p> <p>The Salient Points 180</p> <p><b>CHAPTER 12: INTEGRATING VIA MESSAGING 181</b></p> <p>Messaging Fundamentals 182</p> <p>Message Bus 182</p> <p>Reliable Messaging 184</p> <p>Store‐and‐Forward 184</p> <p>Commands and Events 185</p> <p>Eventual Consistency 186</p> <p>Building an E‐Commerce Application with NServiceBus 186</p> <p>Designing the System 187</p> <p>Domain‐Driven Design 187</p> <p>Containers Diagrams 188</p> <p>Evolutionary Architecture 191</p> <p>Sending Commands from a Web Application 192</p> <p>Creating a Web Application to Send Messages with NServiceBus 192</p> <p>Sending Commands 197</p> <p>Handling Commands and Publishing Events 200</p> <p>Creating an NServiceBus Server to Handle Commands 200</p> <p>Configuring the Solution for Testing and Debugging 201</p> <p>Publishing Events 204</p> <p>Subscribing to Events 206</p> <p>Making External HTTP Calls Reliable with Messaging Gateways 208</p> <p>Messaging Gateways Improve Fault Tolerance 208</p> <p>Implementing a Messaging Gateway 209</p> <p>Controlling Message Retries 212</p> <p>Eventual Consistency in Practice 215</p> <p>Dealing with Inconsistency 215</p> <p>Rolling Forward into New States 215</p> <p>Bounded Contexts Store All the Data They Need Locally 216</p> <p>Storage Is Cheap—Keep a Local Copy 217</p> <p>Common Data Duplication Concerns 223</p> <p>Pulling It All Together in the UI 224</p> <p>Business Components Need Their Own APIs 225</p> <p>Be Wary of Server‐Side Orchestration 226</p> <p>UI Composition with AJAX Data 226</p> <p>UI Composition with AJAX HTML 226</p> <p>Sharing Your APIs with the Outside World 227</p> <p>Maintaining a Messaging Application 227</p> <p>Message Versioning 228</p> <p>Backward‐Compatible Message Versioning 228</p> <p>Handling Versioning with NServiceBus’s Polymorphic Handlers 229</p> <p>Monitoring and Scaling 233</p> <p>Monitoring Errors 233</p> <p>Monitoring SLAs 234</p> <p>Scaling Out 235</p> <p>Integrating a Bounded Context with Mass Transit 235</p> <p>Messaging Bridge 236</p> <p>Mass Transit 236</p> <p>Installing and Configuring Mass Transit 236</p> <p>Declaring Messages for Use by Mass Transit 238</p> <p>Creating a Message Handler 239</p> <p>Subscribing to Events 239</p> <p>Linking the Systems with a Messaging Bridge 240</p> <p>Publishing Events 242</p> <p>Testing It Out 243</p> <p>Where to Learn More about Mass Transit 243</p> <p>The Salient Points 243</p> <p><b>CHAPTER 13: INTEGRATING VIA HTTP WITH RPC AND REST 245</b></p> <p>Why Prefer HTTP? 247</p> <p>No Platform Coupling 247</p> <p>Everyone Understands HTTP 247</p> <p>Lots of Mature Tooling and Libraries 247</p> <p>Dogfooding Your APIs 247</p> <p>RPC 248</p> <p>Implementing RPC over HTTP 248</p> <p>SOAP 249</p> <p>Plain XML or JSON: The Modern Approach to RPC 259</p> <p>Choosing a Flavor of RPC 263</p> <p>REST 264</p> <p>Demystifying REST 264</p> <p>Resources 264</p> <p>Hypermedia 265</p> <p>Statelessness 265</p> <p>REST Fully Embraces HTTP 266</p> <p>What REST Is Not 267</p> <p>REST for Bounded Context Integration 268</p> <p>Designing for REST 268</p> <p>Building Event‐Driven REST Systems with ASP.NET Web API 273</p> <p>Maintaining REST Applications 303</p> <p>Versioning 303</p> <p>Monitoring and Metrics 303</p> <p>Drawbacks with REST for Bounded Context Integration 304</p> <p>Less Fault Tolerance Out of the Box 304</p> <p>Eventual Consistency 304</p> <p>The Salient Points 305</p> <p><b>PART III: TACTICAL PATTERNS: CREATING EFFECTIVE DOMAIN MODELS</b></p> <p><b>CHAPTER 14: INTRODUCING THE DOMAIN MODELING BUILDING BLOCKS 309</b></p> <p>Tactical Patterns 310</p> <p>Patterns to Model Your Domain 310</p> <p>Entities 310</p> <p>Value Objects 314</p> <p>Domain Services 317</p> <p>Modules 318</p> <p>Lifecycle Patterns 318</p> <p>Aggregates 318</p> <p>Factories 322</p> <p>Repositories 323</p> <p>Emerging Patterns 324</p> <p>Domain Events 324</p> <p>Event Sourcing 326</p> <p>The Salient Points 327</p> <p><b>CHAPTER 15: VALUE OBJECTS 329</b></p> <p>When to Use a Value Object 330</p> <p>Representing a Descriptive, Identity‐Less Concept 330</p> <p>Enhancing Explicitness 331</p> <p>Defining Characteristics 333</p> <p>Identity‐Less 333</p> <p>Attribute‐Based Equality 333</p> <p>Behavior‐Rich 337</p> <p>Cohesive 337</p> <p>Immutable 337</p> <p>Combinable 339</p> <p>Self‐Validating 341</p> <p>Testable 344</p> <p>Common Modeling Patterns 345</p> <p>Static Factory Methods 345</p> <p>Micro Types (Also Known as Tiny Types) 347</p> <p>Collection Aversion 349</p> <p>Persistence 35</p> <p>NoSQL 352</p> <p>SQL 353</p> <p>Flat Denormalization 353</p> <p>Normalizing into Separate Tables 357</p> <p>The Salient Points 359</p> <p><b>CHAPTER 16: ENTITIES 36</b></p> <p>Understanding Entities 362</p> <p>Domain Concepts with Identity and Continuity 362</p> <p>Context‐Dependent 363</p> <p>Implementing Entities 363</p> <p>Assigning Identifiers 363</p> <p>Natural Keys 363</p> <p>Arbitrarily Generated IDs 364</p> <p>Datastore‐Generated IDs 368</p> <p>Pushing Behavior into Value Objects and Domain Services 369</p> <p>Validating and Enforcing Invariants 371</p> <p>Focusing on Behavior, Not Data 374</p> <p>Avoiding the “Model the Real‐World” Fallacy 377</p> <p>Designing for Distribution 378</p> <p>Common Entity Modeling Principles and Patterns 380</p> <p>Implementing Validation and Invariants with Specifications 380</p> <p>Avoid the State Pattern; Use Explicit Modeling 382</p> <p>Avoiding Getters and Setters with the Memento Pattern 385</p> <p>Favor Hidden‐Side‐Effect‐Free Functions 386</p> <p>The Salient Points 388</p> <p><b>CHAPTER 17: DOMAIN SERVICES 389</b></p> <p>Understanding Domain Services 390</p> <p>When to Use a Domain Service 390</p> <p>Encapsulating Business Policies and Processes 390</p> <p>Representing Contracts 394</p> <p>Anatomy of a Domain Service 395</p> <p>Avoiding Anemic Domain Models 395</p> <p>Contrasting with Application Services 396</p> <p>Utilizing Domain Services 397</p> <p>In the Service Layer 397</p> <p>In the Domain 398</p> <p>Manually Wiring Up 399</p> <p>Using Dependency Injection 400</p> <p>Using a Service Locator 400</p> <p>Applying Double Dispatch 401</p> <p>Decoupling with Domain Events 402</p> <p>Should Entities Even Know About Domain Services? 403</p> <p>The Salient Points 403</p> <p><b>CHAPTER 18: DOMAIN EVENTS 405</b></p> <p>Essence of the Domain Events Pattern 406</p> <p>Important Domain Occurrences That Have Already Happened 406</p> <p>Reacting to Events 407</p> <p>Optional Asynchrony 407</p> <p>Internal vs External Events 408</p> <p>Event Handling Actions 409</p> <p>Invoke Domain Logic 409</p> <p>Invoke Application Logic 410</p> <p>Domain Events’ Implementation Patterns 410</p> <p>Use the .Net Framework’s Events Model 410</p> <p>Use an In‐Memory Bus 412</p> <p>Udi Dahan’s Static DomainEvents Class 415</p> <p>Handling Threading Issues 417</p> <p>Avoid a Static Class by Using Method Injection 418</p> <p>Return Domain Events 419</p> <p>Use an IoC Container as an Event Dispatcher 421</p> <p>Testing Domain Events 422</p> <p>Unit Testing 422</p> <p>Application Service Layer Testing 424</p> <p>The Salient Points 425</p> <p><b>CHAPTER 19: AGGREGATES 427</b></p> <p>Managing Complex Object Graphs 428</p> <p>Favoring a Single Traversal Direction 428</p> <p>Qualifying Associations 430</p> <p>Preferring IDs Over Object References 431</p> <p>Aggregates 434</p> <p>Design Around Domain Invariants 435</p> <p>Higher Level of Domain Abstraction 435</p> <p>Consistency Boundaries 435</p> <p>Transactional Consistency Internally 436</p> <p>Eventual Consistency Externally 439</p> <p>Special Cases 440</p> <p>Favor Smaller Aggregates 441</p> <p>Large Aggregates Can Degrade Performance 441</p> <p>Large Aggregates Are More Susceptible to Concurrency Conflicts 442</p> <p>Large Aggregates May Not Scale Well 442</p> <p>Defining Aggregate Boundaries 442</p> <p>eBidder: The Online Auction Case Study 443</p> <p>Aligning with Invariants 444</p> <p>Aligning with Transactions and Consistency 446</p> <p>Ignoring User Interface Influences 448</p> <p>Avoiding Dumb Collections and Containers 448</p> <p>Don’t Focus on HAS‐A Relationships 449</p> <p>Refactoring to Aggregates 449</p> <p>Satisfying Business Use Cases—Not Real Life 449</p> <p>Implementing Aggregates 450</p> <p>Selecting an Aggregate Root 450</p> <p>Exposing Behavioral Interfaces 452</p> <p>Protecting Internal State 453</p> <p>Allowing Only Roots to Have Global Identity 454</p> <p>Referencing Other Aggregates 454</p> <p>Nothing Outside An Aggregate’s Boundary May Hold a Reference to Anything Inside 455</p> <p>The Aggregate Root Can Hand Out Transient References to the Internal Domain Objects 456</p> <p>Objects within the Aggregate Can Hold References to Other Aggregate Roots 456</p> <p>Implementing Persistence 458</p> <p>Access to Domain Objects for Reading Can Be at the Database Level 460</p> <p>A Delete Operation Must Remove Everything within the Aggregate Boundary at Once 461</p> <p>Avoiding Lazy Loading 461</p> <p>Implementing Transactional Consistency 462</p> <p>Implementing Eventual Consistency 463</p> <p>Rules That Span Multiple Aggregates 463</p> <p>Asynchronous Eventual Consistency 464</p> <p>Implementing Concurrency 465</p> <p>The Salient Points 468</p> <p><b>CHAPTER 20: FACTORIES 469</b></p> <p>The Role of a Factory 469</p> <p>Separating Use from Construction 470</p> <p>Encapsulating Internals 470</p> <p>Hiding Decisions on Creation Type 472</p> <p>Factory Methods on Aggregates 474</p> <p>Factories for Reconstitution 475</p> <p>Use Factories Pragmatically 477</p> <p>The Salient Points 477</p> <p><b>CHAPTER 21: REPOSITORIES 479</b></p> <p>Repositories 479</p> <p>A Misunderstood Pattern 481</p> <p>Is the Repository an Antipattern? 481</p> <p>The Difference between a Domain Model and a Persistence Model 482</p> <p>The Generic Repository 483</p> <p>Aggregate Persistence Strategies 486</p> <p>Using a Persistence Framework That Can Map the Domain Model to the Data Model without Compromise 486</p> <p>Using a Persistence Framework That Cannot Map the Domain Model Directly without Compromise 487</p> <p>Public Getters and Setters 487</p> <p>Using the Memento Pattern 488</p> <p>Event Streams 49</p> <p>Be Pragmatic 491</p> <p>A Repository Is an Explicit Contract 492</p> <p>Transaction Management and Units of Work 493</p> <p>To Save or Not To Save 497</p> <p>Persistence Frameworks That Track Domain Object Changes 497</p> <p>Having to Explicitly Save Changes to Aggregates 498</p> <p>The Repository as an Anticorruption Layer 499</p> <p>Other Responsibilities of a Repository 500</p> <p>Entity ID Generation 500</p> <p>Collection Summaries 502</p> <p>Concurrency 503</p> <p>Audit Trails 506</p> <p>Repository Antipatterns 506</p> <p>Antipatterns: Don’t Support Ad Hoc Queries 506</p> <p>Antipatterns: Lazy Loading Is Design Smell 507</p> <p>Antipatterns: Don’t Use Repositories for Reporting Needs 507</p> <p>Repository Implementations 508</p> <p>Persistence Framework Can Map Domain Model to Data Model without Compromise 509</p> <p>NHibernate Example 509</p> <p>RavenDB Example 543</p> <p>Persistence Framework Cannot Map Domain Model Directly without Compromise 557</p> <p>Entity Framework Example 558</p> <p>Micro ORM Example 577</p> <p>The Salient Points 593</p> <p><b>CHAPTER 22: EVENT SOURCING 595</b></p> <p>The Limitations of Storing State as a Snapshot 596</p> <p>Gaining Competitive Advantage by Storing State as a Stream of Events 597</p> <p>Temporal Queries 597</p> <p>Projections 599</p> <p>Snapshots 599</p> <p>Event‐Sourced Aggregates 600</p> <p>Structuring 600</p> <p>Adding Event‐Sourcing Capabilities 601</p> <p>Exposing Expressive Domain‐Focused APIs 602</p> <p>Adding Snapshot Support 604</p> <p>Persisting and Rehydrating 605</p> <p>Creating an Event-Sourcing Repository 605</p> <p>Adding Snapshot Persistence and Reloading 607</p> <p>Handling Concurrency 609</p> <p>Testing 610</p> <p>Building an Event Store 611</p> <p>Designing a Storage Format 612</p> <p>Creating Event Streams 614</p> <p>Appending to Event Streams 614</p> <p>Querying Event Streams 615</p> <p>Adding Snapshot Support 616</p> <p>Managing Concurrency 618</p> <p>A SQL Server‐Based Event Store 621</p> <p>Choosing a Schema 621</p> <p>Creating a Stream 622</p> <p>Saving Events 623</p> <p>Loading Events from a Stream 624</p> <p>Snapshots 625</p> <p>Is Building Your Own Event Store a Good Idea? 627</p> <p>Using the Purpose‐Built Event Store 627</p> <p>Installing Greg Young’s Event Store 628</p> <p>Using the C# Client Library 627</p> <p>Running Temporal Queries 632</p> <p>Querying a Single Stream 632</p> <p>Querying Multiple Streams 634</p> <p>Creating Projections 635</p> <p>CQRS with Event Sourcing 637</p> <p>Using Projections to Create View Caches 638</p> <p>CQRS and Event Sourcing Synergy 638</p> <p>Event Streams as Queues 639</p> <p>No Two‐Phase Commits 639</p> <p>Recapping the Benefits of Event Sourcing 639</p> <p>Competitive Business Advantage 639</p> <p>Expressive Behavior‐Focused Aggregates 639</p> <p>Simplified Persistence 640</p> <p>Superior Debugging 640</p> <p>Weighing the Costs of Event Sourcing 640</p> <p>Versioning 640</p> <p>New Concepts to Learn and Skills to Hone 640</p> <p>New Technologies to Learn and Master 641</p> <p>Greater Data Storage Requirements 641</p> <p>Additional Learning Resources 641</p> <p>The Salient Points 641</p> <p><b>PART IV: DESIGN PATTERNS FOR EFFECTIVE APPLICATIONS</b></p> <p><b>CHAPTER 23: ARCHITECTING APPLICATION USER INTERFACES 645</b></p> <p>Design Considerations 646</p> <p>Owned UIs versus Composed UIs 646</p> <p>Autonomous 646</p> <p>Authoritative 647</p> <p>Some Help Deciding 648</p> <p>HTML APIs versus Data APIs 649</p> <p>Client versus Server‐Side Aggregation/Coordination 649</p> <p>Example 1: An HTML API‐Based, Server‐Side UI for Nondistributed Bounded Contexts 651</p> <p>Example 2: A Data API‐Based, Client‐Side UI for Distributed Bounded Contexts 658</p> <p>The Salient Points 667</p> <p><b>CHAPTER 24: CQRS: AN ARCHITECTURE OF A BOUNDED CONTEXT 669</b></p> <p>The Challenges of Maintaining a Single Model for Two Contexts 670</p> <p>A Better Architecture for Complex Bounded Contexts 670</p> <p>The Command Side: Business Tasks 672</p> <p>Explicitly Modeling Intent 672</p> <p>A Model Free from Presentational Distractions 674</p> <p>Handling a Business Request 675</p> <p>The Query Side: Domain Reporting 676</p> <p>Reports Mapped Directly to the Data Model 676</p> <p>Materialized Views Built from Domain Events 678</p> <p>The Misconceptions of CQRS 679</p> <p>CQRS Is Hard 679</p> <p>CQRS Is Eventually Consistent 679</p> <p>Your Models Need to Be Event Sourced 680</p> <p>Commands Should Be Asynchronous 680</p> <p>CQRS Only Works with Messaging Systems 680</p> <p>You Need to Use Domain Events with CQRS 680</p> <p>Patterns to Enable Your Application to Scale 680</p> <p>Scaling the Read Side: An Eventually Consistent Read Model 681</p> <p>The Impact to the User Experience 682</p> <p>Use the Read Model to Consolidate Many Bounded Contexts 682</p> <p>Using a Reporting Database or a Caching Layer 682</p> <p>Scaling the Write Side: Using Asynchronous Commands 683</p> <p>Command Validation 683</p> <p>Impact to the User Experience 684</p> <p>Scaling It All 684</p> <p>The Salient Points 685</p> <p><b>CHAPTER 25: COMMANDS: APPLICATION SERVICE PATTERNS FOR PROCESSING BUSINESS USE CASES 687</b></p> <p>Differentiating Application Logic and Domain Logic 689</p> <p>Application Logic 689</p> <p>Infrastructural Concerns 690</p> <p>Coordinating Full Business Use Cases 698</p> <p>Application Services and Framework Integration 698</p> <p>Domain Logic from an Application Service’s Perspective 700</p> <p>Application Service Patterns 700</p> <p>Command Processor 701</p> <p>Publish/Subscribe 704</p> <p>Request/Reply Pattern 706</p> <p>async/await 708</p> <p>Testing Application Services 709</p> <p>Use Domain Terminology 709</p> <p>Test as Much Functionality as Possible 710</p> <p>The Salient Points 712</p> <p><b>CHAPTER 26: QUERIES: DOMAIN REPORTING 713</b></p> <p>Domain Reporting within a Bounded Context 714</p> <p>Deriving Reports from Domain Objects 714</p> <p>Using Simple Mappings 714</p> <p>Using the Mediator Pattern 718</p> <p>Going Directly to the Datastore 720</p> <p>Querying a Datastore 721</p> <p>Reading Denormalized View Caches 724</p> <p>Building Projections from Event Streams 726</p> <p>Setting Up ES for Projections 727</p> <p>Creating Reporting Projections 728</p> <p>Counting the Number of Events in a Stream 729</p> <p>Creating As Many Streams As Required 729</p> <p>Building a Report from Streams and Projections 730</p> <p>Domain Reporting Across Bounded Contexts 733</p> <p>Composed UI 733</p> <p>Separate Reporting Context 734</p> <p>The Salient Points 736</p> <p>INDEX 737</p>
<p><b>Scott Millett</b> is the Director of IT for Iglu.com, and has been working with .NET since version 1.0. He was awarded the ASP.NET MVP in 2010 and 2011, and is the author of <i>Professional ASP.NET Design Patterns and Professional Enterprise .NET.</i> <p><b>Nick Tune</b> is a software developer delivering solutions to complex business problems using technology, collaboration, and Domain-Driven Design. He continually seeks improvement by working on ambitious products and with enthusiastic people.
<p><b>Build solutions for complex business problems more effectively with Domain-Driven Design</b> <p>This book distills the ideas and theories of the Domain-Driven Design (DDD) philosophy into a practical playbook that you can leverage to simplify application development for complex problem domains. A focus is placed on the principles and practices of decomposing a complex problem space as well as the implementation patterns and best practices for shaping a maintainable solution space. You will learn how to build effective domain models through the use of tactical patterns and how to retain their integrity by applying the strategic patterns of DDD. Full end-to-end coding examples demonstrate techniques for integrating a decomposed and distributed solution space while coding best practices and patterns advise you on how to architect applications for maintenance and scale. <ul> <li>Offers a thorough introduction to the philosophy of DDD for professional developers</li> <li>Simplifies the theories of Domain-Driven Design into practical principles and practices</li> <li>Includes masses of code and examples of concepts in action that other books have only covered theoretically</li> <li>Covers the patterns of CQRS, Messaging, REST, Event Sourcing and Event-Driven Architectures</li> <li>Ideal for developers using Java, Ruby, and other languages who want to learn common DDD implementation patterns</li> <li>Code examples presented in C# demonstrating concepts that can be applied in any language</li> </ul> <p><b>Wrox Professional guides</b> are planned and written by working programmers to meet the real-world needs of programmers, developers, and IT professionals.Focused and relevant, they address the issues technology professionals face every day. They provide examples, practical solutions, and expert education in new technologies, all designed to help programmers do a better job.

Diese Produkte könnten Sie auch interessieren:

Domain Architectures
Domain Architectures
von: Daniel J. Duffy
PDF ebook
31,99 €