问题描述
是否有可研究一套管理组件,并告诉你是否有一个命名空间中的类型依赖于任何在其他任何事业吗?例如,说我有一个 MyApp.BusinessRules
命名空间,不希望它来访问 MyApp.GUI
,但两者的命名空间都在同一个组件。我的目标是能写一个自定义的MSBuild任务是验证各种耦合规律还没有被打破。
到目前为止,我所遇到的唯一工具看起来像它可能做到这一点 NDepend的的,但我不知道是否有一个简单的解决方案。
我的工具 NDepend的的开发商之一。请你能告诉我们你怎么找到复杂的NDepend的,你如何想象一个简单的解决方案适合您?
NDepend的带有3种不同的方法可以做到你想要什么:相关矩阵,的,你也可以写一些的和规则的的,或执行一些特殊的依赖关系。
对于这一点,下面的CQLinq规则可写,会不会比这更简单的:
warnif计数> 0
让businessRules = Application.Namespaces.WithNameLike(^ MyApp.BusinessRules)
让GUI = Application.Namespaces.WithNameLike(^ MyApp.GUI)
从n个businessRules.UsingAny(GUI)
让guidNamespacesUsed = n.NamespacesUsed.Intersect(GUI)
选择新{N,guidNamespacesUsed}
Are there any utilities that can examine a set of managed assemblies and tell you whether any of the types in one namespace depend on any in another? For example, say I have a MyApp.BusinessRules
namespace and don't want it to access directly anything in MyApp.GUI
, but both namespaces are in the same assembly. My goal is to be able to write a custom MSBuild task that verifies that various coupling rules have not been broken.
So far the only tool I have come across that looks like it might do this is NDepend, but I am wondering if there is a simpler solution.
I am one of the developer of the tool NDepend. Please could you let us know what do you find complicated in NDepend and how you imagine a simpler solution for you?
NDepend comes with 3 different ways to do what you want: Dependency Matrix, Dependency Graph and also you can write some Code Rule over LINQ Query (CQLinq) and rules to detect cycle between namespaces, or enforce some particular dependencies.
For that, the following CQLinq rule can be written, could it be any simpler than that?:
warnif count > 0
let businessRules = Application.Namespaces.WithNameLike("^MyApp.BusinessRules")
let gui = Application.Namespaces.WithNameLike("^MyApp.GUI")
from n in businessRules.UsingAny(gui)
let guidNamespacesUsed = n.NamespacesUsed.Intersect(gui)
select new { n, guidNamespacesUsed }
这篇关于检测命名空间之间的依赖关系在.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!