2

I'm currently following an IT study, and we're asked to use interfaces and DTO's in a multi-layered ASP.Net Core MVC consisting of Presentation, Logic/Business, and Data Access, using dependency inversion so that both the presentation and DAL have references to the logic layer. In between the Logic and DAL, we have to use DTO's and Interfaces. I understand the concepts of both, and I know how to use them. However, we can decide for ourselves whether we want to create seperate layers for our DTO's and Interfaces, or to stick them in the logic layer. We are also asked to explain why we chose one option over the other. However, I cannot find any sources for why you would pick one over the other anywhere. So that's why I'm asking here.

So my question is: What are the advantages and disadvantages of putting your DTO's and Interfaces in a seperate layer, and what are the advantages and disadvantages of just keeping them in the logic layer?

Thanks in advance.

TallTed
  • 9,069
  • 2
  • 22
  • 37
oggiV
  • 21
  • 1
  • I am not sure that I understand? You mean an extra layer between the Logic and Data Access Layer where the only things are interfaces and DTOs? This totally does not make sense to me. You will make this extra layer "the core one". And this totally brakes the concept of Clean Architecture. You extra layer will be the core here: https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html . – Yavor Mitev Jun 03 '22 at 19:16

1 Answers1

0

What are the advantages and disadvantages of putting your DTO's and Interfaces in a separate layer I imagine separate layer like this:

     Core
       |
 ------------
 |     |    |
DAL   BLL   PresentationLayer

Advantages are:

  • can be used in any other layers. So each layer can expose own dto by its API, but internally it uses own classes. E.g. data layer can use internally own model clases Person, however data layer returns PersonDto to Business Layer

  • you can easily reference this separate layer into other layers without forcing to introduce unnecessary dependencies. E.g., if application is using just one model from data layer, then you will have to reference this layer into presentation layer.

Disadvantages:

  • recompiling? If you edit your dto, then you need to recompile your layer and recompile all layers that depepnds on this layer

what are the advantages and disadvantages of just keeping them in the logic layer?

Advantages:

  • I do not think that this approach has any advantages

Disadvantages:

  • wheneever you want to use dto or interface in any other layer, you have to reference the whole this logic layer. This logic layer can expose unnecessary API for this layer.
StepUp
  • 36,391
  • 15
  • 88
  • 148