Base solution for your next web application
Open Closed

Can a Dto class be returned from a Domain Service ? #8468


User avatar
0
sumitshah created

We have 3 application service which uses the same piece of code.

In order to reduce redundancy we want to introduce a Domain Service.

We have gone through ABP documents : https://aspnetboilerplate.com/Pages/Documents/Domain-Services.

Unlike Application Services which get/return Data Transfer Objects, a Domain Service gets/returns domain objects (like entities or value types).

It mentions not to get/return Data Transfer Objects,

And our requirment is to return a custom class / Dto which is neither an entity nor a value type.

Please suggest


5 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    hi

    The domain service returns the entity, and then the entity is converted to a DTO in the application service.

  • User Avatar
    0
    ismcagdas created
    Support Team

    This issue is closed because of no recent activity. Please create a new issue if you are still having this problem.

  • User Avatar
    0
    fawad29 created

    I have the same question, I know the document says that domain service should return entity which can be converted into dto, similarly entity/entities should be passed to domain services. In order to reduce redundancy, I want to pass dto as parameter to domain service and return a dto back from domain service. I know I can do this in the code (as it is not being prohibited in the code), however does it break anything?

    I have written code which passess dto to domain from application services and vice versa so aspnetzero does not prevent it explicitly but I would like to know if it will break anything or is it against the best practices?

  • User Avatar
    0
    maliming created
    Support Team

    hi @learner29

    Zero uses a layered structure.According to the convention, we use DTO in application services and entities in domain.

    You can check the explanation of the layered structure here. https://aspnetboilerplate.com/Pages/Documents/NLayer-Architecture

  • User Avatar
    0
    fawad29 created

    I had check that link before posting, can you please answer my specific quetions?

    I have written code which passess dto to domain from application services and vice versa so aspnetzero does not prevent it explicitly but I would like to know if it will break anything or is it against the best practices?