1

我有四个程序集;用户界面、业务逻辑、数据访问、通用。

用户界面引用了 DataAccess 中的存储库,这是不好的做法吗?我是否应该在 BusinessLogic 中创建传递方法以使 UserInterface 不耦合到 DA 程序集?

即使在 BusinessLogic 方法只调用相关的 Repository 方法什么都不做的情况下?

还是我很悬?

4

4 回答 4

2

rather than think of the UI talking to the repository, think of implementations depending on abstractions. in this instance the UI depends on IRepository. How IRepository is implemented doesn't matter.

and putting this all into separate assemblies is overkill. just use namespaces to segregate your code. it will be much easier to maintain.

于 2012-07-05T20:08:09.703 回答
1

如果您正在尝试进行领域驱动设计,那么在您考虑在 UI 中使用它之前,请先了解存储库的作用。很好的解释在这里http://devlicio.us/blogs/casey/archive/2009/02/20/ddd-the-repository-pattern.aspx

于 2012-07-05T19:57:45.863 回答
1

我认为你缺少一个图层。实体层或数据传输层。

这绝对不是一个好的实践,UI 必须了解你的 DAL,这就是你有你的业务层的原因。

我认为你应该用经典的方式 UI - BL - DAL 和向后应该是相同的,使用数据传输对象

始终在这些层之间使用 DTO,将对象从 UI 传输到 BL,从 BL 传输到 DAL,然后反向传输。

于 2012-07-05T20:06:51.110 回答
0

我认为分层结构的主要原因是“关注点分离”。SoC 基本上是提供松散耦合的。所以在 DAL 中引用 UI 并不是一件好事。

另一方面,UI 应该处理用户交互(而不是直接从 DAL 调用)。BL 应该负责验证并调用 DAL 方法。DAL 是最后一步,它可以根据 SQL 方面验证数据,然后处理 SQL 语句。

于 2012-07-05T20:00:55.203 回答