views:

145

answers:

2

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.
  • Question:
    • 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?
+5  A: 

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.

zaph0d
+1  A: 

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.

Michael Bavin