简体   繁体   English

DTO应该包含其他DTO还是构成“行为”?

[英]Should DTOs contain other DTOs or does this constitute 'behaviour'?

We are starting on a new project and are designing the DTOs that will get injected into the corresponding POCOs with the behaviour. 我们正在开始一个新项目,并正在设计DTO,这些DTO将通过行为注入相应的POCO。 However every example of a DTO I can find only contains value types such as: 但是我可以找到的每个DTO示例只包含值类型,例如:

public class CustomerDTO
{
  public int Age { get; set; }
}

But what we would like to do is add DTO properties that reference collections of other DTOs such as: 但我们想要做的是添加引用其他DTO集合的DTO属性,例如:

public class CustomerDTO
{
  public List<AddressDTO> Addresses { get; set; }
}

Is this a bad design idea that will give us problems down the line? 这是一个糟糕的设计理念,会给我们带来问题吗? Or, is there no other way of designing real DTOs that don't reference each other? 或者,没有其他方法可以设计不相互引用的真实DTO吗?

It is typical navigation properties that you want to add to your DTO. 这是您要添加到DTO的典型导航属性。 I think it is valid to use them and the only problem that you can meet is circular references in serialization and so on. 我认为使用它们是有效的,你可以遇到的唯一问题是序列化中的循环引用等等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM