I'm developing an application which implements multi-tier pattern where MySQL is used for persistence. There is a WCF service which provides access to data and provides DTOs.
Further, I plan to implement the following patterns: - DTOs - MVP (not yet sure if passive view or supervising controller) - Code against interfaces where applicable
Currently, I rawly have the following project structure:
+-------------------------------+
| MySQL DB Server |
+------+------------------------+
^
| Uses Entity Framework 5.0
|
+
+-------------------------------------------------------------------------------+
| Application Server |
|-------------------------------------------------------------------------------|
|+------------------+ +----------------+ +--------------+ +--------------------+|
|| Data Access Layer| | Contracts | | Communication| | Business Layer ||
||------------------| |----------------| |--------------| |--------------------||
|| - EF 5.0 Entities| | - WCF Contracts| | - WCF Service| | - Actual Service ||
|| | | | | Hosts | | - Session management|
|| | | | | | | - Security and ||
|+------------------+ +----------------+ +--------------+ +--------------------+|
+-------------------------------------------------------------------------------+
^
| Communicates via DTOs which are acutally wrappers for Entities
| eg. GetUserByID() or SaveUser(userDTO)
|
|
+-------+-----------------------------------------------------------------------+
| Clients |
|-------------------------------------------------------------------------------|
|+-------------------+ +-------------------+|
|| Business Layer |+----------------------------------->| GUI (Winforms) ||
||-------------------| BLL receives DTOs and creates |-------------------||
|| -Provide WCF Servi| Domain Objects (eg. User) which are| -Implementation of||
|| ce Access | Processed by presenters and passed | View Interfaces ||
|| -Service Reference| to views where they are bound to | ||
|| -Implementation of| controls. | ||
|| Presenter Interf.| | ||
|+-------------------+ +-------------------+|
+-------------------------------------------------------------------------------+
+------------------------------------------------------------------------+
| General |
|------------------------------------------------------------------------|
|+---------------------+ +--------------------+ +-----------------------+|
|| DTOs | | Interfaces | | Library ||
||---------------------| |--------------------| |-----------------------||
|| -DTO Definitions | | -View Interfaces | | -General Helper Classe||
|| | | -Presenter Interf. | | s eg. Cryptography ||
|| | | -Domain Model IF. | | ||
|+---------------------+ +--------------------+ +-----------------------+|
+------------------------------------------------------------------------+
Outer boxes are project folders in Visual Studio. Inner boxes are C# Projects
Before I continue coding and spend more time in actual implementation, I just like to get some feedback about the structure / architecture of my project.
I'm wrapping my head around following questions:
- Is the above structure "best-practice"-conform? eg. location of Interfaces, DTOs
- Is it ok to have two business layers or rather split the business layer into client and server? Server BLL is meant to provide general functions like Session management and security while client BLL provides service access. It controls the views by its presenters as well.
- Server side does not know about the domain objects at present. Would it be better to use them here as well? This would result in mapping my entities to domain objects and then to DTOs
- Is it common to receive DTOs from WCF service or should I use domain objects (I know that has been discussed here a lot, but from what I understand, it would be applicable if the domain objects are not that complicated and could save mapping and coding efford when changing my domain objects and database) Wouldn't this result in a very hard to maintain communication chain like: Entities<->Domain Object<->DTO<->Domain Object
- Where do you put validation? I thought to put basic validation into the views or presenters (eg. formatting, null/not null values, ...) while main validation goes to the domain objects...?
- When creating a new record in the database, lets say a new user, should the client also pass a new DTO to the server or is it better to create a service method that accepts simple data typs such as string and int?
Sorry for this long post, but I thougt it would be better to combine my questions into one post and provide the project structure within.
Thanks in advance for any kind of answer.
Regards