Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
  • 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?
like image 938
Jim G. Avatar asked Dec 11 '25 07:12

Jim G.


1 Answers

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.

like image 188
Paul Hiles Avatar answered Dec 13 '25 00:12

Paul Hiles



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!