I've been trying to develop an N-Layered design with a WinForms application using Entity Framework.
Is the below sample flow correct for saving a new record in an n-layered design using Entity Framework?
Presentation Layer
A) UI performs light screen input data validations. Then UI converts view model to DTO and passes it to the Application Layer.
Application Layer
A) Application Layer sends DTO to Domain Model in Domain Layer
Domain Layer
A) Validate incoming DTO values for compliant business rules before creating new instance of Domain Model SoftwareRequest Entity.
B) If all values are validated, then create new instance of Domain Model SoftwareRequest Entity.
C) Exit to return control to Application Layer
Application Layer
A) Call Infrastructure Layer SoftwareRequest Repository and pass in the new Domain Model SoftwareRequest Entity which was provided by the Domain Model
Infrastructure Layer Data Access
A) SoftwareRequest Repository receives new Domain Model SoftwareRequest Entity from Application Layer.
B) Add new Domain Model SoftwareRequest Entity to Entity Framework DBContext - context.SoftwareRequests.Add(NewDomainModelEntity)
C) Save new entity - context.SaveChanges()
D) Exit to return control back to Application Layer
Application Layer
A) Convert results of save operation to DTO
B) Exit to return control back to UI with DTO containing results of adding new SoftwareRequest
UI
A) Convert received DTO to View Model
B) Display View Model data to screen showing results of adding a new software request
--------- Below information added on 2/22/2016 at 6:49am PST ---------
Dependency Summary:
Presentation Layer - References Application Layer to make requests - References Domain Layer only for the purpose of working with interfaces describing DTO's which will be sent from the UI or received from the Application Layer
Application Layer - References Domain Layer interfaces describing DTO's. Also uses interface definitions for Domain Model Entities so it can convert entity responses from the Infrastructure Layer to DTO's which are returned to the UI. A reference to the Infrastructure Layer Data Access is also here so repositories can be access to perform CRUD operations after the involved Domain Model Entities have been validated for rules and values by the Domain Layer.
Domain Layer - Has no references to any layers above or below. Has no dependency injected services from any layer. This includes no tasks involving CRUD with infrastructure repositories. All requests such as for validation of rules receive DTOs containing all the necessary information to carry out requested domain tasks.
Infrastructure Layer Data Access - References Domain Layer interfaces describing Domain Model Entities which are used to perform Entity Framework operations in repositories (i.e. CRUD operations). Also references Domain Layer for definitions of interfaces for repositories which are implemented here in the Infrastructure Layer data access. DTOs are not used in this layer. This layer typically responds with Domain Model Entities to the Application Layer. The Application Layer converts all Domain Model Entity responses (i.e. IEnumerable) to DTOs which are sent back to the UI.