开发者

MVC: Is it considered bad form to give a DTO a reference to the data access layer?

Is it considered bad form to give a DTO a reference to the data access layer?

Or should you always pass a DTO between the data access layer and the application layer?

EDIT: For example, imagine the following:

  • I keep a product types list in my database.
  • I'd like to render this list in a drop-down box in a partial view.
  • This partial view is strongly-typed to a DTO.
  • Questio开发者_运维问答n:
    • Should I retrieve my product types list first, and then pass it to the DTO via its constructor?
    • Or is it acceptable to pass a repository reference to the DTO, and then expect it to retrieve this list from the data access layer?


A DTO should never have a reference to the data access layer.

Rather a DTo is a simple transfer object that contains only data and is used to pass information between layers.


A DTO is for passing data from the business layer to your presentation layer. This way you can bind the DTO to your combobox. The DTO should be populated inside the business layer (middle tier), like when calling a service. The service will call the DAL by for example by DAO's.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜