Immutable Data Design in C# Records and State Modeling

Started by BeMyLove, Nov 19, 2026, 04:05 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

BeMyLove



Immutable Data Design in C# Records and State Modeling | 2.69 MB

Title: Immutable Data Design in C# Records and State Modeling
Author: Michael Tsai
Category: Data Modeling & Design, Object Oriented Programming, Information Technology
Language: English | 256 Pages | ISBN: 1990000109034


Description:
An object has passed through several methods and services. What changed its state along the way? Which values are unchanged, and which have been overwritten?   Immutable Data Design in C#   starts with these everyday development challenges. The book shows you how to leave existing data unchanged and explicitly create a new version when an update is needed. This reduces the effort involved in tracking state, debugging, and testing.

Using an order processing system as a running example, this book guides you through gradually refactoring mutable objects into immutable data models. You will use C# features such as record, init, required, with expressions, immutable collections, and pattern matching to structure data creation, validation, and transformation, then apply these techniques to API inputs and outputs, application configuration objects, and model mapping.

As the examples progress, you will also update deeply nested data, assess performance costs, and consider the constraints imposed by ORMs and serialization. You will learn how to introduce immutable design incrementally into existing projects and evaluate whether AI-suggested refactorings solve real problems. An advanced chapter explores how state-specific types and union types can make invalid states unrepresentable. The goal is to help you understand when immutable design is appropriate and how to weigh its benefits against its costs.

   What You Will Learn

  • Use records and immutable collections, and identify models that look read-only but remain mutable.
  • Express state changes through data transformations, making business rules easier to trace and test.
  • Design API DTOs and application configuration objects, handling validation, serialization, and model mapping.
  • Assess where immutable design fits, its performance costs, and strategies for incremental adoption.
  • Optional advanced reading: Use state-specific types and union types to make invalid states unrepresentable.     

   Who This Book Is For
This book is for developers with C# experience who want to improve their data models, API design, and approach to state management. No background in functional programming, advanced type theory, or domain-driven design (DDD) is required. 

   Table of Contents

  • From mutable objects to immutable data
  • C# records, init, and immutable collections
  • Replacing in-place mutation with data transformation
  • Data models for APIs, DTOs, and system boundaries
  • Trade-offs and adoption of immutable design
  • Ruling out invalid states with types (optional advanced reading)