无法添加此依赖项,因为它将创建循环依赖项 [英] This dependency cannot be added because it will create a circular dependency

查看:975
本文介绍了无法添加此依赖项,因为它将创建循环依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个正确开发的项目,现在我想要一个项目,更准确地说是第三个项目,只有一个表单包含两个按钮控件,用于导航到我开发的每个项目。



在这样的场景中,我使用将两个项目(类库)解决方案文件添加到第三个项目的技术,但是当我添加引用时,它会给我一个错误,这个依赖项无法添加,因为它会创建一个循环依赖....



任何人都可以帮助我或给我一个更好的主意......?

Thanx:Ghalib Mirza。

I have two proper developed projects now i want a project, more precisely a third project with only 1 form containing two button controls for navigation to each of my developed projects.

In such scenerio i use the technique of adding both the two project's (class library) solution files to third project, but when i add references it will gave me error that is "This dependency cannot be added because it will create a circular dependency"....

Anyone can help me or gave me a better idea...?
Thanx : Ghalib Mirza.

推荐答案

你不能这样做:

你有两个项目P1和P2,它们引用了第三个项目P3。

如果在P3中添加对P1的引用,则编译变得不可能:只要编译P1并生成新的二进制文件,就必须重新编译P3,因为它取决于二进制文件,并且更改可能会影响它。这会创建一个新的P3二进制文件,这意味着需要重新编译P1和P2 - 这会创建一个新的二进制文件,因此P3需要....



看看VS是什么在说什么?你不能创建循环依赖,因为它们会阻止编译再次运行!



如果你的P3需要访问P1和P2进行导航,那么它需要一个引用:但是P1和P2没有。如果P3中有P1和P2需要的其他代码,则将其解压缩到P4并让所有三个项目都参考它。



你肯定不应该有P1和P2知道创建和显示它们的类 - 这非常违反OOP原则!
You can't do that:
You have two projects P1 and P2 which have references to a third project P3.
If you add a reference to P1 in P3 then compilation becomes impossible: as soon as you compile P1 and produce a new binary, you have to recompile P3 because it depends on the binary file and the changes may impact it. This creates a new P3 binary, which means that P1 and P2 need to be recompiled - which creates a new binary, so P3 needs ....

See what VS is saying? You can't create circular dependencies because they prevent compilation working ever again!

If your P3 needs access to P1 and P2 for navigation, then it needs a reference: but P1 and P2 do not. If you have other code within P3 that P1 and P2 need, then extract it to P4 and have all three projects refer to it.

You definitely shouldn't have P1 and P2 knowing about the classes that create and display them - thats very much against the OOPs principles!


这篇关于无法添加此依赖项,因为它将创建循环依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆