【发布时间】:2013-03-23 19:48:16
【问题描述】:
我正在开发一个实现多层模式的应用程序,其中 MySQL 用于持久性。有一个提供访问的 WCF 服务 数据并提供 DTO。
此外,我计划实现以下模式: - DTO - MVP(还不确定是被动视图还是监督控制器) - 在适用的情况下针对接口编写代码
目前,我的项目结构如下:
+-------------------------------+
| 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. | | ||
|+---------------------+ +--------------------+ +-----------------------+|
+------------------------------------------------------------------------+
外框是 Visual Studio 中的项目文件夹。内盒是 C# 项目
在我继续编码并花更多时间实际实施之前,我只是 想得到一些关于我的项目结构/架构的反馈。
我正在思考以下问题:
- 上述结构是否符合“最佳实践”? 例如。接口、DTO 的位置
- 可以有两个业务层还是拆分业务层 进入客户端和服务器? 服务器 BLL 旨在提供会话管理等通用功能 和安全,而客户端 BLL 提供服务访问。它控制着 其演示者的观点也是如此。
- 服务器端目前不知道域对象。会不会 在这里也可以更好地使用它们?这将导致映射我的 实体到域对象,然后到 DTO
- 从 WCF 服务接收 DTO 是常见的还是我应该使用域 对象(我知道这里已经讨论了很多,但是从什么 我了解,如果域对象不是,它将适用 这很复杂,并且可以在更改时节省映射和编码工作 我的域对象和数据库) 这不会导致非常难以维护的通信链,例如: 实体域对象DTO域对象
- 您将验证放在哪里?我想将基本验证放入 视图或演示者(例如,格式化、null/not null 值,...)同时 主要验证转到域对象...?
- 在数据库中创建新记录时,假设是一个新用户, 客户端是否也应该将新的 DTO 传递给服务器,还是创建更好 接受简单数据类型(如字符串和 int)的服务方法?
很抱歉这篇长篇文章,但我认为最好结合我的 将问题放在一篇文章中,并在其中提供项目结构。
提前感谢您的任何回答。
问候
【问题讨论】:
标签: architecture domain-driven-design dto n-tier-architecture multi-tier