Should POCO be obtained from DTO or better not?

When creating an n-tier solution, I don’t want to disclose my business objects, but use DTO instead. On the other hand, I don't want to define objects twice and write code copies all the time.

Now, my idea would be to write a DTO containing all the necessary fields and properties, but not logic (only state).

Then I would extract my business objects from these DTOs, expanding them with my business logic, working on the properties of the DTO base classes. These objects will also be objects stored in the used ORM (NHibernate).

With this server-side approach, I could work with business objects and transfer them directly to the client (they are produced, so they are reset). I would not expose my business logic this way and save a lot of code.

Do you think the approach is reasonable?

Hello,

Sebastian

+3
source share
3 answers

You might want to consider the following:

"... because it prevents the DTO from knowing the domain objects allow you to reuse the DTO in different contexts. Similarly, you don’t want the domain objects to know about the DTO, because it may mean that changing the DTO will require changing the code in the domain logic that will lead to a service nightmare.

- , DTO - . - Mapper, ..."

from :

, , AutoMapper.

+6

. Linq to SQL - DTO .

+1

" - DTO. , DTO BO, 2 3 BO

0

Source: https://habr.com/ru/post/1721799/


All Articles