.NET 利用传递依赖项/引用
我有一个包含 3 个项目的 Visual Studio 解决方案:
- MyWebSite (A)
- BusinessModel (B)
- Persistence (C)
Persistence
、项目 C
,依赖于 NHibernate
并包含所有存储库接口、这些存储库的 Hibernate 实现以及映射到数据库表的类。
BusinessModel
,项目B
,依赖于C
,并包含所有服务类和表示业务域实体的类。这些服务使用存储库来检索数据,然后将该数据转换为它们自己的界面中的业务表示形式。
MyWebSite
,项目 A
,依赖于 A
并包含所有 MVC 类/文件。这里的 MVC 控制器使用 B 中的服务类来执行任何业务逻辑功能。此级别不知道项目 B
使用项目 C
的存储库来执行其操作。
在完美的世界中,我想象项目 A
应该引用 B
,而 B
又引用 C
,而 C
又引用 NHibernate
。这似乎不是真的。我发现项目 A
需要引用 B
和 C
以及 NHibernate
!我不喜欢我的 Web 应用程序需要了解我的后端架构,而且我特别不希望它知道我正在使用 NHibernate
作为我的 ORM。
有没有办法告诉这些项目在解析引用时利用传递依赖项?
我的项目是 Visual Studio 2010 中的 .NET 4(如果该信息有任何区别的话)。
编辑: 我发现这个SO答案解释了这些相关问题仅当项目 C
的类从项目 B
中出现时才需要引用。我非常决心不让层之间有任何泄漏,并且我知道 Hibernate 类仅在 C 中使用,所以也许我只是不理解正确......
I have a Visual Studio Solution with 3 projects:
- MyWebSite (A)
- BusinessModel (B)
- Persistence (C)
Persistence
, project C
, depends on NHibernate
and contains all of the repository interfaces, Hibernate
implementations of those repositories, and the classes which map to the DB tables.
BusinessModel
, project B
, depends on C
and contains all of the service classes and classes representing the business domain entities. These services use the repositories to retrieve data and then transform that data into business representations the surface in their own interfaces.
MyWebSite
, project A
, depends on A
and contains all of the MVC classes/files. The MVC controllers here use the service class from B
to do any business logic functions. There is no knowledge from this level that project B
uses project C
's repositories to perform its operations.
In a perfect world, I would imagine that project A
should reference B
which references C
which references NHibernate
. This does not seem to be true. I find that project A
needs a reference to B
and C
and NHibernate
! I don't like the idea of my web application needing knowledge of my back-end architecture and I especially don't want it aware of the fact that I am using NHibernate
as my ORM.
Is there a way to tell these projects to utilize transitive dependencies when resolving their references?
My project is .NET 4 in Visual Studio 2010, if that info makes any difference.
EDIT:
I found this SO answer to a related question which explains these references are only needed if project C
's classes are surfaced from project B
. I have been very determined to not have any leaks between layers and I know Hibernate
classes are only used in C
so maybe I just don't understand correctly...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论