O'Reilly logo

Domain Modeling Made Functional by Scott Wlaschin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to Translate Domain Types to DTOs

The domain types that we define can be quite complex, yet the corresponding DTO types must be simple structures containing only primitive types. How then do we design a DTO given a particular domain type? Let’s look at some guidelines.

Single-Case Unions

Single-case unions—what we are calling “simple types” in this book—can be represented by the underlying primitive in the DTO.

For example, if ProductCode is this domain type:

 type​ ProductCode = ProductCode ​of​ ​string

Then the corresponding DTO type is just string.

Options

For options, we can replace the None case with null. If the option wraps a reference type, we don’t need to do anything because null is a valid value. For value types like int, we’ll ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required