DTO - Data Transfer Object
A Data Transfer Object (DTO) is an object that carries data within an application or between processes.
Programming to an interface doesn’t mean that all classes should implement an interface. Short-lived objects, such as POCOs, DTOs and VMs (View Model TBD), typically contain no behavior that requires mocking, interception, decoration, or replacement. They are mere data objects. This makes them safe to create in your code, so there’s no risk in tightly coupling your code to these data objects. These objects contain the application’s runtime data that flows through the system after classes like controllers and services have long been created. (Seemann 58)
TBD
Starting in C# 9, we should implement DTOs as read-only record types.
Original mutable class DTO
C# 9 read-only record type DTO
or
I favor the property-based record syntax with { get; init; } blocks over positional parameters. This approach prevents parameter order confusion during initialization and provides better code clarity when objects are instantiated. Named properties make the code more self-documenting and less error-prone, especially when dealing with multiple string parameters that could easily be transposed.
See Also: