liveBook · Manning

Data transfer object

As explained in .NET MAUI in Action

A data transfer object is a data structure that carries serialized data between application or service boundaries without encapsulating business behavior.

A data transfer object (DTO) is a data structure that carries data between application boundaries without containing business behavior. In MVVM, this distinguishes a DTO from a ViewModel, which includes view state and functionality. section 9.3.3

Place DTOs in a shared project when the frontend and backend use the same data shapes. This reduces duplication and makes structural changes visible across the solution. section 8.4.2

Use DTOs to represent problem-area data alongside services:

  • Represent products with ProductDto and process them through ProductService. section 9.5.1
  • Represent inventory with StockCountDto and InventoryItemDto and process it through InventoryService. section 9.5.1
  • Return a view-oriented DTO containing the data needed to render a screen in one API call. section 9.3.3
Figure 8.6 MauiStockTake is a full-stack solution written in C#. Therefore, there is no need to duplicate code as it can be shared across the stack. Code shared across the stack in this way is referred to as cross-cutting concerns.

Use the architecture diagram to see how shared DTO code crosses the application, Web API, and .NET MAUI client. section 8.4.2

How .NET MAUI in Action covers it

How deep it goes
Defines DTO behavior and contrasts it with ViewModel functionality, but does not detail serialization or transport protocols.
Examples
Uses ProductDto, StockCountDto, InventoryItemDto, User, and aggregated leaderboard data as examples.
What it assumes
Assumes basic application layers and services, while clarifying the distinction between Model, ViewModel, and DTO.
What you can do after
Apply it via shared projects to reuse data structures and distinguish data-only DTOs from functional ViewModels.
How it connects
Connects DTOs with shared projects, services, APIs, Model, MVVM, and ViewModel.

Also explained in

Compare how 6 books explain data transfer object →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET MAUI in Action. The section links point to the parts of the book it draws on.