表示层引用数据层
我有一个 3 层 .NET 2.0 应用程序。 表示层引用中间层。 中间层引用数据库层。 由于某种原因,当我编译时,数据层的 dll 出现在表示层的 bin 中。 我该如何阻止这个?
I have a 3-tier .NET 2.0 app. The presentation layer references the middle tier. The middle tier references the database layer. For some reason, when I compile, the dll's for the data layer appear in the bin of the presentation layer. How do I stop this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
阻止这种情况的唯一方法是将您的一个或多个层设置为服务层(或类似的层)以在物理上分隔您的层。
由于各个层是相互编译的,因此需要存在程序集才能使整个应用程序正常运行。 您认为应用程序在没有所有程序集的情况下如何工作?
The only way to stop this is to make one or more of your tiers a service-layer (or something similar) to physically separate your tiers.
Since your separate tiers were compiled against each other the assemblies need to be there for the entire application to function properly. How do you envision the application working without all the assemblies?
在参考属性中将复制本地设置为 false
set Copy Local to false in Reference properties
复制是可以的,因为存在所谓的依赖关系。 您的中间层取决于中间层上的数据访问和 UI。 您只需跟踪而不引用来自 UI 的数据访问。
It is OK to be copied because there are known as Dependencies. Your Middle tier depends on DataAccess and UI on Middle tier. You have to keep track only not to reference data access from UI.
通常我会按如下方式执行物理层应用程序:
但我正在改变对此组织的看法。 因为我做过很多项目,其中一些需要维护和改进。 我开始认为这个组织过于单一。 一些作者,如 Ted Faison、Tomas Erl、Robert C. Martin、Andy Aunt 表示,这种层次结构方法有点幼稚。
无论如何......将您的逻辑放入单独的项目中并将它们构建为不同的程序集。 进行层次结构参考,您就会得到您想要的。
Normally I do physical layer application as following:
But I'm changing my view on this organization. As I have done lot of projects and some of them demands maintenance and improvements. I start to think that this organization is too monolithic. Some authors like Ted Faison, Tomas Erl, Robert C. Martin, Andy Aunt says that this hierarchal approach is kind of naive.
Anyway... Put your logic in separated projects and build them as distincted assemblies. Make hierarchal references and you'll have what you want.