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

2023-09-06 23:44:11 作者:淩云卐龙道

请介绍.NET程序集编译循环依赖问题,通俗地说,等technologes是否也有类似的限制。

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.

推荐答案

要添加到卢卡斯的回答是:这是很难拿出一个圆形的组装的相关性在.NET。为了编译 A.DLL 首先需要 B.DLL ;编译 B.DLL 首先需要 C.dll ;但编译 C.dll 您需要的 A.DLL 你想在第一时间进行编译。

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.

你很可能会陷入这种局面的唯一方法是,如果你正在开发的A,B和C并行,而你已经成功偶然引入循环依赖。但只要你做一个干净的构建三个,这个问题将是显而易见的,你将无法继续进行,直到你打破这种循环。

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.

循环的依赖很多比较常见。我试图把这种循环依赖为code异味;无组件之间的循环依赖一个codeBase的是其中的成分很容易被分开并独立重构。

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.

帕特里克Smacchia(在NDepend的家伙)谈了一些关于循环依赖关系以及它们对这里code质量的影响:http://$c$cbetter.com/blogs/patricksmacchia/archive/2009/07/29/maintainability-learnability-component-layering.aspx

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