There was a task to develop a simple application on ASP.NET WebApi 2.0 + EntityFramework + MSSQL. Here I want to ask questions about the server side of the application. There is almost no programming experience. The main responsibilities of the application:
1) Preservation of entities in the database;
2) Editing entities;
3) Search for entities for some attributes.
How I imagine the picture:
Split server into 5 assemblies (packages):
1) API itself - controllers. He knows only about the existence of a data presentation layer. The main task of obtaining data from queries + validation of this data.
2) The level of presentation logic. View Model Description (DTO). Here is the transformation of the Entity in the DTO and back. He knows only about the existence of the level of services and business logic.
3) The level of services. There are calls to the level of data access, level of business logic. Knows about the existence of a data access level and business logic.
4) The level of business logic. Model description + business logic. He does not know about anyone except himself.
5) Data Access Level (DAL). It describes the processes of interaction with the database. He does not know about anyone except himself.
Further, I do not quite understand how to properly establish the interaction between the packages:
Entity creation case:
As I understand it, controllers receive web requests, extract some data (DTO) from it and validate them and, if the request is correct, access the level of data presentation logic. Then there some class (EntityCreator) takes the DTO, converts it into a business entity and refers to the level of services (EntityService). The service receives the entity, opens the context of interaction with the database, if necessary, fills in some attributes, establishes the necessary connections (it does all this interacting with the business logic) and refers to DAL in order to preserve the resulting entity. DAL returns the saved entity to the service, the service returns the entity to the data presentation level (EntityCreator), then it is converted to the corresponding DTO and the controller responds.
Actually the question is whether it is correct to organize the interaction of the modules and their partitioning. It is embarrassing that the presentation layer should understand which service to contact. Perhaps this should be done at the level of the API controller? Then the controller accesses the presentation layer to convert the DTO to the entity, then the controller accesses the service with the received entity, and again accesses the presentation level with the result that the service returned to it.