通俗地描述.NET程序集循环依赖问题

发布于 2024-09-11 01:13:44 字数 103 浏览 6 评论 0原文

请通俗地描述一下.NET程序集编译循环依赖问题,以及其他技术是否有类似的限制。

注意:我知道,这似乎是一个简单的问题,但我见过许多真实的、重要的项目,它们完全破坏了依赖关系图。

Please describe the .NET assembly compilation circular dependency problem in layman's terms, and whether other technologes have similar limitations.

Note: This seems like a simple question, I know, but I have seen a number of real, significant projects that have totally broken dependency graphs.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

对你的占有欲 2024-09-18 01:13:44

与任何其他循环依赖相同...

考虑三个程序集 A、B 和 B。 C

A 需要 B 中定义的内容,B 需要 C 中定义的内容,C 需要 A 中定义的内容。

您可以先构建哪个?

Same as any other circular dependency...

Consider three assemblies A, B & C

A needs something defined in B, B needs something defined in C, and C needs something defined in A.

Which can you build first?

错々过的事 2024-09-18 01:13:44

补充一下 Lucas 的答案:在 .NET 中很难提出循环程序集依赖关系。为了编译A.dll,您首先需要B.dll;要编译B.dll,您首先需要C.dll;但要编译C.dll,您需要首先尝试编译的A.dll

可能遇到这种情况的唯一方法是,如果您并行开发 A、B 和 C,并且意外地引入了循环依赖项。但是,一旦您对所有三个进行了干净的构建,问题就会显而易见,并且在打破循环之前您将无法继续。

单个依赖项中的命名空间和/或类之间的循环依赖项更为常见。我尝试将这种循环依赖视为一种代码味道;组件之间没有循环依赖关系的代码库是那些组件可以轻松保持分离和独立重构的代码库。

Patrick Smacchia(NDepend 人员)在这里谈论了一些依赖循环及其对代码质量的影响:http://codebetter.com/blogs/patricksmacchia/archive/2009/07/29/maintainability-learnability-component-layering.aspx

To add to Lucas's answer: it's very hard to come up with a circular assembly dependency in .NET. In order to compile A.dll you first need B.dll; to compile B.dll you first need C.dll; but to compile C.dll you need the A.dll you were trying to compile in the first place.

The only way you're likely to get into this situation is if you're developing A, B and C in parallel, and you've managed to introduce a circular dependency by accident. But as soon as you do a clean build of all three, the problem will be apparent, and you won't be able to proceed until you break the cycle.

Circular dependencies between namespaces and/or classes within a single dependency are a lot more common. I try to treat this kind of circular dependency as a code smell; a codebase without circular dependencies between components is one where those components can easily be kept separate and refactored independently.

Patrick Smacchia (the NDepend guy) talks a little about dependency cycles and their effect on code quality here: http://codebetter.com/blogs/patricksmacchia/archive/2009/07/29/maintainability-learnability-component-layering.aspx

秋千易 2024-09-18 01:13:44

我是 .NET 开发人员工具 NDepend 的开发人员之一,该工具专门用于强制执行干净的代码结构并消除依赖循环。在我们的产品网站上,您会找到与组件依赖周期问题相关的两本白皮书

通过 .NET 程序集和 Visual Studio 项目对代码库进行分区(8 页)

  • 常见有效和创建程序集的无效原因
  • 提高 Visual Studio 解决方案编译性能(速度提高 10 倍)
  • 组织开发环境

使用命名空间定义 .NET 组件(7 页)

  • 在 .NET 程序集中定义组件
  • 组件之间依赖关系的非循环图
  • 进化设计和非循环组件化

I am one of the developer of the tool NDepend for .NET developers that is specialized in enforcing clean code structure and remove dependency cycles. On our product site you'll find two white-books relative to the component dependency cycle issue:

Partitioning code base through .NET assemblies and Visual Studio projects (8 pages)

  • Common valid and invalid reasons to create an assembly
  • Increase Visual Studio solution compilation performance (up to x10 faster)
  • Organize the development environment

Defining .NET Components with Namespaces (7 pages)

  • Defining components inside .NET assemblies
  • Acyclic graph of dependencies between components
  • Evolutionary Design and Acyclic componentization
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文